Patterns & Tracks
Patterns are the core music type in Resonon. They describe sequences of notes, rests, and samples that play over time. This page covers how patterns divide time, how to nest and layer them, and how to send them to MIDI tracks.
Cycles and Time Division
Section titled “Cycles and Time Division”A pattern is enclosed in square brackets [...] and contains musical elements. Elements divide the cycle evenly:
[C4] // One note fills the whole cycle[C4 D4] // Each note gets 1/2 of the cycle[C4 D4 E4] // Each note gets 1/3 of the cycle[C4 D4 E4 F4] // Each note gets 1/4 of the cycleThe more elements in a pattern, the faster they play:
| Pattern | Elements | Duration per element |
|---|---|---|
[C4] | 1 | Full cycle |
[C4 D4] | 2 | 1/2 cycle each |
[C4 D4 E4] | 3 | 1/3 cycle each |
[C4 D4 E4 F4] | 4 | 1/4 cycle each |
With setbpm(120) and 4 beats per cycle, each cycle lasts 2 seconds. A 4-element pattern gives each element one beat (0.5 seconds).
Nesting
Section titled “Nesting”Wrap elements in [...] to subdivide their time slot:
[[C4 D4] E4] // First half subdivided into two notes, second half is one noteThis creates a triplet-like feel — C4 and D4 split the first half, E4 takes the second half. Nesting can go arbitrarily deep:
[[[C4 D4] [E4 F4 G4]] A4]Here the first half contains five notes (2 + 3), while the second half is a single note.
Chords
Section titled “Chords”Use commas to play elements simultaneously:
[C4, E4, G4] // C major chord — all three notes at onceCommas create a stack — all layers play at the same time. This is useful for chords and for layering rhythmic parts:
[bd _ sd _, ch ch ch ch] // Kick-snare rhythm with steady hi-hatsAlternating Patterns
Section titled “Alternating Patterns”Use angle brackets <...> to alternate one element per cycle:
<C4 D4 E4> // Cycle 1: C4, Cycle 2: D4, Cycle 3: E4, then repeatsThis is useful for creating variation across cycles without writing long patterns.
MIDI Tracks
Section titled “MIDI Tracks”So far you’ve used AudioTrack to play samples. MIDI tracks send note data to external synthesizers, DAWs, or hardware:
let melody = MidiTrack(1); // Channel 1melody << [C4 E4 G4 E4];PLAY;MidiTrack(channel) creates a track on a MIDI channel (1–16). The << operator works the same way — send a pattern and it loops.
Constructor Forms
Section titled “Constructor Forms”MidiTrack(1) // Channel only (velocity defaults to 100)MidiTrack(2, 80) // Channel 2, softer default velocityMidiTrack("lead", 1, 110) // Named track with custom velocityMultiple Tracks
Section titled “Multiple Tracks”Build up arrangements by creating several tracks on different channels:
let melody = MidiTrack(1);let bass = MidiTrack(2);
melody << [C4 E4 G4 E4];bass << [C2 _ C2 G2];PLAY;Each track plays its pattern independently. Changes to one don’t affect the others.
Mixing Audio and MIDI
Section titled “Mixing Audio and MIDI”Audio tracks and MIDI tracks work side by side:
use "std/instruments" { Sampler, Kit };
let drums = AudioTrack("drums");drums.load_instrument(Sampler(Kit("cr78")));drums << [bd _ sd _, ch ch ch ch];
let melody = MidiTrack(1);melody << [C4 E4 G4 E4];
PLAY;Updating Patterns Live
Section titled “Updating Patterns Live”Send a new pattern to replace the current one. The change takes effect at the next cycle boundary:
melody << [C4 E4 G4 E4]; // Start with thismelody << [D4 F4 A4 F4]; // Evaluate again — switches on next cycleThis is the core of live coding: keep playback running and re-evaluate individual lines to evolve your piece.
To clear a track, send an empty pattern:
bass << []; // Silence the bassVelocity
Section titled “Velocity”Control how loud each note plays with the ^ operator:
melody << [C4^120 D4^80 E4^60 F4^40];Values range from 0 to 127. Notes without ^ use the track’s default velocity (100, or whatever you set in the constructor).
Mix accented and default notes:
let soft = MidiTrack(2, 50); // Default velocity 50soft << [C4 D4^110 E4 F4^110]; // Accents on D4 and F4Pattern Variables
Section titled “Pattern Variables”Patterns are values — store them, pass them to functions, compose them:
let kick = [bd _ bd _];let snare = [_ _ sd _];let hats = [ch ch ch ch];
drums << [kick, snare, hats]; // Layer all threeNext Steps
Section titled “Next Steps”You can now write patterns, layer tracks, and code live. Next, learn how to organize your code into a project:
- Your First Project — Project scaffolding, structure, and
resonon run