Kunquat – a fresh take on old school trackers

The specification document is in an early drafting phase.

Kunquat, the Specification

State Machine

Kunquat audio rendering is based around a state machine and three factors: initialisation set used to initialise the machine, audio rate used to control resolution of the execution, and a stream of commands that is used to request audio from and to interact with the state machine.

The state machine is initialised with a set of key/value pairs that define available audio units (i.e. instrument and effects) and a connection graph that connects the instruments through various effects to a stereo output. The initialisation data may also contain an album of songs described as note data that can be used to control the audio units without human intervention.

In addition to providing an initialisation set, the user needs to select an audio rate. The audio rate affects the resolution at which the audio rendering and event processing are done. A higher audio rate produces a more accurate estimation of the sound described by the parameters and make it possible to interact with the state machine more tightly. Specifying a lower audio rate reduces the amount of computation required.

Once the state machine has been initialised, the operation proceeds by feeding commands to the state machine. The possible commands are:

render
Produce a chunk of audio data together with information of any events that were processed during the rendering of the audio chunk.
fire
Feed external events into the state machine.
get_events
Retrieve a set of events that were processed during the last call of render or fire.

Event

The events fired by the state machine contain one or zero parameters. Firing an event modifies the internal state of the state machine.

Trigger

Triggers are used for launching events in an automated fashion. A trigger consists of an event name and an expression. Processing a trigger includes evaluating the expression and launching an event with the value of the expression as a parameter.

Channel

Channels are numbers used for addressing audio unit controls. At any given time a channel has one or zero selected note outputs and one or zero active audio units. Some channel events affect the audio unit either directly or through the selected note output.

Environment

Environment is a variable space that can be used to parameterise parts of the automated playback.

Connection Graph

Connection graph connects instruments through effects into master output.

Randomness

Kunquat composition defines a global random seed that is used to initialise random number generators for various contexts at the start of playback.

Initialisation Set

kqtc00/p_composition.json
kqtc00/p_connections.json
kqtc00/p_random_seed.json

Album Description

kqtc00/album/p_manifest.json
kqtc00/album/p_tracks.json

Audio Unit Description

kqtc00/au_00/hit_00/p_hit_proc_filter.json
kqtc00/au_00/hit_00/p_manifest.json
kqtc00/au_00/p_connections.json
kqtc00/au_00/p_expressions.json
kqtc00/au_00/p_manifest.json
kqtc00/au_00/p_streams.json

Processor Description

kqtc00/au_00/proc_00/c/mod_00/p_f_pitch.json
kqtc00/au_00/proc_00/c/mod_00/p_f_volume.json
kqtc00/au_00/proc_00/c/p_base.wav
kqtc00/au_00/proc_00/c/p_hm_hit_map.json
kqtc00/au_00/proc_00/c/p_nm_note_map.json
kqtc00/au_00/proc_00/c/smp_000/p_sh_sample.json
kqtc00/au_00/proc_00/c/smp_000/p_sample.wv
kqtc00/au_00/proc_00/c/tone_00/p_f_pan.json
kqtc00/au_00/proc_00/c/tone_00/p_f_pitch.json
kqtc00/au_00/proc_00/c/tone_00/p_f_volume.json
kqtc00/au_00/proc_00/p_manifest.json

Pattern Description

kqtc00/pat_000/col_00/p_triggers.json
kqtc00/pat_000/instance_000/p_manifest.json
kqtc00/pat_000/p_length.json
kqtc00/pat_000/p_manifest.json

Tuning Table Description

kqtc00/tuning_00/p_tuning_table.json

Song Description

kqtc00/song_00/p_manifest.json
kqtc00/song_00/p_order_list.json
kqtc00/song_00/p_tempo.json

Events

The events are categorised based on their scope and intended use.

About Slide Events

Some parameters in the playback state can be controlled with slides. Such parameters include note force and pitch, among others. Most slides are specified with a slide target event (denoted by forward slash ‘/’ in the event name) and a slide length event (denoted by forward slash and equals sign ‘/=’ in the event name). Oscillation parameter changes are always performed with slides (with slide length of 0 by default), even though their slide target events are not named with the forward slash.

The slide target event starts the slide progress from the current parameter value to the target value. The slide is initialised with the length specified by the latest corresponding slide length event, or length 0 if no length has been specified. However, it is also possible to specify the slide length after the slide target in the same trigger row. If a slide length is updated while the slide is in progress, the remaining part of the slide will have the length specified by the new slide length event.

All slides are linear in the scale in which they are documented. For example, when a force value is slid from 0 to -6 dBFS, the active force will be -3 dBFS exactly halfway through the slide. Note, however, that tempo adjustments affect the speeds of all slides, since the slide lengths are specified in timestamps.

Triggers for Name/Value Pair Control

Several events (stream, environment variable and device events) control values that are specified with a name setting event (e.g. ‘.s’ modifies a stream whose name is specified with ‘.sn’). For these event pairs, triggers support syntactic sugar of the form [.s:foo x] that is equivalent to triggers [.sn 'foo'] [.s x].

Control Events

Control events are used for controlling generic playback-related behaviour. They are mostly intended to be used by editors and, to certain extent, interactive compositions. Most control events may cause infinite loops in compositions; therefore, control events specified in triggers are ignored by default.

cpause Stop reading pattern data Stop the playback cursor. Active notes and effects will continue to be processed. New events can only be fired through the external interface. This event has no effect if the playback is already paused.
cresume Continue reading pattern data Resume playback cursor movement. This event has no effect unless the playback is paused.
cpattern Read triggers from pattern instance x in a continuous loop Jump to the beginning of pattern instance x and play that pattern instance in an infinite loop. This is mostly intended to be used by editors.
c.gp Set unconditional jump target pattern instance x Set target pattern instance x for event cg. This event does not cause jumping by itself.
c.gr Set unconditional jump target row x Set target row of timestamp x for event cg. This event does not cause jumping by itself.
cg Jump unconditionally Jump to location specified by events c.gp and c.gr. If the target pattern instance has not been specified, the first pattern instance of the first song will be used. If the target row has not been specified, timestamp 0 will be used.
cinfinite+ Enable infinite playback mode By default, control events specified by triggers are ignored. This event will enable the processing of such triggers. Note that, being a control event itself, this event must be fired through the external interface to have an effect. Additionally, playback will jump to the beginning of the specified song if the end is reached. This event has no effect if the infinite playback mode is already enabled.
cinfinite- Disable infinite playback mode Disable control events caused by triggers and stop playback when the end of the specified song is reached. Note that this effect will not disable pattern playback mode. This event has no effect if the infinite playback mode is already disabled.
c.evn Select environment variable x Select environment variable named x for storing a value.
c.ev Set value x of selected environment variable Set value x of an environment variable. The variable name specified with the last c.evn event in the current channel is used. This event has no effect if the type of x is not compatible with the target environment variable.

General Events

#       Do nothing with string value x

?       Event_general_cond
?if     Event_general_if
?else   Event_general_else
?end    Event_general_end_if

calln   Do nothing with string value x
call    Do nothing with any value x

Master Events

mpd Pattern delay by timestamp x Suspend playback cursor for duration specified by timestamp x.
m.jc Set jump counter x Set jump counter used by the jump event mj. Valid range for x is [0, 32767].
m.jp Set jump target pattern instance x Set target pattern instance for the jump event mj.
m.jr Set jump target row x Set target row of timestamp x for the jump event mj.
mj Jump fixed number of times Jump to location specified by events m.jp and m.jr a number of times specified by event m.jc. When the jump event is processed normally, the current playback cursor position (pattern instance, row timestamp, channel number and trigger row offset) is marked as a jump position with the given jump counter. If a playback cursor location is marked as a jump position, the possible corresponding mj trigger is ignored and the jump position is processed. If the jump counter of a jump position is positive, the counter is decremented by 1 and the jump is performed. If the counter is zero, the jump position information will be removed.
m.t Set tempo to x Set tempo to x beats per minute.
m/t Slide tempo to x Slide tempo to x beats per minute. Note that Kunquat implementations are expressly allowed to perform tempo slides in a lower resolution than implied by the audio rate, in order to simplify implementation of the sequencer.
m/=t Set tempo slide length to x Set tempo slide length specified by timestamp x. The length of the slide is interpreted in relation to the logical composition time. For instance, if a tempo slide of length 3 begins at row timestamp 2, the slide is always finished at timestamp 5, regardless of initial and final tempo values.
m.v Set global volume to x dBFS
m/v Slide global volume to x dBFS
m/=v Set global volume slide length to timestamp x
m.r Set active retuner to x
m.rfp Set fixed pitch of the active retuner to x
m.rc Set tuning centre of the active retuner to x
m.ro Set active retuner pitch offset to x cents
mmr Apply initial settings of retuner x to the active retuner
m<r Reset active retuner

Channel Events

.a Set active audio unit control x
n+ Note on with pitch x Start a new note with pitch of x cents. This event has no effect if the selected audio unit does not support voice control.
h Hit with index x Start a new note with hit index x. This event has no effect if the selected audio unit does not support voice control.
n- Note off Release an active note or hit. This event has no effect if there is no foreground note in the channel. The released note or hit can no longer be controlled directly through events.
.f Set force to x Set force of the currently active note to x + s dBFS, where s is the global note force shift (-30 by default).
/f Slide force to x Slide force from current force to x + s dBFS, where s is the global note force shift (-30 by default). The slide is performed using slide length specified by /=f.
/=f Set force slide length to x Use timestamp x as the length of the force slide started by the /f event.
ts Set tremolo speed target to x Set tremolo speed target to x cycles per second. By default, the new speed takes full effect immediately; use the t/=s event for controlling the duration of the transition. Setting zero as the new speed target restores the original force level.
td Set tremolo depth target to x Set tremolo depth target to ±x dB. By default, the new depth takes full effect immediately; use the t/=d event for controlling the duration of the transition. Valid range for x is [0, 24].
t/=s Set tremolo speed slide length to x Use timestamp x as the length of the tremolo speed slide.
t/=d Set tremolo depth slide length to x Use timestamp x as the length of the tremolo depth slide.
->f+ Turn on force carrying Enable carrying of force effects (fixed force, slide and tremolo) from one note to the next. This needs to be applied before the first note that should inherit the force controls of the previous note.
->f- Turn off force carrying Disable carrying of force effects between notes.
/p Slide pitch to x Slide pitch to x cents from current pitch, using slide length specified by the /=p event.
/=p Set pitch slide length to x Use timestamp x as the length of the pitch slide started by the /p event.
vs Set vibrato speed target to x Set vibrato speed target to x cycles per second.
vd Set vibrato depth target to x Set vibrato depth target to x * 5 cents. The depth is the maximum deviation, e.g. a depth of 240 has peaks at one octave above and below the centre pitch.
v/=s Set vibrato speed slide length to x Use timestamp x as the length of the vibrato speed slide.
v/=d Set vibrato depth slide length to x Use timestamp x as the length of the vibrato depth slide.
->p+ Turn on pitch carrying Enable carrying of pitch effects (pitch slide and vibrato) from one note to the next. This needs to be applied before the first note that should inherit the pitch controls of the previous note.
->p- Turn off pitch carrying Disable carrying of pitch effects between notes.
.sn Select channel stream x
.s Set value of a channel stream to x
/s Slide channel stream to x
/=s Set slide length of channel stream to x
os Set oscillation speed of channel stream to x
od Set oscillation depth of channel stream to x
o/=s Set oscillation speed slide length of channel stream to x
o/=d Set oscillation depth slide length of channel stream to x
->s+ Turn on channel stream carrying
->s- Turn off channel stream carrying
.xc Set channel expression to x Set expression applied to all notes in the channel from the current timestamp onwards (including any notes previously started on the same row). Setting the expression to empty string disables channel expression, and setting no value applies the channel default expression setting.
.x Set note expression to x Set expression applied to a note just started. This only affects notes that haven't rendered audio yet. Setting the expression to empty string disables note expression, and setting no value applies the instrument default expression setting.
->x+ Turn on note expression carrying
->x- Turn off note expression carrying
.dn Set channel device event name to x
d Fire channel device event with argument x

Audio Unit Events

abp+ Turn on audio unit bypass
abp- Turn off audio unit bypass
a.s Set value of audio unit stream to x
a/s Slide audio unit stream to x
a/=s Set slide length of audio unit stream to x
aos Set oscillation speed of audio unit stream to x
aod Set oscillation depth of audio unit stream to x
ao/=s Set oscillation speed slide length of audio unit stream to x
ao/=d Set oscillation depth slide length of audio unit stream to x
ad Fire audio unit device event with argument x
a.sus Set instrument sustain value to x Set sustain to a normalised value between 0 and 1. 0 disables sustain completely, 1 applies full sustain. Sustain slows down the processing of note release envelopes. If a force release envelope is not enabled, values ≥ 0.5 disable cutting of a released note.

Query Events

Query events are used to request information from the rendering engine.

qlocation   Force generation of events Atrack, Asystem and Arow
qvoices     Force generation of event Avoices
qf          Force generation of event Af.

Auto Events

Auto events fired with the fire command are ignored. The rendering engine creates auto events to report updates in the playback status.

Atrack      Do nothing with the current track number x.
Asystem     Do nothing with the current system number x.
Arow        Do nothing with the current pattern location timestamp x.
Avoices     Do nothing with the current active voice count x.
Af          Do nothing with the current actual force x of an active note.

Appendix A: Module Format

The save feature in Kunquat Tracker stores initialization sets in zip files. Such saved files are called Kunquat modules. The keys of the initialization set are presented as file paths in the zip file and the values are stored as contents of the corresponding files. In addition to the values required for playback, the tracker extends the initialisation set with some metadata. See Appendix B for description of the metadata.

Appendix B: Metadata and Interface Data

kqtc00/au_00/m_name.json    contains the name of the audio unit

kqtc00/m_authors.json
kqtc00/m_title.json

kqtc00/i_grid_enabled.json
kqtc00/i_grid_patterns.json
kqtc00/pat_000/i_base_grid.json
kqtc00/pat_000/col_00/i_overlay_grids.json

Appendix C: Rendering Limitations

It is often desirable to specify limitations for rendering software. While implementing Kunquat, we have specified such limits for the amount of polyphony, the amount of active jump counters, the amount of nested ifs, the resolution of tempo slides, and the number of unconditional jumps performed without rendering audio between the jumps.

Appendix D: Editing Behaviour

Editors may wish to change the initialization set during rendering. This may cause the rendered sound to differ from the specified outcome during editing. In many cases this could be reasonable trade-off as working with an editor is largely about modifying the initialization set.