Fix led control / add starter animation
authorEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 21 May 2022 17:00:05 +0000 (20:00 +0300)
committerEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 21 May 2022 17:00:05 +0000 (20:00 +0300)
extensions/classes/midimix.sc
Хэзифу/mix101-control.scd
Хэзифу/push-control.scd

index 23fdb6d..c92316b 100644 (file)
@@ -1,8 +1,8 @@
 MidiMix {
-  const <version = "0.1";
-  const <name = \Mix101;
   classvar ledValues;
-  classvar instance = nil;
+  const <version = "0.1";
+  var <name;
+  var <channel = 5;
   var <midiout, <idin;
   var <>caro;
   var <>joro, <>viro, <>wipu, <>wire;
@@ -10,19 +10,19 @@ MidiMix {
   var <>sewo, <>luwo, <>fewo, <>viwo;
   var <>sypu, <>syre;
 
-  *new {
-   if (instance == nil) {
-      ledValues = IdentityDictionary[
-        \on ->  127,
-        \light -> 127,
-        true -> 127,
-        \off -> 0,
-        \dark -> 0,
-        false -> 0
-      ];
-      instance = super.new.prInit;
-    };
-    ^instance
+  *initClass {
+    ledValues = IdentityDictionary[
+      \on ->  127,
+      \light -> 127,
+      true -> 127,
+      \off -> 0,
+      \dark -> 0,
+      false -> 0
+    ];
+  }
+
+  *new {|name=\Mix101|
+    ^super.newCopyArgs(name).prInit;
   }
 
   prInit {
@@ -38,6 +38,7 @@ MidiMix {
     // MIDI out channel selector (back of the device)
     // velocity is the channel
     MIDIdef.noteOn(\caro+name, {|...args|
+      channel = args[0];
       caro.value(*args);
     }, 14, srcID: idin);
 
@@ -92,15 +93,32 @@ MidiMix {
     MIDIdef.noteOn(\viwo+name, {|...args|
       viwo.value(*args);
     }, 20, srcID: idin);
+
+    // Starter message and animation
+    this.animate;
+    "Шаҫиху готов к использованию 😊".postln;
   }
 
   // == LED control
   // pfl a
   leda {|value=true|
     value = ledValues[value] ? value;
-    (0..15).do {|i|
-      [i, value].postln;
-      midiout.noteOn(i, 1, value);
-    };
+    midiout.noteOn(channel, 1, value);
   }
+
+  animate {|stretch=1|
+    {
+      ((1..4)++(7..9)++(17..20)).do {|i|
+        midiout.noteOn(channel, i, 127);
+        (0.1*stretch).wait;
+      };
+      stretch.wait;
+      ((1..4)++(7..9)++(17..20)).do {|i|
+        midiout.noteOn(channel, i, 0);
+        (0.1*stretch)
+      };
+      midiout.noteOn(channel, 17, 127);
+    }.fork();
+  }
+
 }
\ No newline at end of file
index 40c8a9e..a41d1cb 100644 (file)
@@ -23,12 +23,22 @@ MIDIdef.sysex(\testsysex, {|...args|
 )
 
 ~mix = MidiMix();
-~mix.leda(127);
-~mout = MIDIOut.newByName("Mix-101", "Mix-101").latency_(0);
-~mout.noteOn(5, 1, 127);
+~mix.ledb(\off);
+~mout = MIDIOut.newByName("Mix-101", "Mix-101 MIDI 1").latency_(0);
+~mix.
+~mout.noteOn(5, 20, 127);
+
+(
+(0..15).do {|i|
+  [i].postln;
+  ~mout.noteOn(i, 2, 0);
+};
+)
 
 (
 ~mix.joro = {|...args|
   args.postln;
 };
-)
\ No newline at end of file
+)
+
+~mix = MidiMix()
\ No newline at end of file
index fdc2437..1cbe5f7 100644 (file)
   };
 
   // Starter message and animation
-
   {
     (0..127).do({|i|
       ~push.pushOut.noteOn(0, i, 1);