View Single Post
Old 01-07-2012, 07:06 PM   #6
captain_caveman
Human being with feelings
 
captain_caveman's Avatar
 
Join Date: Dec 2011
Posts: 999
Default

Welcome onboard!

If I could point out a couple of bugs for you....

Code:
// Extract note and status value
  note = msg23 & $x7F;
	status = msg1 & $xF0;
The value you extract there for "note" is only the note number when the message type is a Note On or Note Off message. So...
Code:
note == ks1 ? channel = 0;
... when you execute these instructions, if the message type is a Continuous Controller of the number of ks1 (for example), it will behave in the same way as if note number ks1 was received.

Also, the slight PITA of MIDI is that, because note consists of a Note On and a Note Off message, when changing channels you need to handle the possibility of a Note Off being sent to a channel different from it's original Note On channel (which results in hanging notes).

There are two ways of dealing with this, a Note Stack (where you have an list of Note Ons and Channel that have been played, match up the Note Offs to them as they occur and remove that entry) or with an array of every note (JS doesn't have arrays but you can have (roughly) the same functionality as them).

edit: I should clarify that there is a third way, which is sending an All Notes Off message to all channels which does what it says on the tin. It's not very nice when you are playing something though.

Last edited by captain_caveman; 01-07-2012 at 07:13 PM.
captain_caveman is offline   Reply With Quote