summaryrefslogtreecommitdiff
path: root/client/lib
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-10-09 00:30:43 +0200
committerJules Laplace <julescarbon@gmail.com>2018-10-09 00:30:43 +0200
commit8848bc387d62e1667cdfa684f36c058d2619e6b3 (patch)
tree89c790f4bd6aa21fd12d3c943f4d5566a46bab28 /client/lib
parenta411f4822a0b2fc72308bcd4af1bc3593aabd4ad (diff)
mass shooting sonification
Diffstat (limited to 'client/lib')
-rw-r--r--client/lib/midi.js20
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