coremidi - MidiReadProc - using srcConnRefCon to listen to only one source -



coremidi - MidiReadProc - using srcConnRefCon to listen to only one source -

i trying write basic app uses coremidi receive midi events specific source. understand midi events come port phone call proc connected via midiinputportcreate(). understand when using midiportconnectsource() can send identifier (connrefcon) help know source is. i'm not sure how utilize it.

i figure within midireadproc can utilize scrconnrefcon , if statement hear specific source, still dont know *void should pass separate each source. ideally readproc this:

void sourcereadproc (const midipacketlist *pktlist, void *readprocrefcon, void *srcconnrefcon) { if (srcconnrefcon == mysourcechoice) { // pass pktlist } };

any help appreciated. gw

after break i've come project fresh perspective. when phone call midiportconnectsource , pass unique connrefcon it's not apparently passing each endpoint. here's code:

itemcount count = midigetnumberofsources(); (itemcount i=0; i<count; i++) { midiendpointref endpoint = midigetsource(i); midiobjectgetstringproperty(endpoint,kmidipropertyname, &midiendpointsourcename); nslog(@"source %lu: %@", i, midiendpointsourcename); midiportconnectsource(midisourceport, endpoint, (void*)&i); }

then read proc:

void sourcereadproc (const midipacketlist *pktlist, void *readprocrefcon, void *srcconnrefcon) { itemcount *source = (itemcount*) srcconnrefcon; nslog(@"source: %lu", *source); }

i've hooked 2 different midi sources , can find them both fine. first code reports there 2 sources , tells me names. read proc says sources first source. i've tried 3 different info types when passing connrefcon no luck. sense issue must midiportconnectsource.

any help or troubleshooting ideas great. wish coremidi had functions query what's connected ports check that, alas, there's not.

the srcconnrefcon useful if you've made multiple midiportconnectsource() calls. commonly, it's pointer object representing source, anything. if want disambiguate multiple sources, could, say, utilize string.

midiportconnectsource(port, endpoint1, (void *)"endpoint1"); midiportconnectsource(port, endpoint2, (void *)"endpoint2");

then, in sourcereadproc, you'd this:

char *source = (char *)srcconnrefcon; if (!strcmp(source, "endpoint1")) { // process packets source 1 }

make sure allocation lifetime of whatever pass in extends long port connected - otherwise you'll dangling pointer, can hell debug.

coremidi

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -