Hi Paul,
Thanks for your answer.
in fact the MyMIDIPreadProc() can fire successfully. but the trouble is it can not get correct incoming parameter value“void *srcConnRefCon”.
I put more codes here:
// in viewDidLoad:
unsigned long sourceCount = MIDIGetNumberOfSources(); for (int i = 0; i < sourceCount; ++i) { MIDIEndpointRef src = "">MIDIGetSource(i);
MIDIUniqueID sourceUniqueID = NULL;
MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &sourceUniqueID);
NSString *s = [NSString stringWithFormat:@"sourceUniqueID %i",sourceUniqueID]; MIDIPortConnectSource(inPort, src,(__bridge_retained void*)s);
}
// in MyMIDIPreadProc()
void MyMIDIReadProc(const MIDIPacketList *pktlist, void *refCon,void *srcConnRefCon) {
NSString *str = (__bridge NSString*)srcConnRefCon; NSLog(@“ The sourceUniqueID is : %@", str);
for (int i=0; i < pktlist->numPackets; i++) { …..
Then when it receive MIDI notes. it will logs “ The sourceUniqueID is : (null)”
why it logs "(null)” ? I’m using ARC by the way.
Thanks Tin
Hey tin,
still figuring all this stuff too, but from what I understand:
your MyMIDIReadProc will never get fired unless you’ve discovered and connected to a specific MIDI Source:
nSrcs = MIDIGetNumberOfSources(); int yourChosenSource; MIDIEndpointRef src = "">MIDIGetSource (yourChosenSource); MIDIPortConnectSource (inPort, src, NULL);
then your MyMIDIReadProc will fire with incoming MIDI on that specific source..
Hope this helps… Paul.
Hi All,
I want to pass a refCon to identify each MIDI source in MIDIReadProc(). but I don’t know why the srcConnRefCon point always be “null”.
// codes
NSString *str = @“sourceName" MIDIPortConnectSource(inPort, src,(__bridge_retained void*) str);
// use in “ void MyMIDIReadProc(const MIDIPacketList *pktlist, void *refCon,void *srcConnRefCon) "
NSString *receiveStr = (__bridge NSString*)srcConnRefCon; NSLog(@"%@", receiveStr);
Where is wrong ? any help is appreciate.
Thanks Tin
|