Re: CoreMIDI functions returning kMIDIWrongThread
Re: CoreMIDI functions returning kMIDIWrongThread
- Subject: Re: CoreMIDI functions returning kMIDIWrongThread
- From: Doug Wyatt <email@hidden>
- Date: Tue, 25 Apr 2006 19:12:26 -0700
I see there are more messages I should respond to ... tomorrow ...
On Apr 25, 2006, at 8:02, Brian Sheehan wrote:
Hi,
In the following code, all the CoreMIDI functions called return
with errors:
#import <Cocoa/Cocoa.h>
#import <CoreMIDI/CoreMIDI.h>
#import <CoreFoundation/CoreFoundation.h>
int main(int argc, char *argv[])
{
ItemCount numOfEndpoints;
MIDIEndpointRef endpoint;
MIDIClientRef theMidiClient;
OSStatus err = MIDIRestart();
As an app you should not call this unless you find a need to give the
user a way to shut all the drivers down completely and start them
back up again (which is what this call does). It's equivalent to
Audio MIDI Setup's Rescan button.
err = MIDIClientCreate(CFSTR("Test"), NULL, NULL, &theMidiClient);
numOfEndpoints = MIDIGetNumberOfDestinations();
if (numOfEndpoints)
{
endpoint = MIDIGetDestination(0);
}
return NSApplicationMain(argc, (const char **) argv);
}
MIDIRestart() and MIDIClientCreate() both return -10841 (from the
docs: "kMIDIWrongThread: A driver is calling a non-I/O function in the
server from a thread other than the server's main thread").
You aren't linking against CoreMIDIServer.framework are you? That's
the only explanation I can think of for this error appearing in an
app. Only drivers should link against CoreMIDIServer.framework. Apps
should link against CoreMIDI.framework.
If that's not the problem, it could be that you are encountering an
order-of-initialization problem by calling these functions so early.
Try doing this from an application delegate's
applicationWillFinishLaunching.
Doug
The puzzling thing is that in a different project with *exactly* the
same code, things work fine. I noticed that with the second project,
a thread is started by the call to MIDIRestart() - this doesn't happen
with the code in the first project.
Any ideas? I'm really scratching my head here... both the projects
concerned here are Cocoa document based projects. The first project is
a working application, and the second project (where the CoreMIDI
calls succeed) is the default doc-based cocoa app template from xcode.
--
Doug Wyatt
Core Audio, Apple
_______________________________________________
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