]> git.0d.be Git - nanofun.git/commitdiff
add a gain controller, mapped to fader 7 of the nanoKontrol
authorFrédéric Péters <fpeters@0d.be>
Sun, 19 Feb 2017 20:10:54 +0000 (21:10 +0100)
committerFrédéric Péters <fpeters@0d.be>
Sun, 19 Feb 2017 20:10:54 +0000 (21:10 +0100)
index.html
nanofun.js

index dfbdbf3a8f75a2fe6ae457d914cd0c10a0c3dd74..a48ff028e29ea83cda50b0494e3de809dbf045fe 100644 (file)
@@ -28,6 +28,7 @@
   <div id="msg"></div>
   <div id="midiinputs"></div>
   <div id="midioutputs"></div>
+  <form><input id="gain" type="range" min="0" max="127" value="127"></form>
   <div id="gitclone">Source code at <a href="https://git.0d.be/?p=nanofun.git">https://git.0d.be/?p=nanofun.git</a></div>
  </body>
 </html>
index 78d250e80accad437cbd58e11f4c073a9a83d156..5794cbe41e64dd28a3e1e16ee6a2083c6f338966 100644 (file)
@@ -170,15 +170,20 @@ onPortStateChange: function(event) {
 onMIDIMessage: function(message) {
     var port = message.target;
     var data = message.data;
+    console.log(message);
     if (data[0] == 144) { /* touch on */
       var sample_idx = NANOPAD_TOUCHS.indexOf(data[1]);
       if (sample_idx != -1) {
         this.onTouchOn(port, data, sample_idx);
       }
     }
+    if (data[0] == 176) { /* control change */
+      this.onControlChange(port, data, data[1], data[2]);
+    }
 },
 
-onTouchOn: function(port, data, sample_idx) {}
+onTouchOn: function(port, data, sample_idx) {},
+onControlChange: function(port, data, number, value) {}
 
 };
 
@@ -329,12 +334,23 @@ var nanofun = function() {
       self.startSample(sample_idx);
     }
 
+    midi.onControlChange = function(port, data, control, value) {
+      if (control == 7) {
+        $('#gain').val(value).trigger('change');
+      }
+    }
+
     $(document).keypress(function(ev) {
       var sample_idx = KEYBOARD_CODES.indexOf(ev.key);
       if (sample_idx != -1) {
         self.startSample(sample_idx);
       }
     });
+
+    $('#gain').on('change', function() {
+      var fraction = parseInt(this.value) / parseInt(127);
+      self.gainNode.gain.value = fraction * fraction;
+    });
   }
 
   self.startSample = function(sample_idx) {