SPB Git

Repository Public

al_probability_drums.sonata 2.2 KB 85 lines

1// ORIX Sonata2// File: Examples/al_probability_drums.sonata3// Description: A drum machine where every step has a probability of sounding: fixed kicks, likely snares on the backbeat, ghost notes and hats that thin out or fill in, all reproducible from the seed.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//8// category: Algorithmic9// title: Probability Drums10// teaches: random() against a threshold, tables of probabilities, seed, velocity variation11//12// expect: notes 16513// expect: tracks 414// expect: duration 20.0000s15// expect: deterministic16// Chance that each of the sixteen steps of a bar sounds.17const kick_p = [1, 0, 0, 0.1, 0, 0, 0.5, 0, 1, 0, 0.2, 0, 0, 0.3, 0, 0.1]18const snare_p = [0, 0, 0.05, 0, 1, 0, 0, 0.25, 0, 0.2, 0, 0, 1, 0, 0.1, 0.3]19const hat_p = [1, 0.4, 0.9, 0.4, 1, 0.4, 0.9, 0.6, 1, 0.4, 0.9, 0.4, 1, 0.5, 0.9, 0.7]2021pattern chance_bar(pitch: Pitch, table: List<Number>, loud: Velocity) {22    for p_hit in table {23        if random() < p_hit {24            // Certain hits are loud; unlikely ones are ghost notes.25            play pitch duration 1/16 velocity if p_hit >= 1 then loud else loud * (0.35 + random() * 0.3)26        } else {27            rest 1/1628        }29    }30}3132composition "Probability Drums" {33    tempo 96bpm34    seed 3033536    bus kit {37        effects {38            compressor drums39        }40        gain -2dB41    }4243    instrument kick: AcousticKick {44        output kit45        gain -3dB46        repeat 8 {47            chance_bar(C2, kick_p, 0.95)48        }49    }5051    instrument snare: FatSnare {52        output kit53        gain -6dB54        repeat 8 {55            chance_bar(D2, snare_p, 0.9)56        }57    }5859    instrument hat: ClosedHat {60        output kit61        gain -13dB62        pan 0.363        repeat 8 {64            chance_bar(F#2, hat_p, 0.7)65        }66    }6768    instrument bass: MutedBass {69        gain -5dB70        repeat 4 {71            play E2 duration 3/1672            play E2 duration 1/16 velocity 0.573            rest 1/474            play G2 duration 1/875            play A2 duration 1/876            rest 1/477            play D2 duration 3/1678            play D2 duration 1/16 velocity 0.579            rest 1/480            play B1 duration 1/481            rest 1/482        }83    }84}85
Files main
Menu

Theme