Created
September 24, 2013 09:27
-
-
Save novadeviator/6682420 to your computer and use it in GitHub Desktop.
series of loop recorders and players. one is working, but how iterate to get 10 of them.
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
/************************************************************************************************/ | |
// init 10 buffers from 0-9 | |
(0..9).collect({|n| Buffer.alloc(s, s.sampleRate * 10, 1, bufnum:n)}); | |
( // buffer recorder Synth definition | |
SynthDef( "BufferRecorder", { | bufnum = 0 | | |
var input; | |
input = SoundIn.ar(0); | |
RecordBuf.ar(input, bufnum, doneAction: 2, loop: 0); | |
}).add; | |
) | |
( // LoopPlayer Synth definition | |
SynthDef( "LoopPlayer", { | |
arg amp=0, rate=1, bufnum=0; | |
var out, imp, delimp, outlevel; | |
out = BufRd.ar( | |
numChannels: 1, | |
bufnum: bufnum, | |
phase: Phasor.ar( trig:1, rate: rate, start:0, end:BufFrames.kr(bufnum), resetPos:0 ) | |
) * amp; | |
out = FreeVerb.ar( | |
in:out, | |
mix:LFNoise1.kr(0.2, 0.25, 0.5), | |
// mix:0.6, | |
room:0.9, | |
damp:0.3 ); | |
imp = Impulse.kr(10); | |
delimp = Delay1.kr(imp); | |
outlevel = '/outputlevel0'++bufnum.asSymbol; | |
SendReply.kr(imp, outlevel, [Amplitude.kr(out), K2A.ar(Peak.ar(out, delimp).lag(0, 3))]); | |
//outlevel.postln; | |
Out.ar( // output | |
[0,1], // stereo | |
out ); | |
}).add; | |
) | |
( | |
// meter Input levels | |
x = { var input, noise, imp, delimp, mul = 1; | |
imp = Impulse.kr(10); | |
delimp = Delay1.kr(imp); | |
input = SoundIn.ar(0) * mul; | |
// measure rms and Peak | |
SendReply.kr(imp, '/inputlevels', [Amplitude.kr(input), K2A.ar(Peak.ar(input, delimp).lag(0, 3))]); | |
input * 0; | |
}.play; | |
) | |
/*********************************************************************************************/ | |
( // GUI | |
~window = Window.new("Loopers").front; | |
~window.layout_( | |
VLayout( | |
HLayout( | |
~inputLevelIndicator = LevelIndicator(~window, Rect(10,10,4,100)).maxWidth_(4), | |
o = OSCFunc( {arg msg; | |
{ | |
~inputLevelIndicator.value = msg[3].ampdb.linlin(-40, 0, 0, 1); | |
~inputLevelIndicator.peakLevel = msg[4].ampdb.linlin(-40, 0, 0, 1); | |
~inputLevelIndicator.warning_(-6.dbamp); | |
~inputLevelIndicator.critical_(-3.dbamp); | |
~inputLevelIndicator.drawsPeak_(true); | |
~inputLevelIndicator.background_(Color.clear); | |
}.defer; | |
}, '/inputlevels', s.addr); | |
// (0..9).do({|n| | |
VLayout( | |
// rec button | |
Button(~window, Rect()) | |
.states_([["rec", Color.white, Color.grey(0.2)],["rec", Color.black, Color.red]]) | |
.action_({ arg button; | |
if( button.value == 1, { | |
~recorder++n = Synth("BufferRecorder", [\bufnum, n]); | |
AppClock.sched(10.0, { button.value = 0; nil; }); | |
}) | |
}), | |
// play button | |
Button(~window, Rect()) | |
.states_([["play", Color.white, Color.grey(0.2)],["play", Color.black, Color.green]]) | |
.action_({ arg button; | |
if(button.value == 1, { | |
~loopPlayer0 = Synth(\LoopPlayer).set(\bufnum, n, \amp, 0, \rate, 1); // if button value is 1 we start a synth | |
}, { ~loopPlayer0.free; }); // else we free the synth | |
}), | |
// reverse/backward button | |
Button(~window, Rect()) | |
.states_([["forward", Color.white, Color.grey(0.2)],["backward", Color.black, Color.grey(0.8)]]) | |
.action_({ arg button; | |
if(button.value == 1, { | |
~loopPlayer0.set(\rate, -1); | |
}, { ~loopPlayer0.set(\rate, 1); }); | |
}); | |
), // end of a VLayout | |
// volume slider | |
Slider(~window, Rect(height:30)) | |
.orientation_(\vertical) | |
.value_(0).step_(0.001) | |
.action_({ arg gain; ~loopPlayer0.set(\amp, gain.value.linexp(0,1,0.01,3,nil)-0.01 * 3); }), | |
// output level meter | |
~outputLevelIndicator = LevelIndicator(~window, Rect(10,10,4,100)).maxWidth_(4), | |
o = OSCFunc( {arg msg; | |
{ | |
~outputLevelIndicator.value = msg[3].ampdb.linlin(-40, 0, 0, 1); | |
~outputLevelIndicator.peakLevel = msg[4].ampdb.linlin(-40, 0, 0, 1); | |
}.defer; | |
}, '/outputlevel0', s.addr); | |
~outputLevelIndicator.warning_(-6.dbamp); | |
~outputLevelIndicator.critical_(-3.dbamp); | |
~outputLevelIndicator.drawsPeak_(true); | |
~outputLevelIndicator.background_(Color.clear); | |
nil, nil | |
), // end of HLayout | |
nil, nil | |
) // end of VLayout | |
) // end of ~window.layout_ | |
) // GUI ends here | |
/*********************************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment