Skip to content

Instantly share code, notes, and snippets.

@mbutz
Last active November 2, 2017 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbutz/fc549569f488e93a698b to your computer and use it in GitHub Desktop.
Save mbutz/fc549569f488e93a698b to your computer and use it in GitHub Desktop.
AFX Song Sketch
# AFX Song Sketch
use_debug false
set_volume! 1
use_bpm 128 # beat = quarter note
# TODO
# Shaker
# Rework the tune synth
# Break at 19
# Break at 21 with reverb
# Ending
# Check the frog
beep = lambda do
sample :elec_tick, amp: 2, rate: 0.4, attack: 0.0, sustain: 0, release: 0.1, pan: 0, start: 0.04, finish: 1
end
# INSTRUMENTS
cbsa_of = lambda do
sample :loop_compus, amp: 5, rate: 1, pan: 0, start: 0.17, finish: 0.2
end
cbsa_on = lambda do
sample :loop_compus, amp: 3.5, rate: 0.95, pan: 0, start: 0.17, finish: 0.2
end
tick = lambda do
sample :loop_compus, amp: 8, rate: 1, pan: 0, start: 0.19, finish: 0.2
end
hiss = lambda do # this is not anymore a 'hiss'
sample :elec_plip, amp: 1, rate: 1.5, pan: -0.2, start: 0, finish: 0.6
end
bodn_fg = lambda do
use_synth :tri
use_synth_defaults amp: 0.5, cutoff: 0, attack: 0.8, sustain: 3, release: 4, pan: 0.2, depth: 20
end
bodn_bg = lambda do
use_synth :tri
use_synth_defaults amp: 0.3, attack: 3, sustain: 2, release: 3, pan: -0.2, depth: 10
end
bodn_pk = lambda do
use_synth :tri
use_synth_defaults amp: 0.4, cutoff: 0, attack: 0.3, sustain: 3, release: 5, pan: 0.2, depth: 0
end
frog = lambda do
use_synth :tb303
use_synth_defaults amp: 5, attack: 0.3, sustain: 0.4, release: 0.2, pan: rrand(-0.4, 0.1), res: 0.1
end
bnce = lambda do
use_synth :fm
use_synth_defaults amp: 10, attack: 0, sustain: 0.2, release: 0.1, pan: 0.2, depth: 0.5
# divisor = 1 => one octave higher
# depth up makes the sound more sharp and thin
end
bnce_noise = lambda do
use_synth :cnoise
use_synth_defaults amp: 0.6, attack: 0.1, sustain: 0.2, release: 1, pan: 0.2
end
flute = lambda do
use_synth :fm
use_synth_defaults amp: 1, attack: 0.3, sustain: 0.2, release: 0.2, pan: 1
end
tune = lambda do
use_synth :fm # comes in at ca. 3'25
use_synth_defaults amp: 1, attack: 0, sustain: 0.15, release: 0.15, pan: -0.3, depth: 2, divisor: 1
end
base_on = lambda do
sample :drum_bass_hard, amp: 3, rate: 0.7, pan: -0.2
end
base_of = lambda do
sample :drum_bass_hard, amp: 1.5, rate: 0.7, pan: -0.2
end
snre_on = lambda do
sample :drum_snare_hard, amp: 2, rate: 1.275, attack: 0, sustain: 1, release: 0, pan: -0.1
end
snre_of = lambda do
sample :drum_snare_hard, amp: 2, rate: 1.3, attack: 0, sustain: 1, release: 0, pan: -0.1
end
hiht_on = lambda do
sample :drum_cymbal_closed, amp: 2, rate: 1, pan: -0.5, start: 0, finish: 0.4
end
hiht_of = lambda do
sample :drum_cymbal_closed, amp: 2, rate: 1.3, pan: -0.5, start: 0, finish: 0.3
end
hiht_lo = lambda do
sample :drum_cymbal_closed, amp: 3, rate: 1, pan: -0.4, start: 0.0, finish: 0.6
end
hiht_hi = lambda do
sample :drum_cymbal_closed, amp: 3, rate: 1, pan: -0.4, start: 0.0, finish: 0.6
end
snre_hr = lambda do # comes in ca. 2'20
sample :elec_snare, amp: 0.7, rate: 0.5, pan: -0.1, start: 0, finish: 0.4
end
cong_low = lambda do
sample :drum_tom_hi_soft, amp: 2, rate: 1.05, start: 0.1
end
cong_mdm = lambda do
sample :drum_tom_hi_soft, amp: 3, rate: 1.17, start: 0.1
end
cong_hih = lambda do
sample :drum_tom_hi_soft, amp: 3, rate: 1.23, start: 0.1
end
# Helper Functions
# Return note duration based on the defined rythmic pattern
# According to number of pattern values: 4, 8, 16, 32,
# return appropriate fraction of on beat: 1, 0.5, 0.25, 0.125.
# Equivalent to common note values: quarter, eighth, sixteenth or thirty-second note
define :get_note_dur do |a|
if a.count == 4
d = 1
elsif a.count == 8
d = 0.5
elsif a.count == 16
d = 0.25
elsif a.count == 32
d = 0.125
else
puts "NOTE: No idea what rythmic pattern you mean!"
end
return d
end
# Play rhythm (i.e. samples)
define :play_rhythm_bar do |instr, instr_pattern|
d = get_note_dur instr_pattern
instr_pattern.each do |i|
if i != 0
instr.call
end
sleep d
end
end
define :play_notes do |instr, notes|
t = get_note_dur notes
notes.each do |n|
if n[0] == :to
control (play n[4], note_slide: n[1], sustain: n[2], release: n[3]), amp: 3, note: n[5]
# puts "Glissando: #{n}"
elsif n != :-
instr.call
play n
# puts "Note oder Akkord: #{n}"
end
sleep t
end
end
# rhythmic patterns (ptn)
# 1 e + e 2 e + e 3 e + e 4 e + e
beep_ptn = [1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0]
cbsa_on_ptn_a = [1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0]
cbsa_of_ptn_a = [0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1]
cbsa_on_ptn_b = [1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0]
cbsa_of_ptn_b = [0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1]
tick_ptn = [1,1,0,0,0,1,0,0,1,1,0,0,0,1,0,0]
cong_lo_ptn = [0,0,1,0,1,0,0,0,0,1,0,0,1,0,0,0]
cong_hi_ptn = [0,0,0,1,0,1,0,0,0,0,1,1,0,0,1,1]
base_on_ptn_1 = [1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0]
base_of_ptn_1 = [0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0]
base_ptn_2a = [1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0]
base_ptn_2b = [1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0]
snre_on_ptn_1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]
snre_of_ptn_1 = [0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0]
snre_ptn_2 = [0,0,0,0,1,0,0,0,0,0,0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fs4],:-,
:-,:-,:-,[:d4,:fs4],
:-,:-,[:d4,:fs4],:-,
:-,[:d4,:fs4],:-,[:d4,:fs4]]
frog_ptn = [:-,:-,:-,:-,:-,:g1,:-,:-,:-,:-,:-,:-,:-,:-,:-,:-]
flute_ptn_a = [:-,:-,:-,:-,[:to,1,0.5,0.5,:g5,:fs5],:-,[:to,1,1,1,:f5,:e5],:-]
flute_ptn_b = [:-,:-,:-,:-,[:to,1,0.5,0.5,:g4,:fs4],:-,:-,:-]
flute_ptn_v = [[:-,:-,:-,:-,:-,:-,:-,:-],
[:-,:-,:-,:-,:-,:-,:-,:-],
[:-,:-,:-,:-,:-,:-,:-,:-],
[:-,:-,:-,:-,:-,:-,:-,:-]]
flute_ptn_v = [[:-,[:to,1,0.5,0.5,:g5,:fs5],:-,:-,:-,:-,:-,:-],
[:-,:-,:-,[:to,1,0.5,0.5,:b4,:a4],:-,:-,:-,:-],
[:-,[:to,1,0.5,0.5,:e5,:fs5],:-,:-,[:to,1,0.5,0.5,:a5,:b5],:-,:-,:-],
[:-,:-,:-,:-,:-,:-,:-,[:to,1,0.5,0.5,:g4,:e4]],
[:-,:-,:-,:-,[:to,1,0.5,0.5,:g5,:fs5],:-,[:to,1,1,1,:f5,:e5],:-],
[:-,:-,:-,:-,[:to,1,0.5,0.5,:g4,:fs4],:-,:-,:-]]
tune_ptn_b1 = [:a5,:-,:-,:-,
:b5,:-,:d6,:-,
:e6,:-,:-,:-,
:-,:-,:a5,:-]
tune_ptn_b2 = [:b5,:a5,:-,:-,
:b5,:-,:d6,:-,
:-,:-,:e6,:-,
:a5,:-,:-,:-]
tune_ptn_b3 = [:g5,:-,:-,:-,
:a5,:-,:-,:-,
:b5,:-,:-,:-,
:-,:-,:-,:-]
tune_ptn_b4 = [:a5,:-,:g5,:-,
:-,:-,:-,:a5,
:-,:-,:b5,:-,
:a5,:-,:-,:-]
mod_beep = lambda do
in_thread do
4.times do
play_rhythm_bar beep, beep_ptn
end
end
end
# Song Modules
mod_shaker = lambda do
in_thread do
2.times do
play_rhythm_bar cbsa_on, cbsa_on_ptn_a
play_rhythm_bar cbsa_on, cbsa_on_ptn_b
end
end
in_thread do
2.times do
play_rhythm_bar cbsa_of, cbsa_of_ptn_a
play_rhythm_bar cbsa_of, cbsa_of_ptn_b
end
end
in_thread do
2.times do
play_rhythm_bar tick, tick_ptn
play_rhythm_bar tick, tick_ptn
end
end
end
mod_bordun_synth = lambda do
in_thread do
2.times do
with_fx :flanger, phase: 10, wave: 3 do
play_notes bodn_fg, bodn_fg_ptn
end
sleep 4
end
end
in_thread do
2.times do
with_fx :flanger, phase: 10, wave: 3 do
play_notes bodn_bg, bodn_bg_ptn
end
sleep 4
end
end
in_thread do
2.times do
with_fx :flanger, phase: 10, wave: 3 do
play_notes bodn_pk, bodn_pk_ptn
end
sleep 4
end
end
end
mod_frog = lambda do
in_thread do
with_fx :reverb, room: 0.4 do
4.times do
play_notes frog, frog_ptn
end
end
end
end
# base and snare, pattern no. 1
mod_drums_1 = lambda do
in_thread do
4.times do
play_rhythm_bar base_on, base_on_ptn_1
end
end
in_thread do
4.times do
play_rhythm_bar base_of, base_of_ptn_1
end
end
in_thread do
4.times do
play_rhythm_bar snre_on, snre_on_ptn_1
end
end
in_thread do
4.times do
play_rhythm_bar snre_of, snre_of_ptn_1
end
end
end
# base and snare, pattern no. 2
mod_drums_2 = lambda do
# FIXME: repetition should be handled more elegantly
in_thread do
play_rhythm_bar base_on, base_ptn_2a
end
in_thread do
play_rhythm_bar snre_on, snre_ptn_2
end
in_thread do
sleep 4
play_rhythm_bar base_on, base_ptn_2b
end
in_thread do
sleep 4
play_rhythm_bar snre_on, snre_ptn_2
end
in_thread do
sleep 8
play_rhythm_bar base_on, base_ptn_2b
end
in_thread do
sleep 8
play_rhythm_bar snre_on, snre_ptn_2
end
in_thread do
sleep 12
play_rhythm_bar base_on, base_ptn_2b
end
in_thread do
sleep 12
play_rhythm_bar snre_on, snre_ptn_2
end
end
mod_hiht = lambda do
in_thread do
4.times do
play_rhythm_bar hiht_on, hiht_on_ptn
end
end
in_thread do
4.times do
play_rhythm_bar hiht_of, hiht_of_ptn
end
end
in_thread do
4.times do
play_rhythm_bar hiht_lo, hiht_lo_ptn
end
end
in_thread do
4.times do
play_rhythm_bar hiht_hi, hiht_hi_ptn
end
end
end
mod_snre_hr = lambda do
# FIXME: repetition more elegantly
in_thread do
play_rhythm_bar snre_hr, snre_hr_ptn_a
end
in_thread do
play_rhythm_bar snre_hr, snre_hr_ptn_b
end
in_thread do
sleep 4
play_rhythm_bar snre_hr, snre_hr_ptn_a
end
in_thread do
sleep 4
play_rhythm_bar snre_hr, snre_hr_ptn_b
end
in_thread do
sleep 8
play_rhythm_bar snre_hr, snre_hr_ptn_a
end
in_thread do
sleep 8
play_rhythm_bar snre_hr, snre_hr_ptn_b
end
in_thread do
sleep 12
play_rhythm_bar snre_hr, snre_hr_ptn_a
end
in_thread do
sleep 12
play_rhythm_bar snre_hr, snre_hr_ptn_b
end
end
mod_congas = lambda do
in_thread do
4.times do
play_rhythm_bar cong_low, cong_low_ptn
end
end
in_thread do
4.times do
play_rhythm_bar cong_mdm, cong_mdm_ptn
end
end
in_thread do
4.times do
play_rhythm_bar cong_hih, cong_hih_ptn
end
end
end
mod_flute = lambda do
in_thread do
with_fx :reverb, room: 0.9 do
play_notes flute, flute_ptn_a
end
end
in_thread do
sleep 8
with_fx :reverb, room: 0.9 do
play_notes flute, flute_ptn_b
end
end
end
mod_flute_rand = lambda do
in_thread do
with_fx :reverb, room: 0.9 do
use_random_seed rand_i(60)
play_notes flute, choose(flute_ptn_v)
end
end
in_thread do
sleep 4
with_fx :reverb, room: 0.9 do
use_random_seed rand_i(60)
play_notes flute, choose(flute_ptn_v)
end
end
in_thread do
sleep 8
with_fx :reverb, room: 0.9 do
use_random_seed rand_i(60)
play_notes flute, choose(flute_ptn_v)
end
end
in_thread do
sleep 12
with_fx :reverb, room: 0.9 do
use_random_seed rand_i(60)
play_notes flute, choose(flute_ptn_v)
end
end
end
mod_bouncer = lambda do
in_thread do
with_fx :reverb, room: 0.9 do
play_notes bnce, bnce_ptn_b1
play_notes bnce, bnce_ptn_b2
play_notes bnce, bnce_ptn_b3
play_notes bnce, bnce_ptn_b4
end
end
end
mod_bouncer_init = lambda do
in_thread do
with_fx :reverb, room: 0.9 do
play_notes bnce_noise, bnce_ptn_b1
play_notes bnce_noise, bnce_ptn_b2
play_notes bnce_noise, bnce_ptn_b3
play_notes bnce_noise, bnce_ptn_b4
end
end
end
mod_tune = lambda do
in_thread do
play_notes tune, tune_ptn_b1
play_notes tune, tune_ptn_b2
play_notes tune, tune_ptn_b3
play_notes tune, tune_ptn_b4
end
end
# Play the tune
puts "01"
mod_shaker.call
mod_bordun_synth.call
sleep 16
puts "02"
mod_shaker.call
mod_bordun_synth.call
sleep 16
puts "03"
mod_shaker.call
mod_bordun_synth.call
mod_frog.call
sleep 16
puts "04"
mod_shaker.call
mod_bordun_synth.call
mod_frog.call
sleep 16
puts "05"
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_frog.call
sleep 16
puts "06"
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_frog.call
mod_flute.call
sleep 16
puts "07"
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_frog.call
mod_congas.call
sleep 16
puts "08"
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_frog.call
mod_flute_rand.call
sleep 16
puts "09" # frog leaves
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_flute_rand.call
mod_congas.call
sleep 16
puts "10" # congas leave
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
sleep 16
puts "11"
mod_bouncer.call
mod_bouncer_init.call
sleep 16
puts "12"
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_flute_rand.call
sleep 16
puts "13" # bordun in again
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_flute_rand.call
sleep 16
puts "14"
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_flute_rand.call
sleep 16
puts "15" # hammer snare in
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_flute_rand.call
mod_snre_hr.call
sleep 16
puts "16" # drums out, shaker in
mod_bouncer.call
mod_shaker.call
mod_bordun_synth.call
mod_flute_rand.call
sleep 16
puts "17" # drums 2 in
mod_bouncer.call
mod_drums_2.call
mod_hiht.call
mod_bordun_synth.call
mod_snre_hr.call
sleep 16
puts "18"
mod_bouncer.call
mod_drums_2.call
mod_hiht.call
mod_bordun_synth.call
mod_snre_hr.call
sleep 16
puts "19: Missing Break"
mod_drums_2.call
mod_hiht.call
mod_snre_hr.call
mod_frog.call
sleep 16
puts "Mark the Break"
sleep 2
puts "20"
mod_drums_1.call
mod_hiht.call
mod_snre_hr.call
mod_congas.call
mod_frog.call
sleep 16
puts "21: Missing blend: 1.3 to 2.2+"
mod_drums_2.call
mod_hiht.call
mod_snre_hr.call
mod_frog.call
sleep 16
puts "22"
mod_drums_1.call
mod_hiht.call
mod_flute_rand.call
mod_congas.call
mod_bordun_synth.call
mod_frog.call
sleep 16
puts "24"
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_congas.call
mod_bordun_synth.call
sleep 16
puts "25"
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
sleep 16
puts "26"
mod_tune.call
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
sleep 16
puts "27"
mod_tune.call
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_snre_hr.call
sleep 16
puts "28"
mod_tune.call
mod_bouncer.call
mod_shaker.call
mod_bordun_synth.call
mod_flute.call
sleep 16
puts "29"
mod_tune.call
mod_bouncer.call
mod_shaker.call
mod_bordun_synth.call
mod_flute.call
sleep 16
puts "30"
mod_shaker.call
mod_bordun_synth.call
sleep 16
puts "31: Stop and Reverb"
mod_bordun_synth.call
sleep 16
puts "32"
mod_tune.call
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_flute.call
sleep 16
puts "33"
mod_tune.call
mod_bouncer.call
mod_drums_1.call
mod_hiht.call
mod_bordun_synth.call
mod_flute.call
sleep 16
puts "34: Find an appropriate end ..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment