From: Eugene Petkevich Date: Sun, 8 May 2022 08:23:25 +0000 (+0300) Subject: Add rate control and pad response to sampler X-Git-Url: https://git.zuelum.org/?a=commitdiff_plain;h=43b95e08999a2f66bf9de86570cb635c4c01f762;p=scprojects.git Add rate control and pad response to sampler --- diff --git a/push-control.scd b/push-control.scd index 0b695cb..cfd718a 100644 --- a/push-control.scd +++ b/push-control.scd @@ -136,13 +136,13 @@ }); }, 86, 0), - // Keys + // Pads MIDIFunc.noteOn({ |...args| var note, row, col; note = args[1] - 36; col = note % 8; row = (note/ 8).asInteger; - push.hcPushKeyOn(row, col, *push.ppca(*args)); + push.padDown(row, col, *push.ppca(*args)); }, (36..99), 0), @@ -151,7 +151,7 @@ note = args[1] - 36; col = note % 8; row = (note/ 8).asInteger; - push.hcPushKeyOff(row, col, *push.ppca(*args)); + push.padUp(row, col, *push.ppca(*args)); }, (36..99), 0), MIDIFunc.polytouch({ |...args| @@ -159,7 +159,7 @@ note = args[1] - 36; col = note % 8; row = (note/ 8).asInteger; - push.hcPushKeyPressure(row, col, *push.ppca(*args)); + push.padPressure(row, col, *push.ppca(*args)); }, (36..99), 0), ]; @@ -222,7 +222,7 @@ push.pushOut.latency_(0); if (push.pushOut==nil, {"Cannot control push LEDs!"}); - push.hcPushPadLed = {|zi, row, col, light=3, color=0, whiten=false, mode=0| + push.padLight = {|zi, row, col, light=3, color=0, whiten=false, mode=0| if ((col < 0) || (col > 7) || (row < 0) || (row > 7), {}, { zi.pushOut.noteOn(mode, 36+(row*8)+col, zi.pppc(color, light, whiten)); }); diff --git a/sampler.scd b/sampler.scd index d4cddfa..a6fe1da 100644 --- a/sampler.scd +++ b/sampler.scd @@ -4,17 +4,20 @@ var sampler = Environment[ \version -> "33.7.2.3", \maxDur -> maxDur, + \synthName -> \samplerPlay, \buf -> Buffer.alloc(s, s.sampleRate * maxDur, 1), \recsynthdef -> SynthDef(\samplerRecord, { |input, buf| var sig; sig = In.ar(input, 1); RecordBuf.ar(sig, buf, doneAction: Done.freeSelf, loop: 0); }).add, - \playsynthdef -> SynthDef(\samplerPlay, { |out = 0, buf = 0, startPos = 0, duration = 0.01| - var sig, env; - sig = PlayBuf.ar(1, buf, BufRateScale.ir(buf), startPos: startPos*BufSampleRate.ir(buf), doneAction: 2); - env = Env.new([0, 1, 1, 0], [0.01, duration-0.02, 0.01]); + \playsynthdef -> SynthDef(\samplerPlay, { |out = 0, buf = 0, startPos = 0, duration = 0.01, freq=220, amp=1| + var sig, env, rate; + rate = freq / 220; + sig = PlayBuf.ar(1, buf, BufRateScale.ir(buf)*rate, startPos: startPos*BufSampleRate.ir(buf), doneAction: 2); + env = Env.new([0, 1, 1, 0], [0.01, duration/rate-0.02, 0.01]); sig = sig * EnvGen.ar(env, 1, doneAction: 2); + sig = sig * amp; Out.ar(out, sig!2); }).add, \startRec -> { |zi| @@ -41,7 +44,14 @@ buf: zi.buf, startPos: zi.startPos, duration: zi.duration, - ) + ); + }, + \makeSynthArgs -> { |zi| + [ + \buf, zi.buf, + \startPos, zi.startPos, + \duration, zi.duration, + ]; }, \shiftPos -> { |zi, delta| var endPos = zi.startPos + zi.duration; diff --git a/test.scd b/test.scd index 2f6a895..d4a472b 100644 --- a/test.scd +++ b/test.scd @@ -3,7 +3,10 @@ ~se = ~samplerFactory.value; ) +(\freq: 220).play; + ~se.makeSynthEvent +~se.makeSynthArgs ( ~push.recDown = { |zi| @@ -21,6 +24,16 @@ ~se.startPos.postln; ~se.duration.postln; }; +~push.padDown = { |zi, row, col, vel| + var note, amp; + ~push.padLight(row, col, 2, 1, false, 1); + note = Scale.major.degreeToFreq(col, 0.midicps, row+1); + amp = vel.linlin(1, 127, 0.01, 0.4); + Synth(~se.synthName, ~se.makeSynthArgs++[\freq, note]); +}; +~push.padUp = { |zi, row, col, vel| + ~push.padLight(row, col, 0, 0, false, 1); +}; ) //=============================================================================