startMelody

Built-ins

Canonical ID: music.startMelody. Nederlands: startMelodie.

Starts a synthesized score on a named track without blocking the program. The score can contain notes, rests and chords. Use startOrchestra when several instrument parts must start together.

Signature

startMelody(track, score, tempo = 120, instrument = "chip", loop = false, tempoChanges = [])

Example

# language: en
startMelody("theme", "C4+E4+G4:2 F4+A4+C5:2", 120, "gm.acoustic-grand-piano", false, [[2, 90]])
wait(3)

The second chord starts after two beats, when the tempo changes from 120 to 90 BPM.

Score and tempo

A score uses space-separated tokens such as C4:1, C#4:0.5, Bb3:2, R:1 or C4+E4+G4:2. Chords have up to eight distinct pitches and one shared duration. Each event lasts 1/64–64 beats; a score contains 1–4096 events and lasts at most 4096 beats.

Choose chip, bell, pluck, flute, drums or an exact ID from the 128 gm. instruments in the block/composer picker. Pitches must fit MIDI 0–127; drums use B1–A5.

The optional final tempoChanges list contains up to 256 [beat, BPM] pairs. Beat positions start at zero, increase strictly and fall before the score ends. Tempo must be 20–400 BPM. An empty list keeps a constant tempo; a marker at zero overrides the starting tempo. Held notes remain held across a change. Looping repeats the whole score and its tempo changes.

Tracks and host support

The call returns None. Track names are case-sensitive text, 1–64 Unicode code points, nonblank and without control characters. Starting on an existing name replaces its audio while preserving its volume. Use setTrackVolume or stopTrack to control it. There are at most 16 named tracks and 32 simultaneous sounding notes.

Keep a looping track alive with events, a game loop or a positive wait. Normal program completion stops loops; Stop/Reset clean up playback. Synthesized audio requires no asset and works in the IDE, playground and supported native Windows/Linux/Raspberry Pi exports. The text-only CLI and phone preview do not play it.

The melody editor and composer edit ordinary source scores. Optional MIDI keyboard input belongs to the editor; this function does not access MIDI devices or files.