2013-03-23 2 views
1

여러 MIDI 장치를 사용할 때 MIDI 패킷의 소스를 반환하는 방법을 이해해야합니다.CoreMIDI refCon이 MIDIReadProc에 전달되었습니다.

나는 다음과 같은 루프를 사용하여 연결된 모든 내 소스를 가지고 :

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 의견을 보내려고하고 내가 올바른 장치로 의견을 보낼 수 있도록 패킷을 전송하는 장치를 알 필요가 있다는 것입니다.

답변

2

아래 코드는 이미 입력 및 출력에 대한 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... 

} 
관련 문제