mwg API
    Preparing search index...

    Function composeStates

    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) and audio (the MIDI file shape and the seed mixing of data sound effects), and what it makes plays through renderMidiToBuffer, a registered engine, or AdaptiveMusic for bar-aligned switches between game states.

    • 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).

      Parameters

      • base: Partial<MusicScene> & { id: string }
      • states: Readonly<
            Record<string, Partial<Pick<MusicScene, "mood" | "tension" | "voices">>>,
        >

      Returns Record<string, GeneratedMusic>

      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