SPB Git

Repository Public

al_lsystem.sonata 1.9 KB 68 lines

1// ORIX Sonata2// File: Examples/al_lsystem.sonata3// Description: A Lindenmayer system grown for four generations: the symbols 0 and 1 are rewritten by two rules, then read as steps up and down a lydian scale by a harp.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//8// category: Algorithmic9// title: L-System Melody10// teaches: recursion with a depth limit, list rewriting, functions, quotas-safe growth11//12// expect: notes 11813// expect: tracks 214// expect: duration 17.1429s15// expect: deterministic16// Rules: 0 -> 0 1 0, 1 -> 1 1 0. Each generation rewrites every symbol.17fn grow(word: List<Number>, generations: Number) -> List<Number> {18    if generations == 0 {19        return word20    }21    let out_word = []22    for s in word {23        if s == 0 {24            out_word = out_word + [0, 1, 0]25        } else {26            out_word = out_word + [1, 1, 0]27        }28    }29    return grow(out_word, generations - 1)30}3132composition "L-System Melody" {33    tempo 126bpm34    key F lydian3536    let notes = scale_run(F3, lydian, 3)37    // 81 symbols after four generations.38    let word = grow([0], 4)3940    instrument harp: Harp {41        gain -5dB42        let i = 743        for s in word {44            // 1 climbs two steps, 0 falls one: the line rises slowly and wraps at the top.45            i = if s == 1 then i + 2 else i - 146            if i >= len(notes) {47                i = i - 1448            }49            if i < 0 {50                i = i + 751            }52            play notes[i] duration if s == 1 then 1/16 else 1/8 velocity if s == 1 then 0.55 else 0.7553        }54        play notes[7] duration 1/155        effects {56            reverb hall(mix: 0.25)57        }58    }5960    instrument strings: SynthStrings {61        gain -14dB62        // The first generations, slowed down, as the harmony.63        for s in grow([0], 2) {64            chord if s == 0 then [F3, A3, C4, E4] else [G3, B3, D4, E4] duration 1bar velocity 0.565        }66    }67}68
Files main
Menu

Theme