From: Frédéric Péters Date: Sun, 19 Feb 2017 20:10:54 +0000 (+0100) Subject: add a gain controller, mapped to fader 7 of the nanoKontrol X-Git-Url: https://git.0d.be/?p=nanofun.git;a=commitdiff_plain;h=89eca3929ec776548db2db1546228384859321cf add a gain controller, mapped to fader 7 of the nanoKontrol --- diff --git a/index.html b/index.html index dfbdbf3..a48ff02 100644 --- a/index.html +++ b/index.html @@ -28,6 +28,7 @@
+
Source code at https://git.0d.be/?p=nanofun.git
diff --git a/nanofun.js b/nanofun.js index 78d250e..5794cbe 100644 --- a/nanofun.js +++ b/nanofun.js @@ -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) {