Repository Public
1// ORIX Sonata2// File: Examples/algorithmic_canon.sonata3// Description: A seeded random-walk melody played as a three-voice canon, with augmentation and a tuplet cadence.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//8// expect: notes 859// expect: tracks 310// expect: duration 13.7500s11// expect: deterministic12// A random walk on scale degrees, kept inside one octave and a half.13fn walk_melody(length: Number) -> List<Number> {14 let degrees = [1]15 let current = 116 for i in 1..length {17 current = clamp(current + choose([-2, -1, -1, 1, 1, 2]), 1, 11)18 degrees = degrees + [current]19 }20 return degrees21}2223pattern line(degrees: List<Number>, octave: Number, step: Duration, vel: Velocity) {24 for d in degrees {25 play degree(d, octave) duration step velocity vel26 }27}2829composition "Algorithmic Canon" {30 tempo 96bpm31 key G dorian32 seed 3143334 // One melody for every voice: evaluated once at composition level.35 let theme = walk_melody(16)3637 instrument dux: Flute {38 gain -8dB39 pan -0.340 line(theme, 5, 1/8, 0.75)41 line(reverse(theme), 5, 1/8, 0.7)42 tuplet 3 in 2 {43 line(take(theme, 6), 5, 1/8, 0.8)44 }45 play degree(1, 5) duration 1/246 }4748 instrument comes: Clarinet {49 gain -9dB50 pan 0.351 rest 1bar52 transpose -5st {53 line(theme, 4, 1/8, 0.7)54 line(reverse(theme), 4, 1/8, 0.65)55 }56 play degree(5, 4) duration 1/257 }5859 instrument ground: Cello {60 gain -7dB61 // The same theme twice as slow: augmentation.62 line(take(theme, 12), 3, 1/4, 0.7)63 play degree(1, 3) duration 1bar tie64 play degree(1, 3) duration 1/265 }6667 master {68 effects {69 reverb chamber(mix: 0.22)70 }71 }72}73