Repository Public
1// ORIX Sonata2// File: Examples/recursive_fractal.sonata3// Description: A melody generated by recursion: each note of a three-note motif is replaced by a smaller copy of the motif, three levels deep, on harp.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//8// expect: notes 489// expect: tracks 210// expect: duration 9.6429s11// expect: deterministic12const motif = [0st, 7st, 3st]1314// Replaces every step of `shape` by the motif transposed to it, `depth` times.15fn expand(shape: List<Interval>, depth: Number) -> List<Interval> {16 if depth == 0 {17 return shape18 }19 let grown = []20 for s in shape {21 for m in motif {22 grown = grown + [s + m]23 }24 }25 return expand(grown, depth - 1)26}2728composition "Recursive Fractal" {29 tempo 112bpm30 key C minor3132 instrument harp: Harp {33 gain -6dB34 // 3, 9 and 27 notes: the same shape at three scales.35 for depth in 0..3 {36 let line = expand(motif, depth)37 let step = note_value(1/4) / pow(2, depth)38 for i in line {39 play C4 + i duration step velocity 0.5 + 0.1 * depth40 }41 rest 1/442 }43 effects {44 reverb hall(mix: 0.25)45 }46 }4748 instrument bass: DoubleBass {49 gain -8dB50 articulation pizzicato51 for i in expand(motif, 1) {52 play C2 + i duration 1/253 }54 }55}56