Created
December 28, 2015 06:11
-
-
Save kn1kn1/cae4b40e4efb1bafa631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ex-generative.rb | |
# ported from https://github.com/naokinomoto/ex_music_sandbox/blob/master/lib/piece/generative_sup.ex | |
# | |
use_bpm 55 | |
c_major_scale = scale(:C4, :major, num_octaves: 2) # :C4 = 60 | |
puts c_major_scale | |
r = 3.8 | |
x = 0.1 | |
live_loop :Logistics do | |
idx = (c_major_scale.length * x).ceil | |
# puts "idx: #{idx}" | |
m = c_major_scale[idx] | |
use_synth :fm | |
if rand_i(3) > 0 | |
play m, sustain: 1.0 * 1 / 16, amp: 1 | |
end | |
sleep 1.0 * 2 / 16 | |
x = r * x * (1 - x) | |
# puts "x: #{x}" | |
end | |
chord_chain_dict = { | |
I: [:ii, :iii, :IV, :V, :vi, :vii], | |
ii: [:V, :vii], | |
iii: [:IV, :vi], | |
IV: [:ii, :V, :vii], | |
V: [:vi, :I], | |
vi: [:ii, :IV, :V], | |
vii: [:I] | |
} | |
puts chord_chain_dict | |
deg = :I | |
live_loop :Markov do | |
d = deg.downcase | |
sc = d == deg ? :minor : :major | |
use_synth :fm | |
play chord_degree(d, :C4, sc), | |
sustain: 1.0 * 6 / 16, amp: 1 | |
sleep 1.0 * 12 / 16 | |
next_chords = chord_chain_dict[deg] | |
idx = rand_i(next_chords.length) | |
deg = next_chords[idx] | |
end | |
live_loop :Prob do | |
bd = ring(10, 0, 2, 0, 6, 0, 2, 0, 3, 0, 6, 0, 1, 0, 2, 4).tick(:bd) | |
if rand_i(10) < bd | |
sample :bd_haus, amp: 5 | |
end | |
sd = ring(0, 0, 1, 0, 1, 0, 6, 0, 6, 0, 1, 0, 1, 0, 6, 0).tick(:sd) | |
if rand_i(10) < sd | |
sample :sn_dolf | |
end | |
ch = ring(10, 2, 8, 2, 1, 2).tick(:ch) | |
if rand_i(10) < ch | |
sample :drum_cymbal_closed | |
end | |
oh = ring(0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0).tick(:oh) | |
if rand_i(10) < oh | |
sample :elec_cymbal, amp: 0.5 | |
end | |
sleep 1.0 * 1 / 16 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://soundcloud.com/kn1kn1/ex-generative