Add few button handlers / improve sampler / test push with sampler
authorEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 7 May 2022 17:41:38 +0000 (20:41 +0300)
committerEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 7 May 2022 17:41:38 +0000 (20:41 +0300)
push-control.scd
sampler.scd
test.scd

index 9af48a4..0b695cb 100644 (file)
       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|
index 5809eda..d4cddfa 100644 (file)
@@ -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);
     }).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;
       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;
 };
 )
index 7fc28e6..2f6a895 100644 (file)
--- 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