Add pedal support / start sampler with pedal / add pitch guide to sampler
authorEugene Petkevich <nasedil.genio.code@gmail.com>
Thu, 12 May 2022 19:43:41 +0000 (22:43 +0300)
committerEugene Petkevich <nasedil.genio.code@gmail.com>
Thu, 12 May 2022 19:43:41 +0000 (22:43 +0300)
pedal-control.scd [new file with mode: 0644]
sampler.scd
test.scd

diff --git a/pedal-control.scd b/pedal-control.scd
new file mode 100644 (file)
index 0000000..1a868f0
--- /dev/null
@@ -0,0 +1,76 @@
+// MIDI pedals handler
+// by Eugene Zuelum
+
+(
+~pedalFactory = {
+  var pedal = Environment[
+    \version -> "33.7.3.4"
+  ];
+
+  pedal.know = true;
+
+  // Sustain pedal on/off
+  MIDIdef.cc(\midiPedalSustain, { |...args|
+    if (args[0] != 0, {
+      pedal.suDown(*args);
+    }, {
+      pedal.suUp(*args);
+    });
+  },
+  65, 3);
+  // M-Audio Exp-M pedal (values range from 0 to 118 only)
+  MIDIdef.cc(\midiPedalExpression, { |...args|
+    var normed;
+    // m-audio
+    normed = args[0].linlin(0, 118, 0, 1);
+    pedal.xePres(normed, *args);
+  },
+  64, 3);
+
+  pedal.freeDefs = { |zi|
+    MIDIdef(\midiPedalSustain).free;
+    MIDIdef(\midiPedalExpression).free;
+  };
+
+  "Нычосё и Щюҙуԉы готовы к использованию 😊".postln;
+
+  pedal;
+};
+)
+
+//============================================================================= Testing
+
+// Test incoming MIDI messages
+/*
+(
+MIDIdef.cc(\testcc, {|...args|
+(["cc"] ++ args).postln;
+});
+MIDIdef.noteOn(\testnoteon, {|...args|
+(["note on"] ++ args).postln;
+});
+MIDIdef.noteOff(\testnoteoff, {|...args|
+(["note off"] ++ args).postln;
+});
+MIDIdef.touch(\testtouch, {|...args|
+(["touch"] ++ args).postln;
+});
+MIDIdef.polytouch(\testpolytouch, {|...args|
+(["polytouch"] ++ args).postln;
+});
+MIDIdef.bend(\testbend, {|...args|
+(["bend"] ++ args).postln;
+});
+MIDIdef.sysex(\testsysex, {|...args|
+(["sysex"] ++ args).postln;
+});
+)
+*/
+
+// Test library
+/*
+~pe = ~pedalFactory.value;
+~pe.suUp = {"up".postln};
+~pe.suDown = {"down".postln};
+~pe.xePres = {|zi, val| val.postln};
+*/
index ae5b7d2..c341a08 100644 (file)
       sig = sig * amp;
       Out.ar(out, sig!2);
     }).add,
-    \startRec -> { |zi|
+    \startRec -> { |zi, pleiPich=false|
       "startRec called".postln;
       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;
+      zi.pleiPich = pleiPich;
+      if (pleiPich, {
+        zi.pichSint = Synth(\default, [freq: 220]);
+      });
     },
     \startPos -> 0,
     \duration -> 0,
@@ -36,6 +40,9 @@
       "stopRec called".postln;
       zi.duration = thisThread.seconds - zi.startTime;
       zi.recSynth.free;
+      if (zi.pleiPich, {
+        zi.pichSint.set(\gate, 0);
+      });
     },
     \playSample -> { |zi|
       var playSynth;
@@ -70,6 +77,8 @@
   ];
   sampler.know = true;
 
+  "Сэмплер готов к использованию 😊".postln;
+
   sampler;
 };
 )
index 3ed9a42..3a7353c 100644 (file)
--- a/test.scd
+++ b/test.scd
@@ -1,26 +1,19 @@
 (
 ~push = ~pushFactory.value;
 ~se = ~samplerFactory.value;
+~pe = ~pedalFactory.value;
 )
 
 (\freq: 220).play;
 
 ~se.makeSynthEvent
 ~se.makeSynthArgs
-~recording = false;
-
 (
-~push.recDown = { |zi|
-  if (~recording, {
-    ~se.stopRec();
-    ~recording = false;
-  }, {
-    ~se.startRec();
-    ~recording = true;
-  });
+~pe.suDown = { |zi|
+  ~se.startRec(true);
 };
-~push.recUp = { |zi|
-  //~se.stopRec();
+~pe.suUp = { |zi|
+  ~se.stopRec();
 };
 ~push.playDown = { |zi|
   ~se.playSample();