usbMIDI Note On with velocity=0

Status
Not open for further replies.

Shuptuu

Active member
Hi,
I just noticed that using teensy boards as usb midi devices, midi messages like "90 xx 00" (i.e. note on midi message with velocity=0) are considered when received as note off midi messages. Which is normal according the Midi spec, I agree. But that means you can't make a difference between "90 xx 00" and "80 xx 00" messages.
For my project, I need to detect separatly these 2 types of messages. So Is there a way to make Teensy considering "90 xx 00" messages as note on?
Or Is there a way to access the raw midi messages?
Thanks for your help
Olivier
(I'm using arduino IDE to write and compile my code)
 
So you are using the setHandle... method and usbMIDI.setHandleNoteOff(OnNoteOff) gets fired when a note-on with vel=0 is received?

Try the approach in the section "Receiving Messages with Read & Query Functions" of the usbMIDI page.

The getType value should remain as note-on even if Vel=0. (I think!)
 
Thanks for your answer,
Unfortunately not, that's the same with setHandle or query functions. The getType return 0 (note off) even if the message sent is "90 xx 00"....
 
Here's where that happens in the usb_midi.c file:

Code:
210 		if (type1 == 0x09 && type2 == 0x09) { 
211 			if ((n >> 24) > 0) { 
212 				usb_midi_msg_type = 1;		// 1 = Note on 
213 				if (usb_midi_handleNoteOn) 
214 					(*usb_midi_handleNoteOn)(ch, (n >> 16), (n >> 24)); 
215 			} else { 
216 				usb_midi_msg_type = 0;		// 0 = Note off 
217 				if (usb_midi_handleNoteOff) 
218 					(*usb_midi_handleNoteOff)(ch, (n >> 16), (n >> 24)); 
219 			} 
220 		} else
Maybe usb_midi_msg_type could be set to 1 and still leave the handle stuff in place?
 
Here's where that happens in the usb_midi.c file:

Code:
210 		if (type1 == 0x09 && type2 == 0x09) { 
211 			if ((n >> 24) > 0) { 
212 				usb_midi_msg_type = 1;		// 1 = Note on 
213 				if (usb_midi_handleNoteOn) 
214 					(*usb_midi_handleNoteOn)(ch, (n >> 16), (n >> 24)); 
215 			} else { 
216 				usb_midi_msg_type = 0;		// 0 = Note off 
217 				if (usb_midi_handleNoteOff) 
218 					(*usb_midi_handleNoteOff)(ch, (n >> 16), (n >> 24)); 
219 			} 
220 		} else
Maybe usb_midi_msg_type could be set to 1 and still leave the handle stuff in place?

Yes, you got it! this is exactly where is the problem (if we can call this a problem... for me it is!)
I don't really like to modify libraries as long as most of the time, you then forget what you changed and if you do later a library update, your code doesn't work anymore and you don't know why! ;-)
But replacing this code with something like:
Code:
210 		if (type1 == 0x09 && type2 == 0x09) {
211 				usb_midi_msg_type = 1;		// 1 = Note on 
212 				if (usb_midi_handleNoteOn) 
213 					(*usb_midi_handleNoteOn)(ch, (n >> 16), (n >> 24)); 
214 		       } else

would fix my problem.
May go for that option...
Just a small question: this usb_midi.c file is in the Teensy3 folder. I'm using Teensy LC devices. Do you know if that file apply also for Teensy LC? (have to wait tonight or tomorrow before to test....)
Thanks for your help!
Olivier
 
Status
Not open for further replies.
Back
Top