【问题标题】:Getting MIDI Channel from midistatus从 midstatus 获取 MIDI 通道
【发布时间】:2013-04-13 22:57:48
【问题描述】:

我知道这应该很容易,但是... 我正在尝试从 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

但这似乎没有给我正确的值。

【问题讨论】:

    标签: midi coremidi


    【解决方案1】:

    首先,并不是所有的 MIDI 信息都有通道。 (例如,时钟消息和 sysex 消息没有。)带有频道的消息称为“语音”消息。

    为了确定任意 MIDI 消息是否为语音消息,您需要检查第一个字节的前 4 位。然后,一旦你知道你有一条语音消息,通道就在第一个字节的低 4 位。

    语音消息介于0x8n0xEn 之间,其中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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 2010-12-01
      • 1970-01-01
      相关资源
      最近更新 更多