36: 8, 38: 9, 40: 10, 42: 11, 44: 12, 46: 13, 48: 14, 50: 15
};
+/* on French/Belgian keyboards, emulate pad touches with keypresses */
+var KEYBOARD_CODES = Array('a', 'z', 'e', 'r', 't', 'u', 'i', 'o',
+ 'q', 's', 'd', 'f', 'g', 'h', 'j', 'k');
+
var midi = {
onMIDISuccess: function(midiAccess) {
});
midi.onTouchOn = function(port, data, sample_idx) {
- var sample_buffer = self.sample_buffers[sample_idx];
- var nanotouch = $('.nanotouch')[sample_idx];
- if (typeof(sample_buffer) != 'undefined') {
- if (typeof(samples[sample_idx]) != 'undefined' && samples[sample_idx].context.state == 'running') {
- self.samples[sample_idx].stop(0);
+ self.startSample(sample_idx);
+ }
+
+ $(document).keypress(function(ev) {
+ var sample_idx = KEYBOARD_CODES.indexOf(ev.key);
+ if (sample_idx != -1) {
+ self.startSample(sample_idx);
+ }
+ });
+ }
+
+ self.startSample = function(sample_idx) {
+ var sample_buffer = self.sample_buffers[sample_idx];
+ var nanotouch = $('.nanotouch')[sample_idx];
+ if (typeof(sample_buffer) != 'undefined') {
+ if (typeof(samples[sample_idx]) != 'undefined' && samples[sample_idx].context.state == 'running') {
+ self.samples[sample_idx].stop(0);
+ self.samples[sample_idx] = undefined;
+ } else {
+ var sample = self.audioCtx.createBufferSource();
+ self.samples[sample_idx] = sample;
+ sample.loop = false;
+ sample.connect(gainNode);
+ sample.buffer = sample_buffer;
+ sample.onended = function() {
+ console.log('ended');
+ $(nanotouch).removeClass('playing');
self.samples[sample_idx] = undefined;
- } else {
- var sample = self.audioCtx.createBufferSource();
- self.samples[sample_idx] = sample;
- sample.loop = false;
- sample.connect(gainNode);
- sample.buffer = sample_buffer;
- sample.onended = function() {
- console.log('ended');
- $(nanotouch).removeClass('playing');
- self.samples[sample_idx] = undefined;
- }
- $(nanotouch).addClass('playing');
- sample.start(0);
}
+ $(nanotouch).addClass('playing');
+ sample.start(0);
}
}
}