SPB Git

Repository Public

al_markov_chords.sonata 2.0 KB 65 lines

1// ORIX Sonata2// File: Examples/al_markov_chords.sonata3// Description: A chord progression drawn from a transition table: each chord lists the chords that may follow it, with repeats in the list acting as weights.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//8// category: Algorithmic9// title: Markov Chords10// teaches: const tables, nested lists, choose() in a function, sharing one random draw between tracks11//12// expect: notes 23113// expect: tracks 214// expect: duration 43.6364s15// expect: deterministic16// Scale degrees of C major, 0 = I ... 5 = vi. Row i lists what may follow chord i.17const next = [[3, 3, 4, 5, 1], [4, 4, 4, 3], [5, 3, 3], [4, 4, 0, 1], [0, 0, 0, 5, 3], [3, 1, 1, 4]]18const roots = [C3, D3, E3, F3, G3, A3]19const qualities = [maj7, min7, min7, maj7, dom7, min7]2021// Walks the table for `count` chords, starting on I.22fn walk(count: Number) -> List<Number> {23    let states = [0]24    let state = 025    repeat count - 1 {26        state = choose(next[state])27        states = states + [state]28    }29    return states30}3132composition "Markov Chords" {33    tempo 88bpm34    key C major35    seed 73637    // Drawn once, outside the tracks, so the keys and the bass play the same progression.38    let states = walk(15)3940    instrument keys: ElectricPiano {41        gain -6dB42        for state in states {43            let c = chord(roots[state], qualities[state])44            chord c duration 3/8 velocity 0.6545            chord invert(c, 1) duration 3/8 velocity 0.546            chord c duration 1/4 velocity 0.4547        }48        chord chord(C3, maj9) duration 1/149        effects {50            chorus lush(mix: 0.3)51            reverb room(mix: 0.2)52        }53    }5455    instrument bass: FingerBass {56        gain -5dB57        for state in states {58            play roots[state] - 12st duration 3/859            play roots[state] - 12st duration 3/8 velocity 0.660            play roots[state] - 5st duration 1/4 velocity 0.661        }62        play C2 duration 1/163    }64}65
Files main
Menu

Theme