我需要了解在使用多个MIDI设备时如何返回MIDI包的源代码。
我使用下面的循环连接了我所有的源代码:
ItemCount sourceCount = MIDIGetNumberOfSources();
for (ItemCount i = 0 ; i < sourceCount ; ++i) {
MIDIEndpointRef source = MIDIGetSource(i);
MIDISourceConnectPort( inPort, source, &i);
}我知道MIDISourceConnectPort()中的最后一个参数是一个上下文,用于标识发送到MIDIReadProc回调的源。因此,我尝试将源文件的索引发送到MIDIReadProc。
void MIDIReadProc (const MIDIPacketList *pktlist,
void *readProcRefCon,
void *srcConnRefCon)
{
\\ How do I access the source index passed in the conRef by using *srcConnRefSource?
}我需要知道这一点的原因是,我正在尝试向设备发送LED反馈,我需要知道是哪个设备发送了数据包,以便将反馈发送到正确的设备。
发布于 2013-03-24 23:21:16
下面的代码假设您已经为输入和输出设置了MIDIClient和MIDIPortRef:
-(void)connectMidiSources{
MIDIEndpointRef src;
ItemCount sourceCount = MIDIGetNumberOfSources();
for (int i = 0; i < sourceCount; ++i) {
src = MIDIGetSource(i);
CFStringRef endpointName = NULL;
MIDIUniqueID sourceUniqueID = NULL;
CheckError(MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endpointName), "Unable to get property Name");
CheckError(MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &sourceUniqueID), "Unable to get property UniqueID");
NSLog(@"Source: %u; Name: %@; UniqueID: %u", i, endpointName, sourceUniqueID);
// *** The last paramenter in this function is a pointer to srcConnRefCon ***
CheckError(MIDIPortConnectSource(clientInputPort, src, (void*)sourceUniqueID), "Couldn't connect MIDI port");
}
}并在MIDIReadProc中访问源refCon上下文:
void midiReadProc (const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon){
//make a reference to the class you have the MIDIReadProc implemented within
MidiManager *midiListener = (MidiManager*)readProcRefCon;
//print the UniqueID for the source MIDIEndpointRef
int sourceUniqueID = (int*)srcConnRefCon;
NSLog(@"Note On sourceIdx: %u", sourceUniqueID);
// the rest of your code here...
}https://stackoverflow.com/questions/15586755
复制相似问题