首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CoreMIDI refCon已传递给MIDIReadProc

CoreMIDI refCon已传递给MIDIReadProc
EN

Stack Overflow用户
提问于 2013-03-23 20:27:11
回答 1查看 631关注 0票数 2

我需要了解在使用多个MIDI设备时如何返回MIDI包的源代码。

我使用下面的循环连接了我所有的源代码:

代码语言:javascript
复制
ItemCount sourceCount = MIDIGetNumberOfSources();
for (ItemCount i = 0 ; i < sourceCount ; ++i) {

MIDIEndpointRef source = MIDIGetSource(i);
MIDISourceConnectPort( inPort, source, &i);

}

我知道MIDISourceConnectPort()中的最后一个参数是一个上下文,用于标识发送到MIDIReadProc回调的源。因此,我尝试将源文件的索引发送到MIDIReadProc。

代码语言:javascript
复制
void MIDIReadProc (const MIDIPacketList   *pktlist,
                 void                   *readProcRefCon,
                 void                   *srcConnRefCon)
{

\\ How do I access the source index passed in the conRef by using *srcConnRefSource?

}

我需要知道这一点的原因是,我正在尝试向设备发送LED反馈,我需要知道是哪个设备发送了数据包,以便将反馈发送到正确的设备。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-24 23:21:16

下面的代码假设您已经为输入和输出设置了MIDIClient和MIDIPortRef:

代码语言:javascript
复制
-(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上下文:

代码语言:javascript
复制
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...

}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15586755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档