Repository Public
1// ORIX Sonata2// File: Examples/ha_circle_of_fifths.sonata3// Description: All twelve major triads around the circle of fifths, generated by a loop that goes up a fifth and folds the root back into one octave, then the same circle in dominant sevenths.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//8// category: Harmony9// title: Circle of Fifths10// teaches: pitch arithmetic, modulo on pitch numbers, midi() and pitch_number(), loops over a count11//12// expect: notes 11913// expect: tracks 214// expect: duration 30.0000s15// expect: deterministic16// Folds a pitch into the octave starting at `low`.17fn fold(p: Pitch, low: Pitch) -> Pitch {18 let n = (pitch_number(p) - pitch_number(low)) % 1219 return low + 1st * n20}2122composition "Circle of Fifths" {23 tempo 96bpm24 key C major2526 instrument organ: PipeOrgan {27 gain -9dB28 let root = C329 for i in 0..12 {30 chord chord(root, major) + 12st duration 1/231 root = fold(root + 7st, C3)32 }33 chord chord(C3, major) + 12st duration 1/134 // Backwards, each chord the dominant of the next.35 for i in 0..12 {36 chord chord(root, dom7) + 12st duration 1/4 velocity 0.637 root = fold(root + 5st, C3)38 }39 chord [C3, G3, C4, E4, G4, C5] duration 2bars40 }4142 instrument pedal: SubBass {43 gain -8dB44 let root = C245 for i in 0..12 {46 play root duration 1/247 root = fold(root + 7st, C2)48 }49 play C2 duration 1/150 for i in 0..12 {51 play root duration 1/452 root = fold(root + 5st, C2)53 }54 play C2 duration 2bars55 }56}57