Skip to content
3 Death Saves

API Reference

The API is published as the global VGMUSIC and at game.modules.get('vgmusic').api. Both point to the same object.

Playback runs on one client: 3DS-ATLAS picks the primary GM, and only that client starts and stops tracks. Other clients read the API but cannot drive playback.

const handle = VGMUSIC.registerSection({
id: 'my-module.weather',
label: 'MYMODULE.WeatherMusic',
priority: 10,
types: ['Scene'],
predicate: (controller) => game.myModule.isStormy,
contextKey: 'weather'
});

Registers a playlist section. Registered sections appear in the Music Configuration window alongside the built-in ones and compete in the same priority ordering.

PropertyTypeDescription
idstringRequired. Unique registry id.
labelstringLocalization key for the section name. Used verbatim when it resolves to nothing.
prioritynumberDefault sort priority, prefilled in the Configure Section prompt. Defaults to 0.
typesstring[]Document type names the section applies to: Scene, Actor, Token, DefaultMusic.
predicateFunctionActivation test, called with the music controller once per playlist refresh. A falsy return keeps the section silent.
hintstringLocalization key describing when the section plays, shown under the section select in the prompt.
contextKeystringContext key used for flags, suppression, and playback. Defaults to the id.

Registration is validated; it is rejected, logged, and returns null when:

  • id is missing or not a string.
  • id is already registered.
  • types is not an array, or contains a name outside Scene, Actor, Token, DefaultMusic.
  • predicate is defined but not a function.
  • The context key is area or combat, or is already claimed by another registered section.

A successful call returns a handle:

MemberDescription
idThe registered id.
contextKeyThe resolved context key.
unregister()Removes the section and refreshes playback.
refresh()Re-runs playlist selection.

A predicate that throws disables its section for that refresh. When a section’s sources throw while resolving, it is skipped and logged; the other sections still resolve.

Priority 0 is a deliberate value; the module does not treat it as unset.

FunctionReturnsDescription
VGMUSIC.unregisterSection(id)booleanRemoves a registered section. True when a section was removed.
VGMUSIC.getRegisteredSections()object[]Every registered section definition.
VGMUSIC.refreshSections()Promise<void>Re-runs playlist selection, for when a predicate would now answer differently. Resolves once the transition has run.

GM suppression is a world-scoped set of context keys that covers the built-in area and combat contexts and any registered section’s context key. The scene control toggles and the Calendaria indicator write the same set.

The API layers reference-counted suppression on top of it:

FunctionReturnsDescription
VGMUSIC.requestSuppression(context)object | nullSuppresses a context until the returned token is released. Primary GM only; called from any other client it logs and returns null.
VGMUSIC.releaseSuppression(token)booleanReleases a token. True if the token was live.

A context stays silent while any token holds it or the GM suppression set contains it. Tokens live in the primary GM client’s memory and do not persist across reloads.

Fires on every client when the playing track changes.

Hooks.on('vgmusic.trackChanged', ({ prev, current, context }) => {});
FieldTypeDescription
prevPlaylistSound | nullThe track that stopped.
currentPlaylistSound | nullThe track now playing.
contextstring | nullThe playing context key.

Fires on every client when the GM suppression set changes. The payload is the new Set of suppressed context keys.

Hooks.on('vgmusic.suppressionChanged', (contexts) => {});

The built-in sections seed these default priorities into the Configure Section prompt:

SectionPriority
Token combat5
Actor combat0
Default combat-5
Scene combat-10
Scene area-20

You can override the priority per assignment in the prompt.

MemberDescription
VGMUSIC.musicControllerThe controller singleton driving playlist selection and playback.
VGMUSIC.VGMusicConfigThe Music Configuration application class.
VGMUSIC.PlaylistContextA resolved playlist candidate, exposed for consumers building their own.