Author |
Topic: Extract just the midi status (Read 1754 times) |
|
msalmon
New Member

 MIDI-OX Rules!
Posts: 10
|
 |
Extract just the midi status
« on: Dec 2nd, 2009, 1:03pm » |
Quote Modify
|
I want to differentiate midi note on/off events from within a Sink_MidiInput function. The "status" parameter has the velocity attached to it (and possibly is added to the channel??). Assuming the channel isn't also added to get the midi status from the same paramter? vb doesnt seem to have a left-wise bit shift. I'm hoping someone has done this before The Mid, MidB functions might help but I've yet to crack the code!
|
|
IP Logged |
|
|
|
Jamie OConnell
Administrator
    


Gender: 
Posts: 2027
|
 |
Re: Extract just the midi status
« Reply #1 on: Dec 2nd, 2009, 8:05pm » |
Quote Modify
|
The MIDI Message for Note ON contains 3 bytes and looks like: Status/Chan Note# Velocity 9n 0-7F 1-7F n* is 4 bit channel 0 -15 (0 - F) Note# is 0 -127 (0 - 7F) Velocity is 1 - 127 Note OFF is 3 bytes and is specified in either of two ways (depending on transmitter) -- a receiver has to expect either and/or both: Status/Chan Note# Velocity 9n 0-7F 0 8n 0-7F 0-7F
|
« Last Edit: Dec 2nd, 2009, 8:06pm by Jamie OConnell » |
IP Logged |
--Jamie Music is its own reward.
|
|
|
msalmon
New Member

 MIDI-OX Rules!
Posts: 10
|
 |
Re: Extract just the midi status
« Reply #2 on: Dec 4th, 2009, 11:33am » |
Quote Modify
|
Sub Sink_MidiInput( ts, port, status, data1, data2) my understanding of the parameter definition from http://www.midi.org/techspecs/midimessages.php (for channel voice messages) ts = timestamp port = midi device id status = 1 byte, aaaannnn; nnnn = midi channel number 1-16 if aaaa = 1000 (&h80) // NOTE OFF event if aaaa = 1001 (&h90) // NOTE ON event data1 = key note value data2 = velocity So assuming I have that correct, the issue I have is recognizing the aaaa/nibble in the status byte. I was trying to capture the value into it's own variable but VBScript doesn't have bitwise shifting. Or maybe there's a way to do it in a conditional or with some other black magic? Or maybe I should just rewrite it in python? Any comments on performance between VBS & Pywin32 would be appreciated. Also I'd love to know any performance data between using the Sink callback methodology vs. reading the midiInput data in a loop. thanks, ms
|
« Last Edit: Dec 4th, 2009, 11:34am by msalmon » |
IP Logged |
|
|
|
Jamie OConnell
Administrator
    


Gender: 
Posts: 2027
|
 |
Re: Extract just the midi status
« Reply #3 on: Dec 5th, 2009, 1:12am » |
Quote Modify
|
What you wrote is almost right. Go back and look at my previous note for the missing details. In particular, Note On (&h90) with 0 velocity is a Note Off, as is &h80. Also channel is expressed as 0 - 15 (&h0 - &hF). To get the common channel number (1 - 16) you have to add 1 to it. Anyway, you can get the status by several ways. If you want only the nibble shifted down you can do: (status / 16). If you want to retain it's position in the status byte (more common) you can do: (status And &hF0). Equivalently, channel is: ((status And &h0F) + 1) for a 1 based channel number.
|
« Last Edit: Dec 5th, 2009, 1:13am by Jamie OConnell » |
IP Logged |
--Jamie Music is its own reward.
|
|
|
msalmon
New Member

 MIDI-OX Rules!
Posts: 10
|
 |
Re: Extract just the midi status
« Reply #4 on: Dec 5th, 2009, 2:29am » |
Quote Modify
|
thanks that code should do the trick!
|
|
IP Logged |
|
|
|
|