// title: mutronome (brownian motion of beats) // author: eli.rosenkim // description: // beat absolute locations rather than deltas meander randomly each cycle // code: //A metronome that mutates beat locations using something like Brownian Motion ( SynthDef.new(\block, { arg freq=1000; var sig, env; sig = Impulse.ar(0)*10; sig = SVF.ar(sig, freq, 0.9); env = EnvGen.ar(Env.perc(0.01, 1), 1, doneAction: 2); sig = sig*env; sig = sig!2; Out.ar(0, sig); }).add; ) ( SynthDef.new(\clip, { arg freq=1000, res = 0.1; var sig, env; sig = ClipNoise.ar()*0.1; sig = SVF.ar(sig, freq, res); env = EnvGen.ar(Env.perc(0.01, 0.05), 1, doneAction: 2); sig = sig*env; sig = sig!2; Out.ar(0, sig); }).add; ) x = Synth.new(\block, [\freq, 1000]); x = Synth.new(\block, [\freq, 800]); //mutating 4/4 metronome ( ~mutro = { var i = 0, deltas, randos, out, maxStep; deltas = List[0.7, 0.7, 0.7, 0.7]; //starting deltas for each beat randos = List[0, 0, 0, 0]; //random values for each beat, first bar plays straight as randos are all 0 maxStep = deltas[0]/10; loop{ out = ((deltas[i] - randos[(i-1)%(deltas.size)] + randos[i]).abs); //if the first beat is pushed back by 0.2s, the second beat is moved forward 0.2s to keep it in roughly the same position before rando is added out.yield; i = (i+1)%(deltas.size); if(i%(deltas.size) == 0, //adds random value to each term of random array on beat one of each bar after bar 1 {randos = randos.collect({arg item, i; item+(rrand(-1* maxStep, maxStep))})} //{"test".postln} ); }; }; Pbind( \instrument, \block, \freq, Pseq([1000, 800, 800, 800], inf), \dur, Prout(~mutro); ).play; ) //mutating triplets ( ~mutroblock = { var i = 0, deltas, randos, out, maxStep; deltas = List[0.8, 0.8, 0.8, 0.8]; //starting deltas for each beat randos = List[0, 0, 0, 0]; //random values for each beat, first bar plays straight as randos are all 0 maxStep = deltas[0]/40; loop{ out = ((deltas[i] - randos[(i-1)%(deltas.size)] + randos[i]).abs); //if the first beat is pushed back by 0.2s, the second beat is moved forward 0.2s to keep it in roughly the same position before rando is added out.yield; i = (i+1)%(deltas.size); if(i%(deltas.size) == 0, //adds random value to each term of random array on beat one of each bar after bar 1 {randos = randos.collect({arg item, i; item+(rrand(-1* maxStep, maxStep))})} //{"test".postln} ); }; }; ~mutroclip = { var i = 0, deltas, randos, out, maxStep; deltas = List[0.8*(1/3), 0.8*(1/3), 0.8*(1/3)]; randos = List[0, 0, 0]; maxStep = deltas[0]/40; loop{ out = ((deltas[i] - randos[(i-1)%(deltas.size)] + randos[i]).abs); out.yield; i = (i+1)%(deltas.size); if(i%(deltas.size) == 0, {randos = randos.collect({arg item, i; item+(rrand(-1* maxStep, maxStep))})} ); }; }; Pbind( \instrument, \block, \freq, Pseq([1000, 800, 800, 800], inf), \dur, Prout(~mutroblock); ).play; Pbind( \instrument, \clip, \freq, Pseq([10000, 9000, 8000], inf), \res, Pseq([0.1, 0.2, 0.3, 0.1], inf), \dur, Prout(~mutroclip); ).play; )