midi note-off variation #648
Conversation
|
I’m not actually sure what that byte is doing in the channel message. But I think you are correct and just changing msg.type would be fine.
… On Nov 20, 2018, at 11:26 AM, Mark Wheeler ***@***.***> wrote:
@markwheeler commented on this pull request.
In lua/midi.lua:
> + if data[3] > 0 then
+ --print("note")
+ msg = {
+ type = "note_on",
+ note = data[2],
+ vel = data[3],
+ ch = data[1] - 0x90 + 1
+ }
+ -- if velocity is zero then send note off
+ elseif data[3] == 0 then
+ --print("noteoff")
+ msg = {
+ type = "note_off",
+ note = data[2],
+ vel = data[3],
+ ch = data[1] - 0x80 + 1
Should channel not be the same as above? Which makes me wonder if the only thing contained in the if statement should be the msg.type?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
@okyeron sorry for the lag, im waiting for someone else to put eyes on this since i really don't/can't use the midi stuff. but i remember something about this a while ago - it seems strange but IIRC there was actually controversy about mapping vel=0 to noteoff. maybe it should be a configuration option in the lua environment. |
|
I'm sure there's probably some situation where note-on plus vel=0 should NOT be a note-off, but if half the MIDI instrument manufacturers are doing it that way, what can you do? A configuration option would be nice, but I wouldn't know how to implement that. |
|
accidentally approved, disregard.
just change the msg.type. the change to channel will result in the wrong channel being sent. did you test this with your hardware? |
|
there indeed was a controversy about this logic, but i think it was related to the low-level midi events and for the high-level api it will not harm. |
|
updated. tested with Qunexus and Livid Block. is the following syntax OK?
|
|
FWIW - my problem with the MK-225C controller is that it constantly sends an Active Sensing byte which barfs inside my quick hack around this was to wrap most of Midi.to_msg in a check to be sure there is a second data byte
Are clock/start/stop/continue (which also have a nil second byte) ignored somewhere? |
|
clock events don't have a second byte, their length is determined in matron (device_midi.c). what exactly is an active sensing byte? |
Not really sure myself, but I see that message when I plug that device into my mac with MIDI monitor running. The MIDI spec shows this: 11111110= FE= 254 | Active Sensing | -- | -- a google search gives me this description:
|
|
a message with a status byte of 0xfe will be handled as other 1-byte messages, Midi.to_msg should just return |
|
Apparently 0xfe is not being handled as a 1-byte message and it tries to evaluate it as note/cc and maiden spits out a stream of errors about attempting a bitwise operation on nil. looking at device_midi.c 0xfe is not handled explicitly and ends up with the default msg_len = 2; I can file a separate issue for this |
|
but it's handled, see https://github.com/monome/norns/blob/master/matron/src/device/device_midi.c#L55 so the problem is with the lua part, can you send the specific script code that you have a problem with? |
|
Ok so I have a very basic connection script
With the MK-225C as soon as this runs i get a stream of the following errors:
So here it appears to be trying to evaluate the 0xfe message as a note-on. and the second byte of data is nil and causes the error. |
|
FYI doesn't seem like it's handled, and defaulting to length 2: https://github.com/monome/norns/blob/master/matron/src/device/device_midi.c#L98 feel free to submit a PR that has a case for 0xFE and just throws it away |
|
oh wait, it's handled here (missed the bitmask on line 66) https://github.com/monome/norns/blob/master/matron/src/device/device_midi.c#L79 so there needs to be a nested case for 0x0E which just sets len to 0 @okyeron if you can test this with your device that'd be helpful (i don't have any sensing devices) |
|
ie, just add
after line 89, recompile, and it should be good? |
|
debugging this active sensing thing further... It seems norns.midi.event = function(id, data) is receiving I think what's happening is that there's 2 events being sent from device_midi.c. It looks like there might be a bracket out of place at norns/matron/src/device/device_midi.c Line 105 in 39afbf7 and it needs to move down to line 119 |
|
@tehn @okyeron there's no need to add additional cases for handling the 0xfe status byte, see https://github.com/monome/norns/blob/master/matron/src/device/device_midi.c#L55 the bracket at line 105 is in the right place, moving it to line 119 will cause nothing. adding |
|
@artfwo the bracket change totally fixes the issue for me. I added some debug in testing and the |
|
FWIW - this should be testable with any midi hardware sending clock or start/stop messages. |
|
Getting back to the original pull request... Are the changes above good? And then... Would it be reasonable to add the following items to i think this might be useful for someone working outside of the beatclock library - or for making beakclock more readable.
|
|
this is now probably fine as-is. i can't think of anything that would send a note-on with vel 0 expecting an actual note-on. we definitely can't add more msg.type categories without much more modification to edit: sorry for the lack of clarity. would need to add a bunch of code to |
(I hope I'm not being too thick here but...) I'm not sure I see those ramifications since it just sets the msg.type for those incoming bytes. Unless you mean that we would then need to support those same types being sent out? (which I could look at as well) |
Fix to midi.lua for some midi instruments that send a note-on, velocity zero instead of note-off
per #646