The Binding of Isaac: Rebirth

The Binding of Isaac: Rebirth

[AB+] Music Mod Callback
 This topic has been pinned, so it's probably important
Taz  [developer] 11 Jun, 2019 @ 7:15am
Documentation: All Functions
What the heck is a metatable
Last edited by Taz; 11 Jun, 2019 @ 7:16am
< >
Showing 1-4 of 4 comments
Taz  [developer] 11 Jun, 2019 @ 7:21am 
Adding Callbacks

To add a callback, use the following function
MMC.AddMusicCallback( table ref, function callbackFn, Music trackId1, Music trackId2, ... )
ref is your mod table. This is required and the script will error if you use a different table.
callbackFn is the function that is called everytime a track is about to play.
For callbackFn:
The music ID is given as the first argument.
You can find some examples here.

The function can:
  • Return a track Id to play that instead.
  • Return jingle Id, track Id to play a jingle and queue the track.
  • Return 0 to prevent the track from playing, and allow the current one to continue
  • Return -1 to stop all music
  • Return nil to continue to internal code

Any arguments given after the callback function are required track IDs. If any are given, then the music about to play must be one of the track IDs for the function to be called. (eg, you give all treasure room jingles as required track IDs, your function will only be called when one of these is about to play)

Callbacks added first will take priority.
If a callback does not return nil, no other callbacks will be run.

Callbacks are guaranteed to be called at the beginning of each room, even if the music isn't supposed to change.

WARNING!
Mods that register with identical names are classed as the same mod by this script.
Main menu music, cutscenes (excluding boss intro), and endings do not trigger callbacks.
Last edited by Taz; 20 Jun, 2019 @ 4:21am
Taz  [developer] 11 Jun, 2019 @ 7:34am 
Removing Callbacks

To remove a callback, use the following function
MMC.RemoveMusicCallback(table ref)
ref is the mod table you used to add the callback.

This will remove all callbacks associated with the table.

WARNING! Callbacks are not automatically removed when your mod is reloaded with the luamod command. It is recommended you use this function at the beginning of your script to prevent old callbacks from taking priority.
Last edited by Taz; 11 Jun, 2019 @ 7:35am
Taz  [developer] 11 Jun, 2019 @ 7:40am 
Other Global Functions and Variables

MMC.Initialised
This variable is true if the mod has fully loaded. False otherwise.

MMC.Version
A string containing the current version of the API is stored here. You can check that the right version is installed with your mod, as there is a slight possibility that future versions will not be backwards compatible. The current version is 1.2 for Afterbirth+ and 2.0 for Repentance. The mod version in metadata may not match this.

MMC.DisableMusicLayers
A variable that is true if music layers are disabled in favour of a mod that does not allow them. This is false by default, you may change this. This is not associated with the mmclayer command and takes priority if true.

MMC.GetMusicTrack()
This function simply returns the intended track ID of the room you are in. Sometimes this is two values, for example when visiting a treasure room for the first time.

WARNING!
Using this in an uncleared boss room will return ONLY the boss jingle. If you want the intended boss music, use:

MMC.GetBossTrack()
Returns the intended boss room entry music for this room (eg Satan, Mom). If not in a boss room, it will simply return one of the two generic themes.

WARNING!
The function always returns the entry music, not the current one. For example in Hush's boss room, the ID returned will always be ???'s theme, even if Hush is in his final form.

MMC.GetStageTrack()
Returns the stage music track, regardless of room properties.

MMC.Manager()
Return a table that behaves indentically to the MusicManager class. (Meaning you can do MMC.Manager():Crossfade() for example). With the only difference being that it will call all mod callbacks. Useful if you want to allow others to change the music of your custom room or stage with Music API.

local musicmgr = (MMC and MMC.Manager or MusicManager)()
The above code will set musicmgr to MusicManager, running through callbacks if MMC exists and still continues without crashing if it doesn't.

MMC.InCustomStage()
Returns true if on modded floors that have their own custom music (eg The Glacier from Revelations). The mod may not work correctly with callbacks if this is true.

Currently all other variables are hidden and/or localised within the script. If you want access to something via a function or directly, leave a comment on the mod page.
Last edited by Taz; 18 May, 2021 @ 9:25am
Taz  [developer] 11 Jun, 2019 @ 8:09am 
Notes

Using raw track IDs are not recommended. This mod prevents the game's internal code from running by ejecting the game tracks from their normal slots and readding them beyond NUM_MUSIC. The Music enum has been redefined to fit the new music slots.

Raw track IDs are allowed when using Music API Callbacks or when using MMC.Manager instead of MusicManager as they are automatically corrected, but just to be safe, you should get your music ID from the enums or via Isaac.GetMusicIdByName.

Workarounds for no music.xml
Right now it is impossible to add or remove intros or layers from tracks. It you need to remove an intro use a silent short music file. If you need to add one, you should add the track in content instead of replacing and use a callback. In the future I may add silent intros to all tracks for easy replacement.

You can remove layers by adding musicmgr:DisableLayer() to your script where necessary where musicmgr is MusicManager() or MMC.Manager(). Or use MMC.DisableMusicLayers to prevent all layers.
Last edited by Taz; 18 May, 2021 @ 9:27am
< >
Showing 1-4 of 4 comments
Per page: 1530 50