From 6060dcbac2f8cff74de251641d30933ba2c127ad Mon Sep 17 00:00:00 2001 From: Eugene Petkevich Date: Sat, 7 May 2022 20:41:38 +0300 Subject: [PATCH] Add few button handlers / improve sampler / test push with sampler --- push-control.scd | 16 +++++++++++++++- sampler.scd | 22 +++++++++++++++++++--- test.scd | 31 ++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/push-control.scd b/push-control.scd index 9af48a4..0b695cb 100644 --- a/push-control.scd +++ b/push-control.scd @@ -119,8 +119,22 @@ push.hcPushTouchN[args[1]].value(false, *args); }, (0..8), 0), + // Left buttons - //... not ready yet + MIDIFunc.cc({ |...args| + if (args[0] == 127, { + push.playDown(*args); + }, { + push.playUp(*args); + }); + }, 85, 0), + MIDIFunc.cc({ |...args| + if (args[0] == 127, { + push.recDown(*args); + }, { + push.recUp(*args); + }); + }, 86, 0), // Keys MIDIFunc.noteOn({ |...args| diff --git a/sampler.scd b/sampler.scd index 5809eda..d4cddfa 100644 --- a/sampler.scd +++ b/sampler.scd @@ -1,8 +1,10 @@ ( ~samplerFactory = { + var maxDur = 10.0; var sampler = Environment[ \version -> "33.7.2.3", - \buf -> Buffer.alloc(s, s.sampleRate * 10.0, 1), + \maxDur -> maxDur, + \buf -> Buffer.alloc(s, s.sampleRate * maxDur, 1), \recsynthdef -> SynthDef(\samplerRecord, { |input, buf| var sig; sig = In.ar(input, 1); @@ -10,12 +12,13 @@ }).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, doneAction: 2); + 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]); sig = sig * EnvGen.ar(env, 1, doneAction: 2); Out.ar(out, sig!2); }).add, \startRec -> { |zi| + zi.startPos = 0.0; zi.recSynth = Synth(\samplerRecord, [\input, s.inputBus, \buf, zi.buf], addAction: \addToTail); zi.endPos = s.sampleRate * 10; zi.startTime = thisThread.seconds; @@ -31,10 +34,23 @@ playSynth = Synth(\samplerPlay, [\out, 0, \buf, zi.buf, \startPos, zi.startPos, \duration, zi.duration], addAction: \addToHead); + }, + \makeSynthEvent -> { |zi| + ( + instrument: \samplerPlay, + buf: zi.buf, + startPos: zi.startPos, + duration: zi.duration, + ) + }, + \shiftPos -> { |zi, delta| + var endPos = zi.startPos + zi.duration; + zi.startPos = (zi.startPos + delta).clip(0, endPos); + zi.duration = endPos - zi.startPos; } ]; - sampler.know = true; + sampler; }; ) diff --git a/test.scd b/test.scd index 7fc28e6..2f6a895 100644 --- a/test.scd +++ b/test.scd @@ -1,3 +1,32 @@ +( +~push = ~pushFactory.value; +~se = ~samplerFactory.value; +) + +~se.makeSynthEvent + +( +~push.recDown = { |zi| + ~se.startRec(); +}; +~push.recUp = { |zi| + ~se.stopRec(); +}; +~push.playDown = { |zi| + ~se.playSample(); +}; +~push.hcPushTurnL = { |zi, delta| + var mul = 0.01; + ~se.shiftPos(delta * mul); + ~se.startPos.postln; + ~se.duration.postln; +}; +) + +//============================================================================= + +// sampler test + ~se = ~samplerFactory.value; ~se.startRec(); @@ -124,7 +153,7 @@ MIDIdef.freeAll; }.fork(); ) -~push.pushOut +~push.pushOut.sysex(Int8Array[0xF0, 0x00, 0x21, 0x1D, 0x01, 0x01, 0x08, 0x00, 0x00, 0xF7]); m = MIDIClockOut("Ableton Push", "Ableton Push MIDI 2"); m.port -- 2.17.1