Add common midi handler class
authorEugene Petkevich <nasedil.genio.code@gmail.com>
Tue, 31 May 2022 10:22:24 +0000 (13:22 +0300)
committerEugene Petkevich <nasedil.genio.code@gmail.com>
Tue, 31 May 2022 10:22:24 +0000 (13:22 +0300)
extensions/classes/midihandler.sc [new file with mode: 0644]
extensions/classes/midimix.sc
Хэзифу/bcr2000-control.scd
Хэзифу/mix101-control.scd
Хэзифу/test.scd

diff --git a/extensions/classes/midihandler.sc b/extensions/classes/midihandler.sc
new file mode 100644 (file)
index 0000000..817c333
--- /dev/null
@@ -0,0 +1,23 @@
+MidiHandler {
+  var <name, <midiNames;
+  var <midiout, <idin;
+  var <>reveal = false;
+
+  noCallback {|handlerName...args|
+    if (reveal) {
+      "%.%(%)".format(this.name, handlerName, args).postln;
+    };
+  }
+
+  midiInit {
+    var dest;
+    dest = MIDIClient.destinations.detect({ |item|
+      item.device == midiNames[0];
+    });
+    if (dest == nil) {
+      Error("Cannot connect to "++name).throw;
+    };
+    midiout = MIDIOut.newByName(dest.device, dest.name).latency_(0);
+    idin = MIDIClient.sources.detect{|i| i.device == midiNames[0]}.uid;
+  }
+}
\ No newline at end of file
index 5de6ad5..fbb05bd 100644 (file)
@@ -1,11 +1,7 @@
-MidiMix {
+MidiMix101 : MidiHandler {
   classvar ledValues, ledControls;
   classvar controlNotes;
-  const <version = "0.1";
-  var <name;
   var <channel = 5;
-  var <midiout, <idin;
-  var <>reveal = false;
   // channel selector
   var <>chanrot;
   // modes
@@ -62,26 +58,11 @@ MidiMix {
     ];
   }
 
-  *new {|name=\Mix101|
-    ^super.newCopyArgs(name).prInit;
+  *new {|name='DJ-Tech MIX-101', midiNames=#["Mix-101", "Mix-101 MIDI 1", "Mix-101 MIDI 1"]|
+    ^super.newCopyArgs(name, midiNames).midiInit.controlInit;
   }
 
-  noCallback {|handlerName...args|
-    if (reveal) {
-      "%.%(%)".format(this.name, handlerName, args).postln;
-    };
-  }
-
-  prInit {
-    var dest = MIDIClient.destinations.detect({ |item|
-      item.device == "Mix-101"
-    });
-    if (dest == nil) {
-      Error("Cannot connect to DJ-Tech MIX-101").throw;
-    };
-    midiout = MIDIOut.newByName(dest.device, dest.name).latency_(0);
-    idin = MIDIClient.sources.detect{|i| i.device == "Mix-101"}.uid;
-
+  controlInit {
     // MIDI out channel selector (back of the device)
     // velocity is the channel
     MIDIdef.noteOn(\chanrot++name, {|...args|
index 3aee9c4..4724e84 100644 (file)
@@ -16,7 +16,7 @@
 
   MIDIdef.cc(\bcr2000defaultTurn, { |...args|
     controler.turn(*args);
-  }, (1..110), controler.channel);
+  }, (1..110), controler.channel, 2883584);
 
   "Ԃиџуту готов к использованию 😊".postln;
 
index cc33257..8e4a7d5 100644 (file)
@@ -1,29 +1,3 @@
-(
-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;
-});
-)
-
-MKtl.find;
-
 (
 ~mix = MidiMix();
 ~se = Sampler();
@@ -128,7 +102,7 @@ SynthDef(\granular, {|out=0, amp=1, buf=0, density=10, len=0.1, rate=1, pos=0|
 )
 
 (
-~amp = 0.5;
+~amp = 1;
 ~density = 10;
 ~len = 0.1;
 ~rate = 1;
index b719154..0bffc00 100644 (file)
@@ -28,7 +28,7 @@ a = a.resamp1(500);
 ~se.plotter.specs = \bipolar.asSpec;
 
 ~se.soundView.setData(~data, 1024, samplerate: ~se.buf.sampleRate);
-~se.soundView.data
+~se.soundView.data.
 
 (\freq: 220).play;
 
@@ -59,6 +59,7 @@ a = a.resamp1(500);
 };
 ~push.padDown = { |zi, row, col, vel|
   var freq;
+  vel = vel * 5;
   ~push.padLight(row, col, 2, 1, false, 0);
   freq = Scale.major.degreeToFreq(col, 0.midicps, row+1);
   ~notes[freq.cpsmidi.asInteger] = Synth(~se.synthdefName, ~se.makeSynthArgs++[\freq, freq, \amp, vel]);
@@ -74,6 +75,7 @@ a = a.resamp1(500);
 };
 ~push.padPressure = { |zi, row, col, vel|
   var freq;
+  vel = vel * 5;
   //~push.padLight(row, col, 0, 0, false, 1);
   freq = Scale.major.degreeToFreq(col, 0.midicps, row+1);
   if (vel > ~amps[freq.cpsmidi.asInteger], {
@@ -81,7 +83,7 @@ a = a.resamp1(500);
       var maxRatio = 1.5;
       ("initial "++vel).postln;
       if ((vel/amp) > maxRatio, { vel = amp * maxRatio; });
-      ~notes[freq.cpsmidi.asInteger].set(\amp, vel);
+      ~notes[freq.cpsmidi.asInteger].set(\amp, vel*5);
       ("new "++vel).postln;
     });
   });
@@ -347,3 +349,4 @@ s.waitForBoot{
     SSampler(\reel).load([Quarks.folder ++ "/SuperSampler/Testcode/Sounds/Reel Palindruome_44.1kHz_int16.aiff"]);
 }
 )
+