Add pedal adapter
authorEugene Petkevich <nasedil.genio.code@gmail.com>
Wed, 1 Jun 2022 15:38:36 +0000 (18:38 +0300)
committerEugene Petkevich <nasedil.genio.code@gmail.com>
Wed, 1 Jun 2022 15:38:36 +0000 (18:38 +0300)
extensions/classes/midipedals.sc [new file with mode: 0644]

diff --git a/extensions/classes/midipedals.sc b/extensions/classes/midipedals.sc
new file mode 100644 (file)
index 0000000..8c39e19
--- /dev/null
@@ -0,0 +1,37 @@
+MidiPedals : MidiHandler {
+  var <>sustain;
+  var <>express;
+
+  *new {|name='Pedals', midiNames=#["ReMOTE SL", "ReMOTE SL MIDI 1", "ReMOTE SL MIDI 1"], reveal=true|
+    ^super.newCopyArgs(name, midiNames, reveal).midiInit.controlInit;
+  }
+
+  controlInit {
+    // Sustain pedal
+    MIDIdef.cc((\sustain++name).asSymbol, {|...args|
+      sustain.value((args[0]!=0), *args);
+    }, 65, srcID: idin);
+    // Expression pedal
+    MIDIdef.cc((\expression++name).asSymbol, {|...args|
+      express.value(args[0].linlin(0, 118, 0, 1), *args);
+    }, 64, srcID: idin);
+
+    // initialize handlers with revealing code
+    [
+      \sustain, \express
+    ].do{|handlerName|
+      this.perform((handlerName++\_).asSymbol, {|...args|
+        this.noCallback(handlerName, *args);
+      });
+    };
+    "Нычосё и Щюҙуԉы готов к использованию 😊".postln;
+  }
+
+}
+
+// test
+/*
+
+~p = MidiPedals();
+
+*/
\ No newline at end of file