Here's the tune that this code generates: https://bsky.app/profile/hannobraun.com/post/3mqqtvehwlc2y
A Monobloc program, using Monobloc Synth to create music. It's still early days for Monobloc and Synth. The music is not very sophisticated yet, and the code is too tedious and complicated for what it does.
Something went wrong. Try again.
monobloc-synth-2026-07-16.monobloc
· Created 3mo ago ·6.9 kB · 324 lines
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325fn 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 capture 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 bind global_timer osc_a_timer osc_a_volume osc_b_timer osc_b_volume osc_c_timer osc_c_volume{ 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 bind osc return _{ osc osc_saw return}fn pattern_low capture 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 bind beat return _{ beat 32 % match { => beat with { beat 0 >= beat 12 < and } { c3 } => beat with { beat 12 >= beat 16 < and } { e3 } => beat with { beat 16 >= beat 28 < and } { f3 } => beat with { beat 28 >= beat 32 < and } { e3 } => _ { 0 } } return}fn pattern_mid capture 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 bind beat return _{ beat 32 % match { => beat with { beat 0 >= beat 14 < and } { beat 8 % match { => beat with { beat 0 >= beat 3 < and } { c4 } => beat with { beat 3 >= beat 4 < and } { g4 } => beat with { beat 4 >= beat 6 < and } { e4 } => beat with { beat 6 >= beat 8 < and } { d4 } } } => beat with { beat 14 >= beat 16 < and } { d4♯ } => beat with { beat 16 >= beat 30 < and } { beat 8 % match { => beat with { beat 0 >= beat 3 < and } { d4 } => beat with { beat 3 >= beat 4 < and } { a4 } => beat with { beat 4 >= beat 6 < and } { f4 } => beat with { beat 6 >= beat 8 < and } { d4♯ } } } => beat with { beat 30 >= beat 32 < and } { e4 } => _ { 0 } } return}# Infrastructurefn note bind 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 capture sample_rate beats_per_minute bind global_timer return _{ global_timer sample_rate / beats_per_second * return}fn global_timer_update capture sample_rate beats_per_minute length_in_beats bind timer return _{ timer 1 + => timer . sample_rate beats_per_second / length_in_beats * => length_in_samples . timer length_in_samples >= match { => done with { done 1 = } { exit # We'll never reach this code, but we need it to satisfy the # compiler. It doesn't understand yet that `exit` won't return, and # it checks that all match assignments evaluate to the same number # of values. 0 } => _ { timer } } return}fn beats_per_second capture 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 capture sample_rate bind osc_timer pitch return _{ pitch sample_rate / osc_timer + => osc_timer . osc_timer 1 >= match { => must_wrap with { must_wrap 0 = } { osc_timer } => must_wrap with { must_wrap 1 = } { osc_timer 1 - } } return}fn osc_saw bind osc_timer return _{ osc_timer return}Login to leave a reply