Composes a piece from a scene: the same scene always gives the same notes. A melody walks the
mood's scale over a four-bar chord progression (its first two bars come back in the third and
fourth with a changed ending), a bass holds the chord roots, a pad or arpeggio fills the chord,
and drums join once the scene has the voices and the tension for them. The voices limit is
kept by writing fewer layers, never by cutting notes afterwards: 1 voice is the melody alone,
2 adds the bass, 3 adds a one-note arpeggio, 4 adds drums, more adds pad notes.
import { composeMusic } from '@datamoc/mwg/music';
import { renderMidiToBuffer } from '@datamoc/mwg/audio';
const music = composeMusic({ id: 'harbour', seed: 7, mood: 'calm', tension: 0.2, key: 2, bars: 8, voices: 3 });
console.log(music.barSeconds, music.polyphony); // 3 or fewer notes at once
const audio = renderMidiToBuffer(music.file);
console.log(audio.duration > 0);
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.