Change exception to if-else
authorEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 7 May 2022 08:36:25 +0000 (11:36 +0300)
committerEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 7 May 2022 08:36:25 +0000 (11:36 +0300)
push-control.scd

index f0b0a64..67d2785 100644 (file)
@@ -6,6 +6,7 @@
 
 (
 ~pushFactory = {
+  var dest;
   var push = Environment[
     \version -> "33.7.2.5",
 
   };
 
   //============================== LED control
+  dest = MIDIClient.destinations.detect({ |item|
+    var res = false;
+    if (item.device == "Ableton Push", {
+      if (item.name == "Ableton Push MIDI 2", {
+        res = true;
+      });
+      if (item.name == "User Port", {
+        res = true;
+      });
+    });
+    res;
+  });
+  push.pushOut = MIDIOut.newByName(dest.device, dest.name);
+  // The following is working by itself,
+  // but factory function assignment to global var
+  // returns nil
+  /*
   try {
     // linux
     push.pushOut = MIDIOut.newByName("Ableton Push", "Ableton Push MIDI 2");
     // mac os
     push.pushOut = MIDIOut.newByName("Ableton Push", "User Port");
   };
+  */
   push.pushOut.latency_(0);
   if (push.pushOut==nil, {"Cannot control push LEDs!"});