SPB Git

Repository Public

rhythm.md 7.9 KB 311 lines markdown

1<!--2ORIX Sonata3File: Documentation/manual/rhythm.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Rhythm89A track has a **cursor**: a position in musical time that starts at zero. Every statement10places something at the cursor and moves it. Rhythm in Sonata is the art of moving the cursor.1112## Durations1314A duration is a fraction of a whole note.1516| Written | Note value |17|---|---|18| `1/1` | whole |19| `1/2` | half |20| `1/4` | quarter |21| `1/8` | eighth |22| `1/16` | sixteenth |23| `3/8` | dotted quarter (also `dotted(1/4)`) |24| `1/12` | eighth-note triplet (also `triplet(1/8)`) |25| `2bars`, `3beats` | bars and beats of the current signature |2627```sonata28composition "Durations" {29    tempo 100bpm30    instrument piano: GrandPiano {31        play C4 duration 1/432        play D4 duration 1/833        play E4 duration 1/834        play F4 duration 3/8            // dotted quarter35        play G4 duration 1/836        rest 1/437        play C5 duration dotted(1/2)    // the same as 3/438    }39}40```4142`default duration` and `default velocity` set what a `play` uses when it does not say:4344```sonata,fragment45default duration 1/1646default velocity 0.647play C448play D449play E450play F451play G4 duration 1/4 velocity 0.952```5354## Rests, groups and position5556* `rest D` moves the cursor forward.57* `sequence { … }` is a plain group: its statements run one after the other.58* `at POSITION { … }` runs a block at an absolute position and then puts the cursor back where59  it was. Use it to place something without counting rests.6061```sonata62composition "Position" {63    instrument piano: GrandPiano {64        play C3 duration 2bars65        at 1bar {66            // Starts at bar 2 whatever came before.67            chord [E4, G4, C5] duration 1bar68        }69        at 1bar + 3/4 {70            play C6 duration 1/471        }72    }73}74```7576## Voices and parallel lines7778A track can carry several lines at once.7980* Adjacent `voice { }` blocks start together, each on its own voice. The cursor then advances81  by the longest of them.82* In `parallel { }`, every direct statement starts at the cursor.8384```sonata85composition "Voices" {86    tempo 80bpm87    instrument organ: FluteOrgan {88        gain -8dB89        voice {90            play E4 duration 1/291            play F4 duration 1/292            play G4 duration 1/193        }94        voice {95            play C3 duration 1/196            play C3 duration 1/197        }98        // Both voices have ended; this chord starts at bar 3.99        parallel {100            play C3 duration 1/1101            play G3 duration 1/1102            play E4 duration 1/1103        }104    }105}106```107108## Loops109110`repeat N { }` runs a block N times. `for x in LIST { }` runs it once per element.111112```sonata113composition "Loops" {114    instrument marimba: Marimba {115        repeat 2 {116            for n in [C4, E4, G4, E4] {117                play n duration 1/8118            }119        }120        for i in 0..4 {121            // Louder on each repetition.122            play C5 duration 1/4 velocity 0.4 + i * 0.15123        }124    }125}126```127128## Tuplets129130`tuplet N in M { }` plays N notes in the time of M: every duration inside is multiplied by131M/N. Tuplets nest.132133```sonata134composition "Tuplets" {135    instrument piano: GrandPiano {136        tuplet 3 in 2 {137            // Three eighths in the time of two: an eighth-note triplet.138            play C4 duration 1/8139            play E4 duration 1/8140            play G4 duration 1/8141        }142        tuplet 5 in 4 {143            for n in [C5, B4, A4, G4, F4] {144                play n duration 1/16145            }146        }147        play C4 duration 1/2148    }149}150```151152You can also write the fraction directly: `1/12` is one note of an eighth-note triplet.153154## Articulation155156An articulation changes how a note is played. It is written after the note, or set for the157whole track with `articulation`.158159| Articulation | Sounding length | Velocity |160|---|---|---|161| `staccato` | 50 % of the written duration | unchanged |162| `staccatissimo` | 25 % | unchanged |163| `marcato` | 100 % | × 1.2 (at most 1) |164| `accent` | 100 % | × 1.25 (at most 1) |165| `normal`, `legato`, `tenuto`, `pizzicato`, `tremolo` | 100 % | unchanged |166167These are the only places where the compiler changes what you wrote, and it does exactly168this. The cursor always advances by the written duration. Instruments also receive the169articulation and may respond: a bowed string slurs `legato` notes and plucks `pizzicato`.170171```sonata172composition "Articulation" {173    instrument violin: Violin {174        play G4 duration 1/4 staccato175        play A4 duration 1/4 staccato176        play B4 duration 1/4 accent177        play G4 duration 1/4 marcato178        articulation legato179        play D5 duration 1/2180        play B4 duration 1/2181    }182}183```184185## Ties186187`tie` joins a note to the next note of the same pitch in the same voice. The two become one188sounding note; the score still shows two notes joined by a tie, split at the bar line.189190```sonata191composition "Ties" {192    signature 3/4193    instrument flute: Flute {194        play D5 duration 3/4 tie195        play D5 duration 1/4196        play E5 duration 1/4197        play F5 duration 1/4198    }199}200```201202A tie that nothing continues is reported (warning M4005) and the note sounds as written.203204## Swing205206`swing R` delays the off-beats. With a ratio `R` between 50 % (straight) and 75 %, a note that207starts on an odd multiple of the swing unit starts `(2R − 1) × unit` later and still ends where208it would have. The unit is an eighth note unless you say `of 1/16`.209210```sonata211composition "Swing" {212    tempo 120bpm213    swing 66%214    instrument piano: ElectricPiano {215        repeat 2 {216            for n in [C4, E4, G4, A4, Bb4, A4, G4, E4] {217                play n duration 1/8218            }219        }220    }221}222```223224`swing` at composition level applies to every track. Inside a track, `swing 60% { … }` applies225to a block and `swing 60%` from that point on.226227## Tempo228229`tempo` sets the tempo in quarter notes per minute, whatever the signature. Written inside a230composition, it applies from the beginning. To change it later, place it with `at`:231232```sonata233composition "Tempo Changes" {234    tempo 80bpm235    at 2bars {236        tempo 120bpm237    }238    at 4bars {239        // A ritardando: from 120 to 60 over two bars.240        tempo 60bpm ramp 2bars241    }242    instrument piano: GrandPiano {243        repeat 6 {244            for n in [C4, G4, E4, G4] {245                play n duration 1/4246            }247        }248    }249}250```251252`tempo T ramp D` moves the tempo in a straight line, in musical position, from the tempo in253effect to `T` over the duration `D`. Declare tempo changes at composition level so that every254track sees the same map. The exact rule that turns positions into seconds is given in255[Architecture](architecture.md#time).256257## Time signatures258259`signature N/D` decides what `bars` and `beats` mean and how the score is barred. It does not260change durations written as fractions. A change must fall on a bar line:261262```sonata263composition "Signatures" {264    tempo 132bpm265    signature 7/8266    at 2bars {267        signature 4/4268    }269    instrument marimba: Marimba {270        repeat 2 {271            // 7/8 as 2 + 2 + 3272            play A3 duration 1/4 accent273            play E4 duration 1/4274            play A4 duration 3/8 accent275        }276        repeat 2 {277            for n in [A3, C4, E4, A4] {278                play n duration 1/4279            }280        }281    }282}283```284285A change in the middle of a bar is error M4002, with the advice *complete the bar with a rest286first*.287288## Euclidean rhythms289290`euclid(hits, steps)` spreads a number of hits as evenly as possible over a number of steps291and returns a list of booleans. The standard pattern `rhythm` plays a pitch on each hit.292293```sonata294composition "Euclid" {295    tempo 110bpm296    instrument kick: Kick {297        repeat 2 {298            rhythm(C2, euclid(3, 8), step: 1/8)299        }300    }301    instrument hat: ClosedHat {302        gain -10dB303        repeat 2 {304            rhythm(F#2, euclid(5, 8), step: 1/8, vel: 0.5)305        }306    }307}308```309310`rotate(xs, n)` shifts a rhythm so that it starts on another step.311
Files main
Menu

Theme