Repository Public
1// ORIX Sonata2// File: Examples/al_tone_row.sonata3// Description: A twelve-tone row and its three classical transformations, computed by functions: prime, retrograde, inversion and retrograde inversion, passed between four instruments.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//8// category: Algorithmic9// title: Tone Row10// teaches: functions over lists of intervals, reverse(), inversion as negation, voices in dialogue11//12// expect: notes 6013// expect: tracks 514// expect: duration 22.8571s15// expect: deterministic16// The row as semitones above the first note; all twelve pitch classes once.17const row = [0, 11, 3, 4, 8, 7, 9, 5, 6, 1, 2, 10]1819fn inversion(r: List<Number>) -> List<Number> {20 let acc = []21 for x in r {22 acc = acc + [(12 - x) % 12]23 }24 return acc25}2627pattern state(base: Pitch, r: List<Number>, step: Duration) {28 for i in 0..len(r) {29 // Every third note is held longer, so the row keeps one rhythm in all four forms.30 play base + 1st * r[i] duration if i % 3 == 2 then step * 2 else step31 }32}3334composition "Tone Row" {35 tempo 84bpm3637 instrument flute: Flute {38 gain -7dB39 pan -0.440 state(E5, row, 1/8)41 rest 6bars42 }4344 instrument clarinet: Clarinet {45 gain -7dB46 pan 0.447 rest 2bars48 state(E4, reverse(row), 1/8)49 rest 4bars50 }5152 instrument viola: Viola {53 gain -6dB54 pan -0.1555 rest 4bars56 state(E4, inversion(row), 1/8)57 rest 2bars58 }5960 instrument cello: Cello {61 gain -6dB62 pan 0.1563 rest 6bars64 state(E3, reverse(inversion(row)), 1/8)65 }6667 instrument vibes: Vibraphone {68 gain -10dB69 // The row as four trichords, one every two bars.70 for k in 0..4 {71 chord [E4 + 1st * row[3 * k], E4 + 1st * row[3 * k + 1], E4 + 1st * row[3 * k + 2]] duration 2bars velocity 0.572 }73 }74}75