Try making cross-platfrom using exception (not working)
authorEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 7 May 2022 08:22:38 +0000 (11:22 +0300)
committerEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 7 May 2022 08:22:38 +0000 (11:22 +0300)
push-control.scd
test.scd

index be0d937..f0b0a64 100644 (file)
   };
 
   //============================== LED control
-  MIDIClient.destinations.do({ |item|
-    if (item.name == "Ableton Push MIDI 2", {
-      push.pushOut = MIDIOut.newByName("Ableton Push", "Ableton Push MIDI 2").latency_(0);
-    });
-  });
+  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!"});
 
-
   push.hcPushPadLed = {|zi, row, col, light=3, color=0, whiten=false, mode=0|
     if ((col < 0) || (col > 7) || (row < 0) || (row > 7), {}, {
       zi.pushOut.noteOn(mode, 36+(row*8)+col, zi.pppc(color, light, whiten));
 /* Test incoming MIDI messages from push
 (
 MIDIdef.cc(\testcc, {|...args|
-  (["cc"] ++ args).postln;
+(["cc"] ++ args).postln;
 });
 MIDIdef.noteOn(\testnoteon, {|...args|
-  (["note on"] ++ args).postln;
+(["note on"] ++ args).postln;
 });
 MIDIdef.noteOff(\testnoteoff, {|...args|
-  (["note off"] ++ args).postln;
+(["note off"] ++ args).postln;
 });
 MIDIdef.touch(\testtouch, {|...args|
-  (["touch"] ++ args).postln;
+(["touch"] ++ args).postln;
 });
 MIDIdef.polytouch(\testpolytouch, {|...args|
-  (["polytouch"] ++ args).postln;
+(["polytouch"] ++ args).postln;
 });
 MIDIdef.bend(\testbend, {|...args|
-  (["bend"] ++ args).postln;
+(["bend"] ++ args).postln;
 });
 MIDIdef.sysex(\testsysex, {|...args|
-  (["sysex"] ++ args).postln;
+(["sysex"] ++ args).postln;
 });
 )
 */
@@ -242,12 +244,12 @@ MIDIdef.sysex(\testsysex, {|...args|
 
 (
 ~push.hcPushTurnS = { |zi, delta|
-  ~col = (~col + delta).clip(0, 127);
-  ~col.postln;
-  (0..127).do({|i|
-    ~push.pushOut.noteOn(0, i, ~col);
-    ~push.pushOut.control(0, i, ~col);
-  });
+~col = (~col + delta).clip(0, 127);
+~col.postln;
+(0..127).do({|i|
+~push.pushOut.noteOn(0, i, ~col);
+~push.pushOut.control(0, i, ~col);
+});
 };
 )
 */
@@ -256,13 +258,10 @@ MIDIdef.sysex(\testsysex, {|...args|
 (
 ~color = 1;
 8.do({|i|
-  8.do({|j|
-    ~push.pushOut.noteOn(0, 36+(i*8)+j, ~color);
-    ~color = ~color + 1;
-  });
+8.do({|j|
+~push.pushOut.noteOn(0, 36+(i*8)+j, ~color);
+~color = ~color + 1;
+});
 });
 )
 */
-
-MPush.lights.topRowColor.keys;
-MPush.lights.padColor.keys;
\ No newline at end of file
index ba7f0d0..37c0aff 100644 (file)
--- a/test.scd
+++ b/test.scd
@@ -110,7 +110,7 @@ MIDIdef.freeAll;
 };
 )
 
-~push.pushOut.midiClock
+~push.pushOut
 
 m = MIDIClockOut("Ableton Push", "Ableton Push MIDI 2");
 m.port
@@ -118,4 +118,26 @@ Tempo.bpm = 300;
 
 m.stop
 
-Tempo.default.bpm = 1;
\ No newline at end of file
+Tempo.default.bpm = 1;
+
+~pushOut = nil;
+
+(
+try {
+  ~pushOut = MIDIOut.newByName("Ableton Push", "Ableton Push MIDI 2").latency_(0);
+} {
+  ~pushOut = MIDIOut.newByName("Ableton Push", "User Port").latency_(0);
+};
+)
+
+// test exception problem
+
+(
+~factory = {
+  var ret;
+try { Exception.new().throw; ret = 1; } { ret = 2 };
+  ret;
+};
+)
+
+~test = ~factory.value;
\ No newline at end of file