我知道 MIDI 允许我通过捕捉指示控制变化的 MIDI 消息来读取 MIDI 脚踏 Controller 的状态。但是,如果用户还没有触摸/更改控件呢?我还能读取状态/值吗?有什么方法可以做到这一点?
这是我使用 OSX CoreMIDI 捕捉 Midi 消息的代码
void initMidi()
{
MIDIClientRef midiClient;
MIDIPortRef inputPort;
OSStatus status;
MIDIEndpointRef src;
status = MIDIClientCreate(CFSTR("testing"), NULL, NULL, &midiClient);
if (status != noErr)
NSLog(@"Error creating MIDI client: %d", status);
status = MIDIInputPortCreate(midiClient, CFSTR("Input"), midiInputCallback, NULL, &inputPort);
if (status != noErr)
NSLog(@"Error creating MIDI input port: %d", status);
ItemCount numOfDevices = MIDIGetNumberOfDevices();
// just try to connect to every device
for (ItemCount i = 0; i < numOfDevices; i++) {
src = MIDIGetSource(i);
status = MIDIPortConnectSource(inputPort, src, NULL);
}
}
void midiInputCallback(const MIDIPacketList *list,
void *procRef,
void *srcRef)
{
for (UInt32 i = 0; i < list->numPackets; i++) {
const MIDIPacket *packet = &list->packet[i];
for (UInt16 j = 0, size = 0; j < packet->length; j += size) {
UInt8 status = packet->data[j];
if (status < 0xC0) size = 3;
else if (status < 0xE0) size = 2;
else if (status < 0xF0) size = 3;
else if (status < 0xF3) size = 3;
else if (status == 0xF3) size = 2;
else size = 1;
switch (status & 0xF0) {
case 0xb0:
NSLog(@"MIDI Control Changed: %d %d", packet->data[j + 1], packet->data[j + 2]);
break;
}
}
}
}
最佳答案
如果您没有重置设备,也没有更改控件,那么您的程序在收到消息之前不会知道控件的状态。
某些设备可能具有特定于供应商的命令来读取控件的当前状态,或转储整个状态。
关于c++ - 如何读取 MIDI 脚踏 Controller 的初始状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26735414/