• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CoreMIDI functions returning kMIDIWrongThread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >CoreMIDI functions returning kMIDIWrongThread (From: "Brian Sheehan" <email@hidden>)

  • Prev by Date: Virtual MIDI Sending Help Needed
  • Next by Date: playing audio buffer content - Newbie question
  • Previous by thread: CoreMIDI functions returning kMIDIWrongThread
  • Next by thread: Virtual MIDI Sending Help Needed
  • Index(es):
    • Date
    • Thread