Skip to content

Instantly share code, notes, and snippets.

@amonks
Last active April 16, 2016 22:05
Show Gist options
  • Save amonks/f7803ec02aee0b47779cbf2f2519902d to your computer and use it in GitHub Desktop.
Save amonks/f7803ec02aee0b47779cbf2f2519902d to your computer and use it in GitHub Desktop.
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# TRACK
#
# config for this particular track
#
# # # # # # # # # # # # # # # # # # # # # # # # # # #
bpm = 20 # this does change the bpm when reloading code
beat = 0 # this does not reset the beat to 0 when reloading code
progression = :major_fourths
# global master volume
master = 1
# use this map as a mixer
mixer = {
chords: 0.6,
bass: 1,
cym: 0.5,
snare: 0.6,
splash: 0.3,
fast_chords: 0.8,
}
define :circle do |step, circle = :major_fifths, shift = 0|
puts "circle: #{circle}, step: #{step}"
circles = {minor_fifths: ring(:a, :e, :b,
:fs, :cs, :gs,
:eb, :bb, :f,
:c, :g, :d),
major_fifths: ring(:c, :g, :d,
:a, :e, :b,
:fs, :cs, :ab,
:eb, :bb, :f)}
circles[:minor_fourths] = circles[:minor_fifths].reverse
circles[:major_fourths] = circles[:major_fifths].reverse
circles[circle][beat + shift]
end
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# HELPERS
#
# library of helper functions
#
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# use instead of live_loop
# automatically sets the proper bpm
# automatically mixes using the map above
define :l do |name, &b|
live_loop name do
use_bpm bpm
with_amplitude mixer[name] do
b.call
end
end
end
l :metro do
sleep 1
beat = tick
puts "beat #{beat}"
end
# 1 => (0.8 .. 1.2)
define :vary do |n, variance = 0.3|
n * (1 + (rand (variance * 2)) - variance)
end
# fixed-order arpeggiator:
# call like chord, but with an additional
# first argument for sleep time
# eg (arp 1, :c, :major)
define :arp do |beats, *a|
(chord *a).map {|n| play n ; (sleep beats)}
end
# random arpeggiator:
# call like chord, but with an additional
# first argument for sleep time
# eg (arp 1, :c, :major)
define :rarp do |beats, *a|
play (chord *a).choose
sleep beats
end
# concatenate chords
define :stack do |*chords|
out = []
chords.each {|c| out += (chord c)}
ring *out
end
# shorthand amplitude function
# scales (input || 1) by master volume
# example:
# with_amplitude 0.8 do
# sample :whatever
# end
define :with_amplitude do |v_, &b|
with_fx(:level, amp: (vary ((v_ || 1) * master), 0.05)) {b.call}
end
define :sub do |length|
(beat.to_f / length.to_f).floor
end
define :amp do |name, multiplier = 1|
[amp: (vary mixer[name]) * multiplier * master]
end
define :adsr do |a = 0, d = 0, s = 1, r = 0|
[attack: a, decay: d, sustain: s, release: r]
end
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# PARTS
#
# define the loops here
#
# # # # # # # # # # # # # # # # # # # # # # # # # # #
l :change_bpm do
bpm += 0.5
sleep 1
end
# use the same chord everywhere cuz lol music theory
ch = :minor7 # when you code-reload, this *does* reset
# until the end of the 8-beat phrase
# and then returns to the normal progression
#
# so, you should probably set this to the
# first section below
l :change_chord do
chords = ring(:minor7, :sus2,
:minor7, :sus4,
:minor7, :sus2,
:minor, :major)
# rotate through the sections every 8 beats
ch = chords[tick]
puts "chord is now #{ch}"
sleep 1
end
# let's rotate through circles too why not
l :change_circle do
sections = ring(:minor_fifths, :minor_fourths)
progression = sections.tick
sleep 4
end
l :cym do
amps = ring(1, 0.6)
sleep 0.2
sample :drum_cymbal_pedal, *(amp :cym, amps.tick)
sleep 0.3
end
l :splash do
sleep 0.3
sample :drum_splash_hard, *(amp :splash), *(adsr 0.2)
sleep 0.7
end
l :snare do
d = rand > 0.9 ? true : false
sleep d ? 1 : 0.9
sample :drum_snare_soft, *(amp :snare)
sleep d ? 0 : 0.1
end
l :bass do
with_synth :tri do
with_octave (-3) do
play (circle (sub 2), progression), *(adsr 0.1)
sleep 0.2
end
with_octave (-2) do
play (circle (sub 2), progression), *(adsr 0.1)
sleep 0.8
end
end
end
l :fast_chords do
sleep 6.25
n = (circle (sub 2), progression)
with_synth :piano do
for i in (1..10)
play (chord n, ch), amp: 0.1 * i
sleep 0.05
end
end
sleep 0.25
# duration = 4
# 0.5 + 0.25 + 4.25
end
l :chords do
with_synth :beep do
octaves = ring(0, -1)
# change the octave every six beats
with_octave octaves[sub 6] do
n = (circle (sub 2), progression)
play (chord n, ch), *(adsr 0.1, 0.2, 0.5, 0.2)
sleep 0.333
play (chord n, ch, invert: (rand_i 8) - 6)
sleep 0.667
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment