MIDI.js
MIDI.js copied to clipboard
How to implement web worker in MIDI.js app ?
I have below code in my app.js to play sequence of notes.
var notes = [67, 78, 67 ,67,90, 56,..,...,....];
var delay = [.........],tmpdelay=0;
var ctxtime = MIDI.getContext().currentTime;
for(var i=0; l < notes.length; i++)
{
MIDI.noteOn(channel, notes[i], velocity, ctxtime+tmpdelay);
tmpdelay = tmpdelay + delay[i]
}
How can I implement web worker for such case ?
What problem do you want to solve with the web worker? You don't play many notes so you won't have the other issue where web workers are discussed.
Sent from my android device.
-----Original Message----- From: shivrajsa [email protected] To: "mudcube/MIDI.js" [email protected] Cc: Subscribed [email protected] Sent: Mon, 04 Sep 2017 10:25 Subject: [mudcube/MIDI.js] How to implement web worker in MIDI.js app ? (#217)
I have below code in my app.js to play sequence of notes.
var notes = [67, 78, 67 ,67,90, 56,..,...,....];
var delay = [.........],tmpdelay=0;
var ctxtime = MIDI.getContext().currentTime;
for(var i=0; l < notes.length; i++)
{
MIDI.noteOn(channel, notes[i], velocity, ctxtime+tmpdelay);
tmpdelay = tmpdelay + delay[i]
}
How can I implement web worker for such case ?
-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/mudcube/MIDI.js/issues/217
My app has no restriction on playing number of notes at a time. Code I have shared is to give idea. And when there are many notes performance of web gets affected.
Currently I am exploring vkthread to implement web worker.
Rather than using a loop with increasingly longer delays for noteOn, you might want to play the first note then use a setTimeout that will play the next note, and so on until all the notes are played.
That way you will trigger only one note at a time, and have one timer, rather than creating a very large loop and relying on the delays to calculate the timing.
@gleitz Thank you very much, I will try to implement it, I may have to do good enough changes to implement this in my App.
I got good example which demonstrates how setTimeout works synchronously and asynchronously.