]> git.0d.be Git - nanofun.git/commitdiff
turn nanoKontrol external leds mode on (and animate leds a bit)
authorFrédéric Péters <fpeters@0d.be>
Sun, 19 Feb 2017 19:57:51 +0000 (20:57 +0100)
committerFrédéric Péters <fpeters@0d.be>
Sun, 19 Feb 2017 19:57:51 +0000 (20:57 +0100)
README
nanofun.js

diff --git a/README b/README
index 6a0f51c8e53de3eeb2d9d1d342314e9c7543a112..f9984160a2f8a847b7d3bcbf54f3c6673f6a2ff1 100644 (file)
--- a/README
+++ b/README
@@ -25,3 +25,6 @@ A copy of the jQuery JavaScript library is included, it's
   Copyright (c) 2009 John Resig
   Dual licensed under the MIT and GPL licenses.
   http://docs.jquery.com/License
   Copyright (c) 2009 John Resig
   Dual licensed under the MIT and GPL licenses.
   http://docs.jquery.com/License
+
+External led mode support is based on a sysex dump recorded by the Overtone
+project; MIT licensed; https://github.com/overtone/overtone/
index ffa07dd588dcfb3d8af7ba9cebc17138e365b4c5..78d250e80accad437cbd58e11f4c073a9a83d156 100644 (file)
@@ -51,7 +51,7 @@ initPorts: function() {
 },
 
 onMIDIAccessChange: function(e) {
 },
 
 onMIDIAccessChange: function(e) {
-    console.log(e);
+    console.log('on midi access change', e);
     //console.log(this);
     var port = e.port;
     var portContainer = $("#midi" + port.type + "s");
     //console.log(this);
     var port = e.port;
     var portContainer = $("#midi" + port.type + "s");
@@ -59,17 +59,20 @@ onMIDIAccessChange: function(e) {
         portContainer.empty();
     }
 
         portContainer.empty();
     }
 
-    if (port.type == "input") {
-        if (this.inputs[port.name] === undefined) {
-            this.registerPort(port);
-        }
+    if (port.state == "disconnected") {
+      if (port.type == "input") {
+        this.inputs[port.name] = undefined;
+      } else {
+        this.outputs[port.name] = undefined;
+      }
     } else {
     } else {
-        if (this.outputs[port.name] === undefined) {
-            this.registerPort(port);
-        }
+      if (port.type == "input") {
+        if (this.inputs[port.name] === undefined) { this.registerPort(port); }
+      } else {
+        if (this.outputs[port.name] === undefined) { this.registerPort(port); }
+      }
+      this.renderPort(port);
     }
     }
-
-    this.renderPort(port);
 },
 
 renderPort: function(port) {
 },
 
 renderPort: function(port) {
@@ -85,6 +88,72 @@ registerPort: function(port) {
         port.onmidimessage = function(m) { self.onMIDIMessage(m); };
     } else {
         this.outputs[port.name] = port;
         port.onmidimessage = function(m) { self.onMIDIMessage(m); };
     } else {
         this.outputs[port.name] = port;
+
+        if (port.name == 'nanoKONTROL2 MIDI 1') {
+          /* turn "external leds" mode on.
+           *
+           * The sysex dump has been recorded from the official Korg kontrol
+           * editor by the Overtone project, original code at:
+           * https://github.com/overtone/overtone/blob/master/src/overtone/device/midi/nanoKONTROL2.clj */
+          device("nanoKONTROL2 MIDI 1").raw([240, 126, 127, 6, 1, 247]);
+          device("nanoKONTROL2 MIDI 1").raw([240, 66, 64, 0, 1, 19, 0, 31, 18, 0, 247]);
+          device("nanoKONTROL2 MIDI 1").raw([240, 126, 127, 6, 1, 247]);
+
+          device("nanoKONTROL2 MIDI 1").raw([ 240, 66, 64, 0, 1, 19, 0, 127, 127,
+                2, 3, 5, 64, 0, 0, 0, 1, 16, 1, 0, 0, 0, 0, 127, 0, 1, 0, 16,
+                0, 0, 127, 0, 1, 0, 32, 0, 127, 0, 0, 1, 0, 48, 0, 127, 0, 0,
+                1, 0, 64, 0, 127, 0, 16, 0, 1, 0, 1, 0, 127, 0, 1, 0, 0, 17, 0,
+                127, 0, 1, 0, 0, 33, 0, 127, 0, 1, 0, 49, 0, 0, 127, 0, 1, 0,
+                65, 0, 0, 127, 0, 16, 1, 0, 2, 0, 0, 127, 0, 1, 0, 18, 0, 127,
+                0, 0, 1, 0, 34, 0, 127, 0, 0, 1, 0, 50, 0, 127, 0, 1, 0, 0, 66,
+                0, 127, 0, 16, 1, 0, 0, 3, 0, 127, 0, 1, 0, 0, 19, 0, 127, 0,
+                1, 0, 35, 0, 0, 127, 0, 1, 0, 51, 0, 0, 127, 0, 1, 0, 67, 0,
+                127, 0, 0, 16, 1, 0, 4, 0, 127, 0, 0, 1, 0, 20, 0, 127, 0, 0,
+                1, 0, 36, 0, 127, 0, 1, 0, 0, 52, 0, 127, 0, 1, 0, 0, 68, 0,
+                127, 0, 16, 1, 0, 0, 5, 0, 127, 0, 1, 0, 21, 0, 0, 127, 0, 1,
+                0, 37, 0, 0, 127, 0, 1, 0, 53, 0, 127, 0, 0, 1, 0, 69, 0, 127,
+                0, 0, 16, 1, 0, 6, 0, 127, 0, 0, 1, 0, 22, 0, 127, 0, 1, 0, 0,
+                38, 0, 127, 0, 1, 0, 0, 54, 0, 127, 0, 1, 0, 70, 0, 0, 127, 0,
+                16, 1, 0, 7, 0, 0, 127, 0, 1, 0, 23, 0, 0, 127, 0, 1, 0, 39, 0,
+                127, 0, 0, 1, 0, 55, 0, 127, 0, 0, 1, 0, 71, 0, 127, 0, 16, 0,
+                1, 0, 58, 0, 127, 0, 1, 0, 0, 59, 0, 127, 0, 1, 0, 0, 46, 0,
+                127, 0, 1, 0, 60, 0, 0, 127, 0, 1, 0, 61, 0, 0, 127, 0, 1, 0,
+                62, 0, 127, 0, 0, 1, 0, 43, 0, 127, 0, 0, 1, 0, 44, 0, 127, 0,
+                1, 0, 0, 42, 0, 127, 0, 1, 0, 0, 41, 0, 127, 0, 1, 0, 45, 0, 0,
+                127, 0, 127, 127, 127, 127, 0, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                0, 0, 0, 0, 0, 0, 0, 0, 0, 247]);
+
+          device("nanoKONTROL2 MIDI 1").raw([240, 126, 127, 6, 1, 247]);
+          device("nanoKONTROL2 MIDI 1").raw([240, 66, 64, 0, 1, 19, 0, 31, 17, 0, 247]);
+
+          function on(note) { device("nanoKONTROL2 MIDI 1").cc(note, 127); }
+          function off(note) { device("nanoKONTROL2 MIDI 1").cc(note, 0); }
+          var leds = Array(43, 44, 42, 41, 45);
+          for (var i=0; i<8; i++) {
+            leds.push(64+i);
+            leds.push(48+i);
+            leds.push(32+i);
+            i += 1;
+            leds.push(32+i);
+            leds.push(48+i);
+            leds.push(64+i);
+          }
+                console.log(leds);
+          on(leds[0]);
+          on(leds[1]);
+          on(leds[2]);
+          var led_idx = 2;
+          var interval_id = setInterval(function() {
+            if (led_idx < leds.length) {
+              on(leds[led_idx+1]);
+            }
+            off(leds[led_idx-2]);
+            if (led_idx-1 == leds.length) {
+              clearInterval(interval_id);
+            }
+            led_idx += 1;
+          }, 50);
+        }
     }
 
     port.onstatechange = function(e) { self.onPortStateChange(e); };
     }
 
     port.onstatechange = function(e) { self.onPortStateChange(e); };