]> git.0d.be Git - nanofun.git/blobdiff - nanofun.js
use nanokontrol solo buttons for looping samples
[nanofun.git] / nanofun.js
index 9244d0b11f54d4fb251016acf81df049ffb58a59..b3b58ac9faf9edbe385d55aa6a8af555d56f8412 100644 (file)
@@ -372,6 +372,19 @@ var nanofun = function() {
 
     midi.onControlChange = function(port, data, control, value) {
       if (control > 7 && control < 16) return; /* range between sliders and pots */
+      if (control >= 32 && control < 40) { /* "S" buttons */
+          var nanotouch = $('.nanotouch')[control-32];
+          if (value == 127) {
+            var checked = $(nanotouch).find('.loop input').prop('checked');
+            if (checked) {
+              $(nanotouch).find('.loop input').prop('checked', false);
+              device("nanoKONTROL2 MIDI 1").cc(control, 0);
+            } else {
+              $(nanotouch).find('.loop input').prop('checked', true);
+              device("nanoKONTROL2 MIDI 1").cc(control, 127);
+            }
+          }
+      }
       if (control > 23) return; /* after pots */
       if (control < 8) {
         control += 8; /* sliders, control bottom pads (8-15) */
@@ -443,7 +456,7 @@ var nanofun = function() {
         var sample = self.audioCtx.createBufferSource();
         var gainNode = self.touchGainNodes[sample_idx];
         self.samples[sample_idx] = sample;
-        sample.loop = false;
+        sample.loop = ($(nanotouch).find('.loop input:checked').length == 1);
         sample.connect(gainNode);
         sample.buffer = sample_buffer;
         sample.onended = function() {