diff options
Diffstat (limited to 'client/lib/midi.js')
| -rw-r--r-- | client/lib/midi.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/client/lib/midi.js b/client/lib/midi.js index f2e0295..338526a 100644 --- a/client/lib/midi.js +++ b/client/lib/midi.js @@ -54,7 +54,7 @@ export function midi_init() { /* play a single note */ -export function play_note(index, duration, channel="all", exporting=false){ +export function play_note(index, duration, channel="all", exporting=false, defer=0){ // console.log(index) const scale = scales.current() const freq = scale.index(index + Math.round(nx.offset.value), nx.octave.value) @@ -71,9 +71,12 @@ export function play_note(index, duration, channel="all", exporting=false){ if (exporting || midiDevice) { duration = duration || 60000 / Tone.Transport.bpm.value if (! exporting) { - midiDevice.playNote(note, channel, { duration }) - if (sendPitchBend) { - midiDevice.sendPitchBend(cents, channel) + if (defer) { + setTimeout(() => { + play_midi_note(note, cents, channel, duration) + }, defer) + } else { + play_midi_note(note, cents, channel, duration) } } } else { @@ -82,6 +85,13 @@ export function play_note(index, duration, channel="all", exporting=false){ return note } +export function play_midi_note(note, cents, channel, duration) { + midiDevice.playNote(note, channel, { duration }) + if (sendPitchBend) { + midiDevice.sendPitchBend(cents, channel) + } +} + /* play the next note in sequence */ export function play_sequence(i, bounds, diff, note_time, channel="all", exporting) { @@ -90,7 +100,7 @@ export function play_sequence(i, bounds, diff, note_time, channel="all", exporti if (i >= count) i = 0 const y = Math.floor(i / rows[0].length) const x = i % rows[0].length - if (!x) console.log(y) + // if (!x) console.log(y) const n = rows[y][x] i += 1 if (i >= count) i = 0 |
