playNote duration seems to not work in v3?
hello!
I'm just playing around with webmidi.js and a Novation Launchpad X a bit and am seeing some things that I can't quite make sense off:
// midi controller does not light up at all WebMidi.outputs[1].playNote(36, {duration: 500}) // midi controller lights up and does not turn off again WebMidi.outputs[1].playNote(36, {duration: 2000})
I'd be surprised if I'd found a bug but I'm short of any better explanations.
I'll look into logging more events from the device to better understand this but wanted to share this in the meantime and say hi on the forum :wave:
Comments
When I try your code, everything seems to work on my end. Which version are you using?
I'm loading webmidi.js from here: https://cdn.jsdelivr.net/npm/webmidi@next/dist/webmidi.iife.js
I've also tried to log the from the corresponding input to see what events come through but I haven't quite been able to get that to work. When I send to output X channel 1, should I be able to listen to what I'm sending on input X channel 1? Maybe that's not how midi works. I'm very new to this so excuse my lack of understanding please :)
I'm loading webmidi.js from here: https://cdn.jsdelivr.net/npm/webmidi@next/dist/webmidi.iife.js
This would mean you are currently using v3.0.0-alpha.3.
When I send to output X channel 1, should I be able to listen to what I'm sending on input X channel 1?
No. From WebMidi,js' perspective, an output refers to a device (hardware or software) to which we can send MIDI data. For instance, if you have a sound module that supports MIDI, you can send it commands to play sounds. An input refers to a device from which we can receive MIDI data (a keyboard, for example).
Some MIDI devices (DAWs, for example) have both IN and OUT ports. However, that does not mean that what comes in is forwarded to the out port.
If you want to better understand what happens a the MIDI level, you can install software that will let you spy on MIDI traffic. I use MIDI Monitor (macOS) for that very purpose.
Cheers!
This would mean you are currently using v3.0.0-alpha.3.
Yes! I started a new project and saw the great API docs for v3 so I figured I might just give that a try. :)
works as expected btw
Could the issue be that
returns false when
options.time
isnull
?https://webmidijs.org/docs/v3.0.0-alpha.3/OutputChannel.js.html#line-666
Which browser are you using?
You are right that
convertToTimestamp()
will returnfalse
if the time is not defined. However,false + 1000
is supposed to work out to1000
.Maybe I need to be more defensive here.
Passing
webmidi.time
as thetime
option toplayNote
fixes the problem!Using latest Chrome
You are completely right. I wasn't witnessing the problem because I was triggering the
playNote()
at the very beginning of my code. This meant that thetime
did not really matter. It also fooled my unit tests for the same reason. I will fix this.I just checked the code for v2 and it seems I made a mistake in refactoring for v3. As you can see, v3 is a major overhaul. Let me get back to you regarding the fix. I guess very few people are using v3... which is a good thing since it's still very alpha!
No problem! I'm happy to help. The code seems very readable & I was able to check some basic things figure this out.
I published an updated version (v3.0.0-alpha.4). Can you test it and report back? The new version can be linked against this url:
https://cdn.jsdelivr.net/npm/webmidi@v3.0.0-alpha.4/dist/webmidi.iife.js
Thank you so much, Martin, for reporting the problem.
It's fixed! Thanks :)