Plays a parsed .song.json file against a set of instruments. More...
| Import Statement: | import Clayground.Sound |
Resolves each track's instrument field against the objectName of the provided instruments, then advances playback position in beats on an internal timer, firing triggerNote() on the matching instrument. Watches the source file for changes and hot-reloads without resetting the playhead.
A version 2 song file defines its own instruments and the structure adaptive music needs: segments with exit cues, layers an intensity fades in, transitions synced to beat, bar, exit or end, and stingers. It plays on those instruments (instruments is not read) and follows state, intensity and playStinger(). Its notes are scheduled 0.25 s ahead of the engine on their exact frames, the path renderOffline() takes, so live and offline render the same samples; a control reaches the music that much later. A song with "output": "snes" plays through the SNES-style output of the buses its instruments play on - resampled to 32 kHz with the soft top end of the chip's gaussian - from its first frame, live and offline; a song without it turns that output off on those buses.
Two players that share a bus share its SNES output: the last one to play sets it. A player turns off what it turned on when it is destroyed or loads a song that does not ask for it, but only if no player started the output since; stop() leaves it on, so what still rings rings out through it. In C++ the same rule holds through the engine: engine.snesOutput(bus).start(frame) returns a token, and release(token) turns the output off only if nothing started it, or switched it on with setEnabled(true), after that start.
SongPlayer { source: "songs/adaptive.song.json" state: game.fighting ? "combat" : "explore" intensity: game.danger }
See the Clayground.Sound Module overview or the plugin README for the JSON format.
Path to a .song.json file.
List of instrument objects (SynthInstrument / SampleInstrument etc). Each is looked up by its objectName to match track bindings.
True once the song parsed successfully.
Read-only. True while actively advancing.
Current position in beats; for a v2 song, beats into segment.
Tempo in BPM, taken from the song file.
Total length in beats (sum of section lengths (\times) repeats); for a v2 song, the length of segment.
When true, playback wraps to 0 at end instead of stopping.
Volume of the whole song, 0..1, default 1. It scales every note the player triggers, on any of its instruments, on top of the instrument's own volume and its bus volume, and it keeps scaling notes while they ring, so animating it fades the song smoothly. Two players sharing instruments keep separate volumes. A QML object in instruments that forwards triggerNote() to an instrument passes the volume on; an instrument that does not play on the Clayground.Sound engine does not get it.
Last parse/IO error, empty when OK.
Read-only. The file version of the loaded song, 1 or 2.
Version 2: the segment the music should play. Changing it moves the music there on the sync point of the first transition in the file that matches, or on the next bar. Set before play(), the segment the song starts in.
Version 2: 0..1, default 0. Each layer of the song sounds from its low to its high intensity, its level moving over the layer's fade; a note plays at the level its start falls on.
Read-only. Version 2: the segment playing now. It moves with the engine's frame, which also runs where no audio output device opens: the engine then renders on a clock of its own and nothing is heard.
Version 2: plays the stinger name on top of the music, on its sync point. Returns false for an unknown stinger or while nothing plays.
seconds of the song from its start (0 or less: its length, totalBeats at tempo) as mono samples (the (L + R) / 2 downmix, clamped to -1..1) at 44.1 kHz, with the bound instruments' current patches and the player's volume and loop. Every note starts on its exact frame, where live playback starts it on the tick it falls into. Renders on an engine of its own and does not touch the live sound or the playhead. Only SynthInstrument and SampleInstrument play here; the bus volume, echo and reverb are not part of it, a version 2 song's own echo and reverb are. A C++ program without QML renders the same samples through renderSong() of Clayground::SoundEngine.
A version 2 song renders on its own instruments, from the player's state and intensity (0 seconds: one pass of that segment), and cues steer it as a game would: [{ at: 2, state: "combat" }, { at: 3, intensity: 1 }, { at: 4, stinger: "pickup" }], at in seconds. Played live, a control reaches the song 0.25 s after it is set; cues at those song times render what was heard.
Emitted when the song reaches its end (not when looping).
Emitted after the source file changed on disk and was re-parsed successfully; playback continues from the current position.
Emitted when the source file fails to parse. On a mid-playback hot reload, the previous model is preserved and playback keeps going.
See also SynthInstrument and SampleInstrument.