<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>
}
$('.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) {