]> git.0d.be Git - nanofun.git/blobdiff - nanofun.js
allow selection of multiple files
[nanofun.git] / nanofun.js
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) {