fn start => { | | sample_rate => sample_rate . 0.125 => volume . 240 => beats_per_minute . 32 => length_in_beats . -9 note => c4 . -8 note => c4♯ . c4♯ => d4♭ . -7 note => d4 . -6 note => d4♯ . d4♯ => e4♭ . -5 note => e4 . -4 note => f4 . -3 note => f4♯ . f4♯ => g4♭ . -2 note => g4 . -1 note => g4♯ . g4♯ => a4♭ . 0 note => a4 . 1 note => a4♯ . a4♯ => b4♭ . 2 note => b4 . c4 2 / => c3 . c4♯ 2 / => c3♯ . d4♭ 2 / => d3♭ . d4 2 / => d3 . d4♯ 2 / => d3♯ . e4♭ 2 / => e3♭ . e4 2 / => e3 . f4 2 / => f3 . f4♯ 2 / => f3♯ . g4♭ 2 / => g3♭ . g4 2 / => g3 . g4♯ 2 / => g3♯ . a4♭ 2 / => a3♭ . a4 2 / => a3 . a4♯ 2 / => a3♯ . b4♭ 2 / => b3♭ . b4 2 / => b3 . c3 2 / => c2 . c3♯ 2 / => c2♯ . d3♭ 2 / => d2♭ . d3 2 / => d2 . d3♯ 2 / => d2♯ . e3♭ 2 / => e2♭ . e3 2 / => e2 . f3 2 / => f2 . f3♯ 2 / => f2♯ . g3♭ 2 / => g2♭ . g3 2 / => g2 . g3♯ 2 / => g2♯ . a3♭ 2 / => a2♭ . a3 2 / => a2 . a3♯ 2 / => a2♯ . b3♭ 2 / => b2♭ . b3 2 / => b2 . global_timer_init => global_timer . osc_init => osc_a_timer osc_a_volume . osc_init => osc_b_timer osc_b_volume . osc_init => osc_c_timer osc_c_volume . global_timer osc_a_timer osc_a_volume osc_b_timer osc_b_volume osc_c_timer osc_c_volume loop } fn loop => global_timer osc_a_timer osc_a_volume osc_b_timer osc_b_volume osc_c_timer osc_c_volume { | sample_rate volume beats_per_minute length_in_beats c2 c2♯ d2♭ d2 d2♯ e2♭ e2 f2 f2♯ g2♭ g2 g2♯ a2♭ a2 a2♯ b2♭ b2 c3 c3♯ d3♭ d3 d3♯ e3♭ e3 f3 f3♯ g3♭ g3 g3♯ a3♭ a3 a3♯ b3♭ b3 c4 c4♯ d4♭ d4 d4♯ e4♭ e4 f4 f4♯ g4♭ g4 g4♯ a4♭ a4 a4♯ b4♭ b4 | global_timer global_timer_to_beat => beat . global_timer global_timer_update => global_timer . osc_a_timer voice osc_a_volume * osc_b_timer voice osc_b_volume * + osc_c_timer voice osc_c_volume * + volume * push_sample osc_a_timer beat pattern_mid osc_update => osc_a_timer . osc_b_timer beat pattern_low osc_update => osc_b_timer . 0.75 => osc_a_volume . osc_c_timer beat pattern_low 2 / osc_update => osc_c_timer . 0.25 => osc_b_volume . global_timer osc_a_timer osc_a_volume osc_b_timer osc_b_volume osc_c_timer osc_c_volume loop } fn voice => osc { | return _ . | osc osc_saw return } fn pattern_low => beat { | c2 c2♯ d2♭ d2 d2♯ e2♭ e2 f2 f2♯ g2♭ g2 g2♯ a2♭ a2 a2♯ b2♭ b2 c3 c3♯ d3♭ d3 d3♯ e3♭ e3 f3 f3♯ g3♭ g3 g3♯ a3♭ a3 a3♯ b3♭ b3 c4 c4♯ d4♭ d4 d4♯ e4♭ e4 f4 f4♯ g4♭ g4 g4♯ a4♭ a4 a4♯ b4♭ b4 return _ . | beat 32 % match => beat if { | | beat 0 >= beat 12 < and } { | c3 | c3 } => beat if { | | beat 12 >= beat 16 < and } { | e3 | e3 } => beat if { | | beat 16 >= beat 28 < and } { | f3 | f3 } => beat if { | | beat 28 >= beat 32 < and } { | e3 | e3 } => _ { | | 0 } . return } fn pattern_mid => beat { | c2 c2♯ d2♭ d2 d2♯ e2♭ e2 f2 f2♯ g2♭ g2 g2♯ a2♭ a2 a2♯ b2♭ b2 c3 c3♯ d3♭ d3 d3♯ e3♭ e3 f3 f3♯ g3♭ g3 g3♯ a3♭ a3 a3♯ b3♭ b3 c4 c4♯ d4♭ d4 d4♯ e4♭ e4 f4 f4♯ g4♭ g4 g4♯ a4♭ a4 a4♯ b4♭ b4 return _ . | beat 32 % match => beat if { | | beat 0 >= beat 14 < and } { | c4 g4 e4 d4 | beat 8 % match => beat if { | | beat 0 >= beat 3 < and } { | c4 | c4 } => beat if { | | beat 3 >= beat 4 < and } { | g4 | g4 } => beat if { | | beat 4 >= beat 6 < and } { | e4 | e4 } => beat if { | | beat 6 >= beat 8 < and } { | d4 | d4 } . } => beat if { | | beat 14 >= beat 16 < and } { | d4♯ | d4♯ } => beat if { | | beat 16 >= beat 30 < and } { | d4 a4 f4 d4♯ | beat 8 % match => beat if { | | beat 0 >= beat 3 < and } { | d4 | d4 } => beat if { | | beat 3 >= beat 4 < and } { | a4 | a4 } => beat if { | | beat 4 >= beat 6 < and } { | f4 | f4 } => beat if { | | beat 6 >= beat 8 < and } { | d4♯ | d4♯ } . } => beat if { | | beat 30 >= beat 32 < and } { | e4 | e4 } => _ { | | 0 } . return } # Infrastructure fn note => distance_from_a4_in_half_steps { | return _ . | 2 distance_from_a4_in_half_steps 12 / pow 440 * return } fn global_timer_init => { | return _ . | 0 return } fn global_timer_to_beat => global_timer { | sample_rate beats_per_minute return _ . | global_timer sample_rate / beats_per_second * return } fn global_timer_update => timer { | sample_rate beats_per_minute length_in_beats return _ . | timer 1 + => timer . sample_rate beats_per_second / length_in_beats * => length_in_samples . timer length_in_samples >= match => done if { | | done 1 = } { | | exit } => _ { | timer | timer } . return } fn beats_per_second => { | beats_per_minute return _ . | beats_per_minute 60 / return } fn osc_init => { | return _ _ . | 0 => osc_timer . 1 => osc_volume . osc_timer osc_volume return } fn osc_update => osc_timer pitch { | sample_rate return _ . | pitch sample_rate / osc_timer + => osc_timer . osc_timer 1 >= match => must_wrap if { | | must_wrap 0 = } { | osc_timer | osc_timer } => must_wrap if { | | must_wrap 1 = } { | osc_timer | osc_timer 1 - } . return } fn osc_saw => osc_timer { | return _ . | osc_timer return }