Rhythm
A track has a cursor: a position in musical time that starts at zero. Every statement places something at the cursor and moves it. Rhythm in Sonata is the art of moving the cursor.
Durations
A duration is a fraction of a whole note.
| Written | Note value |
|---|---|
1/1 |
whole |
1/2 |
half |
1/4 |
quarter |
1/8 |
eighth |
1/16 |
sixteenth |
3/8 |
dotted quarter (also dotted(1/4)) |
1/12 |
eighth-note triplet (also triplet(1/8)) |
2bars, 3beats |
bars and beats of the current signature |
composition "Durations" {
tempo 100bpm
instrument piano: GrandPiano {
play C4 duration 1/4
play D4 duration 1/8
play E4 duration 1/8
play F4 duration 3/8 // dotted quarter
play G4 duration 1/8
rest 1/4
play C5 duration dotted(1/2) // the same as 3/4
}
}default duration and default velocity set what a play uses when it does not say:
default duration 1/16
default velocity 0.6
play C4
play D4
play E4
play F4
play G4 duration 1/4 velocity 0.9Rests, groups and position
rest Dmoves the cursor forward.sequence { … }is a plain group: its statements run one after the other.at POSITION { … }runs a block at an absolute position and then puts the cursor back where it was. Use it to place something without counting rests.
composition "Position" {
instrument piano: GrandPiano {
play C3 duration 2bars
at 1bar {
// Starts at bar 2 whatever came before.
chord [E4, G4, C5] duration 1bar
}
at 1bar + 3/4 {
play C6 duration 1/4
}
}
}Voices and parallel lines
A track can carry several lines at once.
- Adjacent
voice { }blocks start together, each on its own voice. The cursor then advances by the longest of them. - In
parallel { }, every direct statement starts at the cursor.
composition "Voices" {
tempo 80bpm
instrument organ: FluteOrgan {
gain -8dB
voice {
play E4 duration 1/2
play F4 duration 1/2
play G4 duration 1/1
}
voice {
play C3 duration 1/1
play C3 duration 1/1
}
// Both voices have ended; this chord starts at bar 3.
parallel {
play C3 duration 1/1
play G3 duration 1/1
play E4 duration 1/1
}
}
}Loops
repeat N { } runs a block N times. for x in LIST { } runs it once per element.
composition "Loops" {
instrument marimba: Marimba {
repeat 2 {
for n in [C4, E4, G4, E4] {
play n duration 1/8
}
}
for i in 0..4 {
// Louder on each repetition.
play C5 duration 1/4 velocity 0.4 + i * 0.15
}
}
}Tuplets
tuplet N in M { } plays N notes in the time of M: every duration inside is multiplied by
M/N. Tuplets nest.
composition "Tuplets" {
instrument piano: GrandPiano {
tuplet 3 in 2 {
// Three eighths in the time of two: an eighth-note triplet.
play C4 duration 1/8
play E4 duration 1/8
play G4 duration 1/8
}
tuplet 5 in 4 {
for n in [C5, B4, A4, G4, F4] {
play n duration 1/16
}
}
play C4 duration 1/2
}
}You can also write the fraction directly: 1/12 is one note of an eighth-note triplet.
Articulation
An articulation changes how a note is played. It is written after the note, or set for the
whole track with articulation.
| Articulation | Sounding length | Velocity |
|---|---|---|
staccato |
50 % of the written duration | unchanged |
staccatissimo |
25 % | unchanged |
marcato |
100 % | × 1.2 (at most 1) |
accent |
100 % | × 1.25 (at most 1) |
normal, legato, tenuto, pizzicato, tremolo |
100 % | unchanged |
These are the only places where the compiler changes what you wrote, and it does exactly
this. The cursor always advances by the written duration. Instruments also receive the
articulation and may respond: a bowed string slurs legato notes and plucks pizzicato.
composition "Articulation" {
instrument violin: Violin {
play G4 duration 1/4 staccato
play A4 duration 1/4 staccato
play B4 duration 1/4 accent
play G4 duration 1/4 marcato
articulation legato
play D5 duration 1/2
play B4 duration 1/2
}
}Ties
tie joins a note to the next note of the same pitch in the same voice. The two become one
sounding note; the score still shows two notes joined by a tie, split at the bar line.
composition "Ties" {
signature 3/4
instrument flute: Flute {
play D5 duration 3/4 tie
play D5 duration 1/4
play E5 duration 1/4
play F5 duration 1/4
}
}A tie that nothing continues is reported (warning M4005) and the note sounds as written.
Swing
swing R delays the off-beats. With a ratio R between 50 % (straight) and 75 %, a note that
starts on an odd multiple of the swing unit starts (2R − 1) × unit later and still ends where
it would have. The unit is an eighth note unless you say of 1/16.
composition "Swing" {
tempo 120bpm
swing 66%
instrument piano: ElectricPiano {
repeat 2 {
for n in [C4, E4, G4, A4, Bb4, A4, G4, E4] {
play n duration 1/8
}
}
}
}swing at composition level applies to every track. Inside a track, swing 60% { … } applies
to a block and swing 60% from that point on.
Tempo
tempo sets the tempo in quarter notes per minute, whatever the signature. Written inside a
composition, it applies from the beginning. To change it later, place it with at:
composition "Tempo Changes" {
tempo 80bpm
at 2bars {
tempo 120bpm
}
at 4bars {
// A ritardando: from 120 to 60 over two bars.
tempo 60bpm ramp 2bars
}
instrument piano: GrandPiano {
repeat 6 {
for n in [C4, G4, E4, G4] {
play n duration 1/4
}
}
}
}tempo T ramp D moves the tempo in a straight line, in musical position, from the tempo in
effect to T over the duration D. Declare tempo changes at composition level so that every
track sees the same map. The exact rule that turns positions into seconds is given in
Architecture.
Time signatures
signature N/D decides what bars and beats mean and how the score is barred. It does not
change durations written as fractions. A change must fall on a bar line:
composition "Signatures" {
tempo 132bpm
signature 7/8
at 2bars {
signature 4/4
}
instrument marimba: Marimba {
repeat 2 {
// 7/8 as 2 + 2 + 3
play A3 duration 1/4 accent
play E4 duration 1/4
play A4 duration 3/8 accent
}
repeat 2 {
for n in [A3, C4, E4, A4] {
play n duration 1/4
}
}
}
}A change in the middle of a bar is error M4002, with the advice complete the bar with a rest first.
Euclidean rhythms
euclid(hits, steps) spreads a number of hits as evenly as possible over a number of steps
and returns a list of booleans. The standard pattern rhythm plays a pitch on each hit.
composition "Euclid" {
tempo 110bpm
instrument kick: Kick {
repeat 2 {
rhythm(C2, euclid(3, 8), step: 1/8)
}
}
instrument hat: ClosedHat {
gain -10dB
repeat 2 {
rhythm(F#2, euclid(5, 8), step: 1/8, vel: 0.5)
}
}
}rotate(xs, n) shifts a rhythm so that it starts on another step.