Re: MIDIThruConnection Confusion
Re: MIDIThruConnection Confusion
- Subject: Re: MIDIThruConnection Confusion
- From: Michael Fielitz <email@hidden>
- Date: Tue, 30 Jul 2013 12:41:44 +0200
Hello,
just for the record – the solution to my problem is just a simple cast through CFDataGetBytePtr. Sarayuth Thammabhokin has been so kind and sent me the following code snippet:
<code>
- (IBAction)disposeAllThruConnections:(id)sender;
{
CFDataRef outConnectionList;
OSStatus err = MIDIThruConnectionFind(CFSTR("de.12decode.MW2E"), &outConnectionList);
if (!err && outConnectionList)
{
CFIndex byteCount = CFDataGetLength(outConnectionList);
const MIDIThruConnectionRef *thruConnPtr = (const MIDIThruConnectionRef *)CFDataGetBytePtr(outConnectionList);
NSUInteger itemCount = byteCount / sizeof(MIDIThruConnectionRef);
//......do stuff
if (itemCount)
{
NSRunAlertPanel(@"Attention!", @"Invalid thru connection detected.", @"OK", nil, nil);
for (int i = 0 ; i < itemCount; ++i)
{
err = MIDIThruConnectionDispose(thruConnPtr[i]);
if (err)
{
NSLog(@"Error When Dispose MIDIThruConnection With Code: %ld", err);
}
}
}
CFRelease(outConnectionList);
}
}
</code>
Michael
> From: Michael Fielitz
> Date: Fri, 12 Apr 2013 10:26:01 +0200
>
> Hi,
>
> does anybody has some experiences with these functions? The documentation for MIDIThruConnectionCreate says:
> inPersistentOwnerID - If null, then the connection is marked as owned by the client and will be automatically disposed with the client.
>
> However, when my program has been terminating abnormally, the thru daemon is still hanging around and doing its job whenever a coremidi process is running.
> The only way to kill this beast seems to be to delete the file:
>
> ~/Preferences/ByHost/com.apple.MIDI.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.plist
>
> I also tried the other option with PersistentOwnerID and looking for dangling refs on program start. The problem is, I have no idea how to properly deserialize outConnectionList:
>
> - (void)disposeAllThruConnections;
> {
> CFDataRef outConnectionList;
> OSStatus status = MIDIThruConnectionFind(CFSTR("de.12decode.MW2E"), &outConnectionList);
>
> if (status == noErr && CFDataGetLength(outConnectionList) != 0) {
> #if 0
> NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:(NSData *)outConnectionList];
> for (int i = 0; i < [array count]; i++) {
> MIDIThruConnectionRef ref = (MIDIThruConnectionRef)[array objectAtIndex:i];
> MIDIThruConnectionDispose(ref);
> }
> #endif
> }
> }
>
> The code above crashes on unarchiveObjectWithData. Are there any other possibilities?
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden