我知道这应该很容易但是..。我正在尝试从midiStatus消息中获取MIDI频道号。
我收到了MIDI的信息:
MIDIPacket *packet = (MIDIPacket*)pktList->packet;
for(int i = 0; i<pktList->numPackets; i++){
Byte midiStatus = packet->data[0];
Byte midiCommand = midiStatus>>4;
if(midiCommand == 0x80){} ///note off
if(midiCommand == 0x90){} ///note on
}我试过了
Byte midiChannel = midiStatus - midiCommand但这似乎没有给我正确的价值观。
发布于 2013-04-14 07:15:53
首先,并不是所有的MIDI消息都有通道。(例如,时钟消息和sysex消息不需要。)带有通道的消息被称为“语音”消息。
为了确定任意MIDI消息是否为语音消息,您需要检查第一个字节的前4位。然后,一旦您知道您有一条语音消息,通道就在第一个字节的低4位。
语音消息在0x8n和0xEn之间,其中n是通道。
Byte midiStatus = packet->data[0];
Byte midiCommand = midiStatus & 0xF0; // mask off all but top 4 bits
if (midiCommand >= 0x80 && midiCommand <= 0xE0) {
// it's a voice message
// find the channel by masking off all but the low 4 bits
Byte midiChannel = midiStatus & 0x0F;
// now you can look at the particular midiCommand and decide what to do
}还请注意,MIDI通道在消息中介于0-15之间,但通常以1-16之间的形式呈现给用户。在向用户显示通道之前,您必须添加1,如果从用户获取值,则必须减去1。
https://stackoverflow.com/questions/15993856
复制相似问题