Created
December 23, 2014 05:47
-
-
Save helmholtz/b5c77da0506194ac2c2f 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
s.boot; | |
( | |
// SynthDefs | |
SynthDef(\singrain, { |freq = 440, amp = 0.2, sustain = 2, pan=0, out=0| | |
var sig, env; | |
env = EnvGen.kr(Env.perc(0.02, sustain), doneAction: 2); | |
sig = SinOsc.ar(freq, 0, amp) * env; | |
Out.ar(out, Pan2.ar(sig, pan)); | |
}).add; | |
SynthDef(\singrain2, { |freq = 440, amp = 0.2, sustain = 2, pan=0, out=0, controlBus=0| | |
var sig, env; | |
env = EnvGen.kr(Env.perc(0.02, sustain), doneAction: 2); | |
sig = SinOsc.ar(freq, 0, amp) * env; | |
Out.kr(controlBus, env); //Control out | |
Out.ar(out, Pan2.ar(sig, pan)); | |
}).add; | |
SynthDef(\sawpass, { |freq = 440, amp = 0.2, sustain = 2, pan=0, out=0| | |
var dry,wet; | |
dry = Saw.ar(freq, amp) * EnvGen.kr(Env.perc(0.02, sustain), doneAction: 2); | |
wet = LPF.ar(dry, (EnvGen.kr(Env.perc(0.02, sustain))*500) + freq); | |
Out.ar(out, Pan2.ar(wet, pan)); | |
}).add; | |
) | |
( | |
// Useful Constants | |
~up = [[0,1,0],[0,0,1],[1,0,0]]; | |
~down = [[0,0,1],[1,0,0],[0,1,0]]; | |
~ones={1.dup(3)}.dup(3); | |
~maj = [1.0,1.25,1.5]; | |
~min = [1.0,1.2,1.5]; | |
~sus = [1.0,1.33333333333333333,1.5]; | |
~stuck=[[1,0,0],[0,1,0],[0,0,1]]; | |
// Markov Implementation | |
r = { |multiplier = 440, | |
nodelist = #[1.0,1.25,1.5], | |
matrix = #[ [0,1,0], | |
[0,0,1], | |
[1,0,0] ], | |
seed = 0, | |
length = 8| | |
Prout({ | |
var old_node, new_node, counter; | |
counter = 0; | |
old_node = nodelist[seed]; | |
while({counter < length},{ | |
nodelist.do({ arg item, index; | |
if (old_node == item, { new_node = nodelist.wchoose(matrix[index].normalizeSum) }) | |
}); | |
old_node = new_node; | |
counter = counter + 1; | |
(new_node*multiplier).yield; | |
}) | |
}); | |
}; | |
) | |
( | |
var base1, base2, pitchlist1, pitchlist2, controlBusArray1, controlBusArray2; | |
base1=660; | |
base2=165; | |
pitchlist1 = [1.25, 1.625, 1.5]; | |
pitchlist2 = [0.75, 1.375, 1.0]; | |
controlBusArray1 = { Bus.control(s,1) }.dup(3); | |
controlBusArray2 = { Bus.control(s,1) }.dup(3); | |
//Define Patterns | |
p = Pbind( | |
\freq, Pwrand( | |
[r.value(base1, pitchlist1, ~up+(0.05*~ones), 1, rrand(6,12)), | |
Pseq([\rest], rrand(6,12)) | |
], [0.5, 0.5], 50), | |
\dur, Pwrand([1, 0.5, 0.25, 0.0625],[0.125, 0.25, 0.5, 1].normalizeSum, inf), | |
\sustain, Pwrand([0.5, 1, 4], [0.6, 0.25, 0.15], inf) * Pkey(\dur), | |
\amp, Pwhite(0.05,0.2,inf), | |
\pan, Pwhite(-1.0,1.0,inf), | |
\controlBus, Pfunc({|ev| //Choose controlBus basd on freq | |
var out=0; | |
pitchlist1.do({|item, i| | |
if ((ev[\freq] == (item*base1)), {out = controlBusArray1[i]}) | |
}); | |
out; | |
}), | |
\instrument, \singrain2); | |
q= Pbind( | |
\freq, Pif( Pfunc({(~event[\freq] == \rest && 0.75.coin) || 0.25.coin}), | |
r.value([base2, 2*base2, 9*base2], pitchlist2, ~up+(0.05*~ones), 1, inf), \rest), | |
\dur, Pwrand([1, 0.5, 0.25, 0.0625],[0.125, 0.25, 0.5, 0.25].normalizeSum, 280), | |
\sustain, Pwrand([8,2,1,0.5, 0.25], [0.25,1,1,1,0.25], inf) * [0.5, 1, 0.3], | |
\amp, Pwhite(0.05,0.25,inf) * [1, 1, 0.02], | |
\pan, Pwhite(-1.0,1.0,inf), | |
\controlBus, Pfunc({|ev| //Choose controlBus basd on freq | |
var out=0; | |
pitchlist2.do({|item, i| | |
if ((ev[\freq].first == (item*base2)), {out = controlBusArray2[i]}) | |
}); | |
out; | |
}), | |
\timingOffset, [0, [0,0.125, 0.25].choose], | |
\instrument, \singrain2); | |
t = Pbind( | |
\freq, Pwrand([2640, 3960, 5280], [0.8, 0.1, 0.1], 120) + Pwhite(-20,20,120), | |
\delta, Prand([1.5, 0.75, Pseq([0.25,0.5]), Pseq([0.125,0.625])],inf), | |
\sustain, 0.0625, | |
\pan, Prand([-1, -0.5, 0, 0.5, 1], inf), | |
\amp, Pwhite(0.05, 0.1, inf) + (0.1 * Pfunc({(~event[\freq] == \rest).asInteger})), | |
\instrument, \sawpass); | |
x = Pbind( | |
\freq, Pif( Pfunc({(~event[\freq] != \rest)}), | |
[82.5, 165, 825], \rest), | |
\dur, Pwrand([1, 0.5],[2,1].normalizeSum, 60), | |
\sustain, Pwrand([4,2], [2,1], inf) * [0.5,1, 0.3], | |
\amp, Pwhite(0.05,0.25,inf) * [1, 1, 0.02], | |
\pan, Pwhite(-1.0,1.0,inf), | |
\timingOffset, [0, [0,0.25].choose], | |
\instrument, \singrain); | |
//Play patterns | |
p.collect({ |ev| ~event = ev }).play; | |
Ptpar([8, q, 32, t, 32.5, t, 64, x]).play; | |
// Visualization stuff | |
w=Window.new; | |
v=UserView(w, w.view.bounds.insetBy(50,50)); | |
v.resize = 5; | |
v.background_(Color.rand); | |
v.animate = true; | |
v.drawFunc={ | |
var intensity, left1, left2; | |
left1 = sin((v.frame/(16*2*3.14159))).linlin(-1,1,0,v.bounds.width-100); | |
left2 = sin((v.frame/(-32*2*3.14159))).linlin(-1,1,0,v.bounds.width-100); | |
//Draw grid lines | |
Pen.strokeColor = Color.grey(0.75); | |
Pen.width = 1; | |
8.do({|i| | |
Pen.moveTo(0@(165*(i+1)).linlin(150,1400,v.bounds.height,0)); | |
Pen.lineTo(v.bounds.width@(165*(i+1)).linlin(150,1400,v.bounds.height,0)); | |
Pen.stroke;}); | |
//Draw pattern one | |
Pen.strokeColor = Color.white; | |
pitchlist1.do({|item, i| | |
var left = [left1, left2].choose; | |
intensity = controlBusArray1[i].getSynchronous; | |
Pen.alpha=intensity*2; | |
Pen.width = 10*intensity; | |
Pen.moveTo((left+(i*20))@(item*base1).linlin(150,1400, v.bounds.height, 0)); | |
Pen.lineTo((left+(100+(10*intensity))+(i*20))@(item*base1).linlin(150,1400, v.bounds.height, 0)); | |
Pen.stroke; | |
}); | |
//Draw pattern two | |
Pen.strokeColor = Color.red; | |
pitchlist2.do({|item, i| | |
intensity = controlBusArray2[i].getSynchronous; | |
Pen.alpha=intensity; | |
Pen.width = 5*intensity; | |
Pen.moveTo((left2+(i*20))@(item*base2).linlin(150,1400, v.bounds.height, 0)); | |
Pen.lineTo((left2+(100+(10*intensity))+(i*20))@(item*base2).linlin(150,1400, v.bounds.height, 0)); | |
Pen.stroke; | |
Pen.alpha = intensity/4; | |
Pen.moveTo((left2+(i*20))@(2*item*base2).linlin(150,1400, v.bounds.height, 0)); | |
Pen.lineTo((left2+(100+(10*intensity))+(i*20))@(2*item*base2).linlin(150,1400, v.bounds.height, 0)); | |
Pen.stroke; | |
Pen.alpha = intensity/8; | |
Pen.moveTo((left2+(i*20))@(9*item*base2).linlin(150,1400, v.bounds.height, 0)); | |
Pen.lineTo((left2+(100+(10*intensity))+(i*20))@(9*item*base2).linlin(150,1400, v.bounds.height, 0)); | |
Pen.stroke; | |
}); | |
}; | |
w.front; | |
w.onClose = { controlBusArray1.free; controlBusArray2.free } | |
) | |
s.makeWindow; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment