Repository Public
1// ORIX Sonata2// File: Examples/al_random_walk.sonata3// Description: A seeded random walk on a pentatonic scale: each step moves up or down by at most two scale degrees and is reflected at the edges; the same seed always gives the same melody.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//8// category: Algorithmic9// title: Random Walk10// teaches: seed, random_int(), clamp(), variables in a track, determinism11//12// expect: notes 11313// expect: tracks 214// expect: duration 27.7778s15// expect: deterministic16composition "Random Walk" {17 tempo 108bpm18 key A minor19 seed 17292021 let notes = scale_run(A3, pentatonic_minor, 2)2223 instrument kalimba: Kalimba {24 gain -5dB25 let position = 526 repeat 96 {27 position = clamp(position + random_int(-2, 2), 0, len(notes) - 1)28 // Long notes are rarer than short ones.29 play notes[position] duration choose([1/16, 1/16, 1/8, 1/8, 1/8, 1/4]) velocity 0.5 + random() * 0.430 }31 play notes[0] duration 1/132 effects {33 delay echo(time: note_value(3/16), feedback: 0.35, mix: 0.2)34 reverb room(mix: 0.2)35 }36 }3738 instrument pad: SynthPad {39 gain -16dB40 // Each track has its own random stream: this one is not disturbed by the walk above.41 repeat 4 {42 chord [A2, E3, choose([A3, C4, D4]), choose([E4, G4])] duration 2bars43 }44 }45}46