]> git.0d.be Git - nanofun.git/commitdiff
allow selection of multiple files
authorFrédéric Péters <fpeters@0d.be>
Wed, 22 Feb 2017 11:01:22 +0000 (12:01 +0100)
committerFrédéric Péters <fpeters@0d.be>
Sat, 1 Apr 2017 10:37:18 +0000 (12:37 +0200)
index.html
nanofun.js

index d4cd50f237f4d25069799b2fa771c1ed20e32967..55897f262212d974f213db2b9403dc8fbd51ad1b 100644 (file)
@@ -14,7 +14,7 @@
    <div class="nanotouch" data-touch="0">
      <span class="name"></span>
      <span class="duration"></span>
-     <input type="file" accept="audio/*">
+     <input type="file" accept="audio/*" multiple>
      <input class="touch-gain" type="range" min="0" max="127" value="127">
    </div>
   </div>
index 2a2a5dfbe736ec05559d9f91dde2a085aaca70ce..a1c14b16beaf4ac1ad4efff1965e7c24834603cf 100644 (file)
@@ -324,21 +324,27 @@ var nanofun = function() {
     }
 
     $('.nanotouch input[type=file]').on('change', function(ev) {
-      var nanotouch = $(this).parent();
-      var sample_idx = $nanopad.children().index(nanotouch);
-      var reader = new FileReader();
-      reader.onload = function(e) {
-        self.audioCtx.decodeAudioData(this.result, function(buffer) {
-          sample_buffers[sample_idx] = buffer;
-          $(nanotouch).find('span.duration').text(parseInt(buffer.duration) + 's');
-          $(nanotouch).removeClass('error').addClass('loaded');
-        }, function(e) {
-          $(nanotouch).find('span').text('');
-          $(nanotouch).removeClass('loaded').addClass('error');
-        });
+      var sample_idx = parseInt($(this).parent().data('touch'));
+      for (var i=0; i<this.files.length; i++) {
+        var reader = new FileReader();
+        var nanotouch = $('.nanotouch')[sample_idx + i];
+        reader.onload = function(e) {
+          var $nanotouch = $(this.nanotouch);
+          var sample_idx = this.sample_idx;
+          self.audioCtx.decodeAudioData(this.result, function(buffer) {
+            sample_buffers[sample_idx] = buffer;
+            $nanotouch.find('span.duration').text(parseInt(buffer.duration) + 's');
+            $nanotouch.removeClass('error').addClass('loaded');
+          }, function(e) {
+            $nanotouch.find('span').text('');
+            $nanotouch.removeClass('loaded').addClass('error');
+          });
+        }
+        reader.nanotouch = nanotouch;
+        reader.sample_idx = sample_idx + i;
+        reader.readAsArrayBuffer(this.files[i]);
+        $(nanotouch).find('span.name').text(this.files[i].name);
       }
-      reader.readAsArrayBuffer(this.files[0]);
-      $(nanotouch).find('span.name').text(this.files[0].name);
     });
 
     midi.onTouchOn = function(port, data, sample_idx) {