One piece per game state, all with the same key, tempo and length in bars, so they can be
swapped at a bar line without a jump: AdaptiveMusic.load(name, stems, { barSeconds }) per
state, then switchVersion(name, fade, 'bar'). Each state overrides the base scene's
mood, tension and voices (the seed stays, so the states share their melodic outline).
import { composeStates } from '@datamoc/mwg/music';
const states = composeStates(
{ id: 'forest', seed: 3, mood: 'calm', tension: 0.2, key: 7, bars: 8, voices: 4 },
{ exploration: {}, combat: { mood: 'tense', tension: 0.9 }, victory: { mood: 'triumphant', tension: 0.4 } },
);
console.log(states.combat.barSeconds === states.exploration.barSeconds); // true
Generated game music: a scene described as data (mood, tension, key, seed, length, voices) becomes a playable MIDI file, the same one every time. Renderer-free; it builds on
core(the seeded generator) andaudio(the MIDI file shape and the seed mixing of data sound effects), and what it makes plays throughrenderMidiToBuffer, a registered engine, orAdaptiveMusicfor bar-aligned switches between game states.