Re: Newbie documentation for MIDI
Re: Newbie documentation for MIDI
- Subject: Re: Newbie documentation for MIDI
- From: Chris Reed <email@hidden>
- Date: Tue, 26 Nov 2002 15:18:46 -0600
Owww.... :)
DO is *much* simpler to use than NSPorts or mach_ports, etc. Even for
inter-machine messaging, DO is quite simple.
This method makes self available for DO. (All the code here is for
inter-thread or inter-process. It won't work between machines.)
- (BOOL)vendMyselfAs:(NSString *)name onRunLoop:(NSRunLoop *)runLoop
inNewThread:(BOOL)inNewThread
{
NSConnection *conn = [NSConnection defaultConnection];
[conn enableMultipleThreads];
[conn setRootObject:self];
BOOL registeredOK = [conn registerName:name];
if (registeredOK && inNewThread)
[conn runInNewThread];
}
return registeredOK;
}
If you don't set inNewThread to YES, the run loop for the thread you
send this message in will be monitoring the connection. By default, the
connection is watched in NSDefaultRunLoopMode.
In the calling object:
- (id)proxyWithName:(NSString *)name
{
return [[[NSConnection rootProxyForConnectionWithRegisteredName:name
host:nil] retain] autorelease];
}
Once you have the proxy you're free to send messages to it just like
any other object, only they will be executed in the receiving thread
instead of sending one.
You should create a protocol for the root proxy in order to speed
things up (so the connection doesn't have to spend time querying the
root proxy). Like this:
@protocol MyRootProxyProtocol
- (oneway void)updateGUIWithNewValue:(float)value;
@end
Then call this method on the proxy once you have it:
myProxy = [[self proxyWithName:@"MyGUIUpdater"]
setProtocolForProxy:@protocol(MyRootProxyForProtocol)];
Notice that I used the "oneway" keyword in the protocol definition.
That prevents the sender from blocking, waiting for a response.
(All this code was written in-line, and hasn't been tested. YMMV.)
Cheers
-chris
On Tuesday, November 26, 2002, at 02:36 pm, Michael Thornburgh wrote:
for cross-thread communication, you're _supposed_ to use
"Distributed Objects". i've never really bothered trying
to figure DO out though. it seems like you have to jump
through a mess of nasty looking hoops so you can end up
with simple objc messages.
if i wanted to signal my UI thread from my real-time thread
that it should do some drawing for me at some point, i'd
use NSPorts and NSPortMessages. here's some simple code
to illustrate how to do this (compile at the command line
with "cc -framework Foundation filename.m", run with "./a.out"):
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.