Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

multi threading, not unloading threads

 
   Mac (Home) -> Programmer Help RSS
Next:  Universal Binary Won't Run On PPC Macs  
Author Message
Santa Claus

External


Since: Sep 24, 2005
Posts: 85



(Msg. 1) Posted: Mon Jan 22, 2007 8:34 pm
Post subject: multi threading, not unloading threads
Archived from groups: comp>lang>objective-c, others (more info?)

ok, i found out that all sounds MUST be played in the main thread for
some reason so here's what i've done

detatch a thread that scans for the sound file and then loads it into an
array

when that thread is finished, it sets a boolean value saying the sound
has been loaded. i then play the sound loaded in the main thread if the
boolean flag is set

it seems to work for me ok but counting the threads, it shouldn't have
more than one thread running while it's playing. i have 9 running now.

is this something else i have to contend with locating?

-(void)playsound
{
if (lastSoundIsValid && !lastSoundIsMovie)
{
[(NSSound *)[soundArray objectAtIndex: [soundArray count] - 1] play];
lastSoundIsPlaying = YES;
}
#if BuildForOSX == 3
else
{
if (lastSoundIsValid)
{
[(QTMovie *)[soundArray objectAtIndex: [soundArray count] - 1]
play];
lastSoundIsPlaying = YES;
}
}
#endif
lastSoundIsValid = NO;
}

-(void)loadsound: (NSString *) soundname;
{
NSAutoreleasePool *pool1 = [[NSAutoreleasePool alloc] init];
isFinishedLoadingSound = NO;
lastSoundIsValid = NO;
lastSoundIsMovie = NO;
NSSound *tempsound;
BOOL isloaded = NO;
NSError *myerror;
myerror = [[NSError alloc] init];
NSMutableString *soundfilename = [[[NSMutableString alloc] init]
autorelease];
[soundfilename setString: [self locateSound: soundname]];
if ([soundfilename length] > 0)
{
if (([soundfilename rangeOfString: @".mp3" options:
NSCaseInsensitiveSearch].location == NSNotFound) && ([soundfilename
rangeOfString: @".m4v" options: NSCaseInsensitiveSearch].location ==
NSNotFound) && ([soundfilename rangeOfString: @".m4b" options:
NSCaseInsensitiveSearch].location == NSNotFound) && ([soundfilename
rangeOfString: @".aac" options: NSCaseInsensitiveSearch].location ==
NSNotFound) && ([soundfilename rangeOfString: @".m4p" options:
NSCaseInsensitiveSearch].location == NSNotFound))
{
[soundArray addObject: [[NSSound alloc] initWithContentsOfFile:
soundfilename byReference:YES]];
NSLog(@"Now playing sound --> %@",soundfilename);
lastSoundIsPlaying = NO;
lastSoundIsValid = YES;
isloaded = YES;
}
#if BuildForOSX == 3
else
{
if ([QTMovie canInitWithFile: soundfilename])
{
[soundArray addObject: [QTMovie movieWithFile: soundfilename
error: &myerror]];
NSLog(@"Now playing sound --> %@",soundfilename);
lastSoundIsValid = YES;
lastSoundIsPlaying = NO;
lastSoundIsMovie = YES;
isloaded = YES;
}
}
#endif
}
else
{
tempsound = [[NSSound soundNamed: soundname] autorelease];
if (tempsound != nil)
{
NSLog(@"Now playing sound --> %@",soundname);
[soundArray addObject: [NSSound soundNamed: soundname]];
lastSoundIsValid = YES;
lastSoundIsPlaying = NO;
isloaded = YES;
}
}
if (!isloaded)
{
NSLog(@"Unable to locate the sound --> %@", soundname);
[yasse_link echoTextToGameScreen: [NSMutableString stringWithString:
[NSString stringWithFormat: @"Unable to locate the sound --> %@\n",
soundname]]];
}
isFinishedLoadingSound = YES;
[pool1 release];
}

-(void)stopPlayingSounds;
{
if ([soundArray count] > 0)
{
[soundArray makeObjectsPerformSelector: @selector(stop)];
[soundArray removeAllObjects];
}
isFinishedLoadingSound = YES;
}

-(BOOL)isPlayingSounds
{
return ([soundArray count] > 0);
}
Back to top
Login to vote
Gregory Weston

External


Since: Jun 06, 2005
Posts: 660



(Msg. 2) Posted: Tue Jan 23, 2007 9:20 am
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: comp>sys>mac>programmer>help (more info?)

In article <santa-3BFF26.20344522012007.TakeThisOut@news.giganews.com>,
Santa Claus <santa.TakeThisOut@northpole.com> wrote:

> ok, i found out that all sounds MUST be played in the main thread for
> some reason so here's what i've done

The above is not actually true. What you're probably running into is the
lack of an active run loop in the thread(s) from which you're trying to
play sounds.

> detatch a thread that scans for the sound file and then loads it into an
> array
>
> when that thread is finished, it sets a boolean value saying the sound
> has been loaded. i then play the sound loaded in the main thread if the
> boolean flag is set
>
> it seems to work for me ok but counting the threads, it shouldn't have
> more than one thread running while it's playing. i have 9 running now.
>
> is this something else i have to contend with locating?

On a quick glance through the code, I don't see any real attempt to
prevent multiple sounds from playing at once. I note that the loadsound:
method clears the flag that indicates any sound is playing without
verifying that that's the case. Nothing at all in what you've posted
seems to be looking to see if a sound is already playing.


> -(void)playsound
> {
> if (lastSoundIsValid && !lastSoundIsMovie)
> {
> [(NSSound *)[soundArray objectAtIndex: [soundArray count] - 1] play];
> lastSoundIsPlaying = YES;
> }
> #if BuildForOSX == 3
> else
> {
> if (lastSoundIsValid)
> {
> [(QTMovie *)[soundArray objectAtIndex: [soundArray count] - 1]
> play];
> lastSoundIsPlaying = YES;
> }
> }
> #endif
> lastSoundIsValid = NO;
> }

Here's the same routine, using the knowledge that you control soundArray
and everything you put in it is known to respond to the 'play' message.
You really don't need to care about what type of object it is. And even
if you did, you shouldn't be tracking it in a boolean. You can just
query the object. Otherwise you need to keep an array of booleans that
tracks the array of "sound" objects, right?

- (void)playSound
{
if(lastSoundIsValid)
{
[[soundArray lastObject]play];
lastSoundIsPlaying = YES;
lastSoundIsValid = NO;
}
}


> -(void)loadsound: (NSString *) soundname;
> {
> NSAutoreleasePool *pool1 = [[NSAutoreleasePool alloc] init];
> isFinishedLoadingSound = NO;
> lastSoundIsValid = NO;
> lastSoundIsMovie = NO;
> NSSound *tempsound;
> BOOL isloaded = NO;
> NSError *myerror;
> myerror = [[NSError alloc] init];
> NSMutableString *soundfilename = [[[NSMutableString alloc] init]
> autorelease];
> [soundfilename setString: [self locateSound: soundname]];
> if ([soundfilename length] > 0)
> {
> if (([soundfilename rangeOfString: @".mp3" options:
> NSCaseInsensitiveSearch].location == NSNotFound) && ([soundfilename
> rangeOfString: @".m4v" options: NSCaseInsensitiveSearch].location ==
> NSNotFound) && ([soundfilename rangeOfString: @".m4b" options:
> NSCaseInsensitiveSearch].location == NSNotFound) && ([soundfilename
> rangeOfString: @".aac" options: NSCaseInsensitiveSearch].location ==
> NSNotFound) && ([soundfilename rangeOfString: @".m4p" options:
> NSCaseInsensitiveSearch].location == NSNotFound))
> {
> [soundArray addObject: [[NSSound alloc] initWithContentsOfFile:
> soundfilename byReference:YES]];
> NSLog(@"Now playing sound --> %@",soundfilename);
> lastSoundIsPlaying = NO;
> lastSoundIsValid = YES;
> isloaded = YES;
> }
> #if BuildForOSX == 3
> else
> {
> if ([QTMovie canInitWithFile: soundfilename])
> {
> [soundArray addObject: [QTMovie movieWithFile: soundfilename
> error: &myerror]];
> NSLog(@"Now playing sound --> %@",soundfilename);
> lastSoundIsValid = YES;
> lastSoundIsPlaying = NO;
> lastSoundIsMovie = YES;
> isloaded = YES;
> }
> }
> #endif
> }
> else
> {
> tempsound = [[NSSound soundNamed: soundname] autorelease];
> if (tempsound != nil)
> {
> NSLog(@"Now playing sound --> %@",soundname);
> [soundArray addObject: [NSSound soundNamed: soundname]];
> lastSoundIsValid = YES;
> lastSoundIsPlaying = NO;
> isloaded = YES;
> }
> }
> if (!isloaded)
> {
> NSLog(@"Unable to locate the sound --> %@", soundname);
> [yasse_link echoTextToGameScreen: [NSMutableString stringWithString:
> [NSString stringWithFormat: @"Unable to locate the sound --> %@\n",
> soundname]]];
> }
> isFinishedLoadingSound = YES;
> [pool1 release];
> }

Specific comments / study questions:
1. Why are you creating your mutable string with alloc/init/autorelease
instead of just [NSMutableString string]?
2. Why are you setting the already allocated string instead of just
declaring it and assigning it the result of locateSound:?
3. Why is it an NSMutableString instead of an NSString if you never
mutate it? Even if you're going to do the copy I wonder about in
question 2, you can initialize a string with a string instead of
creating it and then setting it after the fact.
4. Why are you using NSMovie for some types that are purely audio and
handled by NSSound?
5. What's going to happen if my some weird quirk you get a sound file
named "foo.mp3.aiff"?
6. isFinishedLoadingSound really needs to be protected by a lock if
that's your thread serialization flag.

You've got a few memory errors in there. When locateSound: succeeds and
gives you back something that goes through NSSound you add an
alloc/inited sound directly to an array. That instance will leak,
because you never give up the implicit reference count from the
alloc/init operation. In the tempsound section, on the other hand, you
autorelease something that's already autoreleased. That's likely to
crash. You don't need to allocate the NSError you're passing to
movieWithFile:error:. That'll leak. Then again you never do anything
with the error, so you might as well just pass nil.

I think the following code does the same thing as yours, minus the
outright errors but retaining some things that I consider suspect
because I can't tell for sure outside the context of your program.

- (void)loadSound:(NSString*)inSoundName
{
BOOL isLoaded = NO;
isFinishedLoadingSound = NO;
lastSoundIsValid = NO;
NSAutoreleasePool* thePool = [[NSAutoreleasePool alloc] init];
NSArray* theMovieTypes = [NSArray arrayWithObjects:@"MP3", @"M4V",
@"M4B", @"AAC", @"M4P", nil];
NSString* theSoundPath = [self locateSound:inSoundName];
id theSound = nil;
if([theSoundPath length] > 0)
{
NSString* theExtension = [theSoundPath pathExtension];
if([theMovieTypes indexOfObject:[theExtension uppercaseString] ==
NSNotFound)
{
theSound = [[NSSound alloc] initWithContentsOfFile:theSoundPath
byReference:YES];
[theSound autorelease];
}
else
{
if([QTMovie canInitWithFile:theSoundPath])
{
theSound = [QTMovie movieWithFile:theSoundPath error:nil];
}
}
}
else
{
theSound = [NSSound soundNamed:soundname];
}
if(theSound)
{
[soundArray addObject:theSound];
lastSoundIsValid = YES;
lastSoundIsPlaying = NO;
}
else
{
[yasse_link echoTextToGameScreen:[NSString stringWithFormat:
@"Unable to locate the sound --> %@\n", soundname]];
}
isFinishedLoadingSound = YES;
[thePool release];
}

>
> -(void)stopPlayingSounds;
> {
> if ([soundArray count] > 0)
> {
> [soundArray makeObjectsPerformSelector: @selector(stop)];
> [soundArray removeAllObjects];
> }
> isFinishedLoadingSound = YES;
> }
>
> -(BOOL)isPlayingSounds
> {
> return ([soundArray count] > 0);
> }

--
The best intentions in the world don't make a flawed argument magically valid.
Back to top
Login to vote
Santa Claus

External


Since: Sep 24, 2005
Posts: 85



(Msg. 3) Posted: Tue Jan 23, 2007 7:33 pm
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

ok, i deliberately crashed in order to see the threads in action
(deliberately crashing is sometimes pretty hard you know). i see the
main thread 0, and the playing thread 7, but i never activated any of
the others. if this is normal, i'll ignore them all and get down to
real code fixing. by the way, i played the sound in thread zero because
of what apple said... ok, i was wrong. i was looking for where i read
it and it didn't have what i wanted to relay to you. (i misread it
originally)

Thread 0 Crashed:
0 libobjc.A.dylib 0x90a3e0f0 objc_msgSend + 16
1 com.robertdell.yasse 0x15da95f4 -[updater
deliberatelyCrash] + 84 (updater.m:85)
2 com.robertdell.yasse 0x15cbcc64 -[yasse
myProcessYESCommand:] + 27340 (yasse.m:15293)
3 com.robertdell.yasse 0x15cd0a48 -[yasse
myProcessCommand:] + 612 (yasse.m:17183)
4 com.robertdell.yasse 0x15c9fe7c -[yasse processCommand:]
+ 3816 (yasse.m:12231)
5 Avalon 0x00026988 -[PluginControl
pluginProcessCommand:] + 196 (PluginControl.m:118)
6 Avalon 0x0000f4ec -[LineProcessor
sendCommand:] + 624 (LineProcessor.m:75)
7 Avalon 0x0000e318 -[LineProcessor send:] +
92 (LineProcessor.m:42)
8 com.apple.AppKit 0x937a7c4c -[NSApplication
sendAction:to:from:] + 108
9 com.apple.AppKit 0x937a7b80 -[NSControl
sendAction:to:] + 96
10 com.apple.AppKit 0x937e56e0 -[NSTextField
textDidEndEditing:] + 632
11 com.apple.Foundation 0x9295bad8 _nsnote_callback + 180
12 com.apple.CoreFoundation 0x90803010 __CFXNotificationPost +
368
13 com.apple.CoreFoundation 0x907fb0ec
_CFXNotificationPostNotification + 684
14 com.apple.Foundation 0x92945ee0 -[NSNotificationCenter
postNotificationName:object:userInfo:] + 92
15 com.apple.AppKit 0x93836f40 -[NSTextView(NSPrivate)
_giveUpFirstResponder:] + 512
16 com.apple.AppKit 0x93836d2c
-[NSTextView(NSKeyBindingCommands) insertNewline:] + 512
17 com.apple.AppKit 0x9383678c -[NSTextView
doCommandBySelector:] + 212
18 com.apple.AppKit 0x937e9dc4
-[NSKeyBindingManager(NSKeyBindingManager_MultiClients)
interpretEventAsCommand:forClient:] + 1700
19 com.apple.AppKit 0x937e84c0 -[NSTSMInputContext
interpretKeyEvents:] + 1104
20 com.apple.AppKit 0x937e78a0 -[NSView
interpretKeyEvents:] + 64
21 com.apple.AppKit 0x937e76f4 -[NSTextView keyDown:] +
756
22 com.apple.AppKit 0x93762fa0 -[NSWindow sendEvent:] +
6424
23 com.apple.AppKit 0x9370b8d4 -[NSApplication
sendEvent:] + 4172
24 Avalon 0x000103e4 -[SIApplication
sendEvent:] + 1556 (SIApplication.m:159)
25 com.apple.AppKit 0x93702d10 -[NSApplication run] + 508
26 com.apple.AppKit 0x937f387c NSApplicationMain + 452
27 Avalon 0x00002548 _start + 348 (crt.c:272)
28 Avalon 0x000023e8 start + 60

Thread 1:
0 libSystem.B.dylib 0x9002bbc8
semaphore_wait_signal_trap + 8
1 libSystem.B.dylib 0x900306ac pthread_cond_wait + 480
2 com.apple.Foundation 0x92963300 -[NSConditionLock
lockWhenCondition:] + 68
3 com.apple.AppKit 0x937a3708 -[NSUIHeartBeat
_heartBeatThread:] + 324
4 com.apple.Foundation 0x9295c194 forkThreadForFunction +
108
5 libSystem.B.dylib 0x9002b508 _pthread_body + 96

Thread 2:
0 libSystem.B.dylib 0x90054ae8
semaphore_timedwait_signal_trap + 8
1 libSystem.B.dylib 0x90071168
pthread_cond_timedwait_relative_np + 556
2 ...ple.CoreServices.CarbonCore 0x90bf4500 TSWaitOnSemaphoreCommon +
176
3 ...ickTimeComponents.component 0x999cf7c4
ReadSchedulerThreadEntryPoint + 5300
4 libSystem.B.dylib 0x9002b508 _pthread_body + 96

Thread 3:
0 libSystem.B.dylib 0x90054ae8
semaphore_timedwait_signal_trap + 8
1 libSystem.B.dylib 0x90071168
pthread_cond_timedwait_relative_np + 556
2 ...ple.CoreServices.CarbonCore 0x90bf4500 TSWaitOnSemaphoreCommon +
176
3 ...ple.CoreServices.CarbonCore 0x90bfefa8 AIOFileThread(void*) + 520
4 libSystem.B.dylib 0x9002b508 _pthread_body + 96

Thread 4:
0 libSystem.B.dylib 0x9000ab48 mach_msg_trap + 8
1 libSystem.B.dylib 0x9000aa9c mach_msg + 60
2 com.apple.CoreFoundation 0x907dbb78 __CFRunLoopRun + 832
3 com.apple.CoreFoundation 0x907db47c CFRunLoopRunSpecific + 268
4 com.apple.CoreFoundation 0x907ea8dc CFRunLoopRun + 52
5 com.apple.DVCPROHDMuxer 0x166c91ac
AVS::DestroyAVCDeviceController(AVS::AVCDeviceController*) + 404
6 libSystem.B.dylib 0x9002b508 _pthread_body + 96

Thread 5:
0 libSystem.B.dylib 0x9000ab48 mach_msg_trap + 8
1 libSystem.B.dylib 0x9000aa9c mach_msg + 60
2 com.apple.CoreFoundation 0x907dbb78 __CFRunLoopRun + 832
3 com.apple.CoreFoundation 0x907db47c CFRunLoopRunSpecific + 268
4 com.apple.audio.CoreAudio 0x9145063c
HALRunLoop::OwnThread(void*) + 264
5 com.apple.audio.CoreAudio 0x914503dc
CAPThread::Entry(CAPThread*) + 96
6 libSystem.B.dylib 0x9002b508 _pthread_body + 96

Thread 6:
0 libSystem.B.dylib 0x90054ae8
semaphore_timedwait_signal_trap + 8
1 libSystem.B.dylib 0x90071168
pthread_cond_timedwait_relative_np + 556
2 com.apple.audio.CoreAudio 0x91461794 CAGuard::WaitFor(unsigned
long long) + 204
3 com.apple.audio.CoreAudio 0x914616a4
CAGuard::WaitUntil(unsigned long long) + 304
4 com.apple.audio.CoreAudio 0x9145f8e8 HP_IOThread::WorkLoop() +
852
5 com.apple.audio.CoreAudio 0x9145f580
HP_IOThread::ThreadEntry(HP_IOThread*) + 16
6 com.apple.audio.CoreAudio 0x914503dc
CAPThread::Entry(CAPThread*) + 96
7 libSystem.B.dylib 0x9002b508 _pthread_body + 96

Thread 7:
0 libSystem.B.dylib 0x9002bcb8 semaphore_wait_trap + 8
1 ...ickTimeComponents.component 0x99f15274 QTThreadWaitSignal + 100
2 ...ickTimeComponents.component 0x99a4f2dc audioprepThreadEntry + 76
3 ...ickTimeComponents.component 0x99f14f34 start_thread + 84
4 libSystem.B.dylib 0x9002b508 _pthread_body + 96
Back to top
Login to vote
Michael Ash

External


Since: Mar 21, 2006
Posts: 164



(Msg. 4) Posted: Tue Jan 23, 2007 7:33 pm
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Santa Claus <santa.TakeThisOut@northpole.com> wrote:
> ok, i deliberately crashed in order to see the threads in action
> (deliberately crashing is sometimes pretty hard you know).

*(int *)NULL = 0 should do it. But this is a very silly way to accomplish
this. Learn to use the debugger. Learn to love the debugger.

> i see the
> main thread 0, and the playing thread 7, but i never activated any of
> the others. if this is normal, i'll ignore them all and get down to
> real code fixing. by the way, i played the sound in thread zero because
> of what apple said... ok, i was wrong. i was looking for where i read
> it and it didn't have what i wanted to relay to you. (i misread it
> originally)

All of these threads are normal. Commentary below:

> Thread 0 Crashed:
> 0 libobjc.A.dylib 0x90a3e0f0 objc_msgSend + 16
[snip]

This, obviously, is your main thread.

> Thread 1:
> 0 libSystem.B.dylib 0x9002bbc8
> semaphore_wait_signal_trap + 8
> 1 libSystem.B.dylib 0x900306ac pthread_cond_wait + 480
> 2 com.apple.Foundation 0x92963300 -[NSConditionLock
> lockWhenCondition:] + 68
> 3 com.apple.AppKit 0x937a3708 -[NSUIHeartBeat
> _heartBeatThread:] + 324
> 4 com.apple.Foundation 0x9295c194 forkThreadForFunction +
> 108
> 5 libSystem.B.dylib 0x9002b508 _pthread_body + 96

This thread is created by AppKit to handle things like animating the
default button.

> Thread 2:
> 0 libSystem.B.dylib 0x90054ae8
> semaphore_timedwait_signal_trap + 8
> 1 libSystem.B.dylib 0x90071168
> pthread_cond_timedwait_relative_np + 556
> 2 ...ple.CoreServices.CarbonCore 0x90bf4500 TSWaitOnSemaphoreCommon +
> 176
> 3 ...ickTimeComponents.component 0x999cf7c4
> ReadSchedulerThreadEntryPoint + 5300
> 4 libSystem.B.dylib 0x9002b508 _pthread_body + 96

This thread is created by QuickTime to handle some sort of scheduling.

> Thread 3:
> 0 libSystem.B.dylib 0x90054ae8
> semaphore_timedwait_signal_trap + 8
> 1 libSystem.B.dylib 0x90071168
> pthread_cond_timedwait_relative_np + 556
> 2 ...ple.CoreServices.CarbonCore 0x90bf4500 TSWaitOnSemaphoreCommon +
> 176
> 3 ...ple.CoreServices.CarbonCore 0x90bfefa8 AIOFileThread(void*) + 520
> 4 libSystem.B.dylib 0x9002b508 _pthread_body + 96

This thread is created by Carbon to handle asynchronous IO.

> Thread 4:
> 0 libSystem.B.dylib 0x9000ab48 mach_msg_trap + 8
> 1 libSystem.B.dylib 0x9000aa9c mach_msg + 60
> 2 com.apple.CoreFoundation 0x907dbb78 __CFRunLoopRun + 832
> 3 com.apple.CoreFoundation 0x907db47c CFRunLoopRunSpecific + 268
> 4 com.apple.CoreFoundation 0x907ea8dc CFRunLoopRun + 52
> 5 com.apple.DVCPROHDMuxer 0x166c91ac
> AVS::DestroyAVCDeviceController(AVS::AVCDeviceController*) + 404
> 6 libSystem.B.dylib 0x9002b508 _pthread_body + 96

This thread appears to be created by some QT component for reasons
unknown.

> Thread 5:
> 0 libSystem.B.dylib 0x9000ab48 mach_msg_trap + 8
> 1 libSystem.B.dylib 0x9000aa9c mach_msg + 60
> 2 com.apple.CoreFoundation 0x907dbb78 __CFRunLoopRun + 832
> 3 com.apple.CoreFoundation 0x907db47c CFRunLoopRunSpecific + 268
> 4 com.apple.audio.CoreAudio 0x9145063c
> HALRunLoop::OwnThread(void*) + 264
> 5 com.apple.audio.CoreAudio 0x914503dc
> CAPThread::Entry(CAPThread*) + 96
> 6 libSystem.B.dylib 0x9002b508 _pthread_body + 96

This thread is created by CoreAudio to handle audio generation.

> Thread 6:
> 0 libSystem.B.dylib 0x90054ae8
> semaphore_timedwait_signal_trap + 8
> 1 libSystem.B.dylib 0x90071168
> pthread_cond_timedwait_relative_np + 556
> 2 com.apple.audio.CoreAudio 0x91461794 CAGuard::WaitFor(unsigned
> long long) + 204
> 3 com.apple.audio.CoreAudio 0x914616a4
> CAGuard::WaitUntil(unsigned long long) + 304
> 4 com.apple.audio.CoreAudio 0x9145f8e8 HP_IOThread::WorkLoop() +
> 852
> 5 com.apple.audio.CoreAudio 0x9145f580
> HP_IOThread::ThreadEntry(HP_IOThread*) + 16
> 6 com.apple.audio.CoreAudio 0x914503dc
> CAPThread::Entry(CAPThread*) + 96
> 7 libSystem.B.dylib 0x9002b508 _pthread_body + 96

Another CoreAudio thread.

> Thread 7:
> 0 libSystem.B.dylib 0x9002bcb8 semaphore_wait_trap + 8
> 1 ...ickTimeComponents.component 0x99f15274 QTThreadWaitSignal + 100
> 2 ...ickTimeComponents.component 0x99a4f2dc audioprepThreadEntry + 76
> 3 ...ickTimeComponents.component 0x99f14f34 start_thread + 84
> 4 libSystem.B.dylib 0x9002b508 _pthread_body + 96

And finally a QuickTime audio thread.

In general, you can treat threads the way you would treat allocated
memory. You don't worry if you have a bunch of things hanging around that
you don't know about, because libraries can make them too. Get worried if
you start performing actions, go back to where you started, and the number
of things keeps increasing.

--
Michael Ash
Rogue Amoeba Software
Back to top
Login to vote
Santa Claus

External


Since: Sep 24, 2005
Posts: 85



(Msg. 5) Posted: Tue Jan 23, 2007 8:37 pm
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <1169602131.138481.RemoveThis@nfs-db1.segnet.com>,
Michael Ash <mike.RemoveThis@mikeash.com> wrote:
> In general, you can treat threads the way you would treat allocated
> memory. You don't worry if you have a bunch of things hanging around that
> you don't know about, because libraries can make them too. Get worried if
> you start performing actions, go back to where you started, and the number
> of things keeps increasing.

thanks, i'll ignore them until that happens.
Back to top
Login to vote
Santa Claus

External


Since: Sep 24, 2005
Posts: 85



(Msg. 6) Posted: Wed Jan 24, 2007 6:17 pm
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <uce-139F4B.22241323012007.RemoveThis@comcast.dca.giganews.com>,
Gregory Weston <uce.RemoveThis@splook.com> wrote:


> > actually, this is a habit of programming, assume i may change it at some
> > point in the routine so make it mutable. at a later date when i want to
> > change things, i may convert it to regular strings.
> >
> > > 4. Why are you using NSMovie for some types that are purely audio and
> > > handled by NSSound?
> >
> > actually, i tested my mp3 files with nssound and nssound didn't play
> > them so i needed a mp3 player (quicktime) to play them.
>
> Something funky with your system or data, then, since NSSound uses
> QuickTime to support some of the data types it works with and MP3 in
> particular is handled by CoreAudio as of 10.3.

http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/C
lasses/NSSound_Class/Reference/Reference.html#//apple_ref/occ/instm/NSSou
nd/initWithContentsOfFile:byReference:

scroll back up to the class description and you'll see:
The NSSound class provides a simple interface for loading and playing
AIFF, WAV, and NeXT .snd files. NSSound supports 16-bit, mono and
stereo, 44.1KHz and 22.05KHz data.

this led me to believe that i needed something extra to play mp3 files.

>
>
> > > if([theMovieTypes indexOfObject:[theExtension uppercaseString] ==
> > > NSNotFound)
> >
> > this looks MUCH cleaner than mine... and i think i understand it as well
> > which is the important thing.
>
> Techniques like that especially come in handy when you find you have to
> update the list 6 months from now.


i've improved and simplified it a bit more. note, i tested out a simple
nsstring release and it crashed the thread. i also tested out nsmutable
setstring and it doesn't leak.

-(void)playsound
{
[(QTMovie *)[soundArray lastObject] play];
NSLog(@"Now playing sound", nil);
lastSoundIsPlaying = YES;
lastSoundIsValid = NO;
}

- (void)loadsound: (NSString *) inSoundName
{
isFinishedLoadingSound = NO;
lastSoundIsValid = NO;
NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init];
NSLog(@"locating sound --> %@",inSoundName);
NSString *theSoundPath = [self locateSound: inSoundName];
NSLog(@"located sound --> %@",theSoundPath);
id theSound = nil;
if([theSoundPath length] > 0)
{
theSound = [[NSSound alloc] initWithContentsOfFile: theSoundPath
byReference:YES];
[theSound autorelease];
NSLog(@"Now loaded sound --> %@", theSoundPath);
}
else
{
theSound = [NSSound soundNamed: inSoundName];
NSLog(@"Now loaded sound --> %@", inSoundName);
}
if(theSound)
{
[soundArray addObject: theSound];
lastSoundIsValid = YES;
lastSoundIsPlaying = NO;
}
else
{
[yasse_link echoTextToGameScreen: [NSString stringWithFormat:
@"Unable to locate the sound --> %@\n", inSoundName]];
}
isFinishedLoadingSound = YES;
[thePool release];
}

the next thing to do is to completely reqrite sound file locating, it
takes 2-3 seconds for my routine to locate a sound, i'm going to cut it
down to miliseconds.
Back to top
Login to vote
Dan Johnson

External


Since: Jan 25, 2007
Posts: 5



(Msg. 7) Posted: Thu Jan 25, 2007 6:20 am
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: comp>lang>objective-c, others (more info?)

"Santa Claus" <santa.TakeThisOut@northpole.com> wrote in message
news:santa-3BFF26.20344522012007@news.giganews.com...
> ok, i found out that all sounds MUST be played in the main thread for
> some reason so here's what i've done
>
> detatch a thread that scans for the sound file and then loads it into an
> array
>
> when that thread is finished, it sets a boolean value saying the sound
> has been loaded. i then play the sound loaded in the main thread if the
> boolean flag is set
>
> it seems to work for me ok but counting the threads, it shouldn't have
> more than one thread running while it's playing. i have 9 running now.
>
> is this something else i have to contend with locating?

[snip- source code]

Your source does not semm to include any threading
code at all; it does not create threads, destroy them,
or synchronize with them.

Your 9 threads might represent concurrent sound-readers
that you did not intend to start; or maybe you expect them
to shut down when done, but they deadlock instead.

Or perhaps something else.

From your description, it seems like you are trying to
use NSMutableArray as a synchronized queue, which
isn't safe without further synchronization. You need
@synchronized() blocks around all accesses to shared
state here, and some way to signal the main thread that
a sound is ready.

Remember that threads can't really share objects;
They can only take turns at them. And you'll get
better performance if you avoid doing even that,
since locking is expensive.

Instead, each thread should work in its own object
graph, and then transfer objects to another thread
when needed; data should be transfered rather than
shared.

Cocoa makes this pretty easy (for your case anyway):
transfer data to worker threads by passing it as
an argument to 'detachNewThread...'. The workers
then pass their results back to the main thread using
'performSelectorOnMainThread:...'.
Back to top
Login to vote
Gregory Weston

External


Since: Jun 06, 2005
Posts: 660



(Msg. 8) Posted: Thu Jan 25, 2007 7:14 am
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: comp>sys>mac>programmer>help (more info?)

In article <santa-4428F5.18174824012007.TakeThisOut@news.giganews.com>,
Santa Claus <santa.TakeThisOut@northpole.com> wrote:

> > Something funky with your system or data, then, since NSSound uses
> > QuickTime to support some of the data types it works with and MP3 in
> > particular is handled by CoreAudio as of 10.3.
>
> http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/C
> lasses/NSSound_Class/Reference/Reference.html#//apple_ref/occ/instm/NSSou
> nd/initWithContentsOfFile:byReference:
>
> scroll back up to the class description and you'll see:
> The NSSound class provides a simple interface for loading and playing
> AIFF, WAV, and NeXT .snd files. NSSound supports 16-bit, mono and
> stereo, 44.1KHz and 22.05KHz data.
>
> this led me to believe that i needed something extra to play mp3 files.

That needs to be updated, at least so it doesn't present the list as if
it's exhaustive. I'll file a report.

<http://developer.apple.com/qa/qa2001/qa1335.html>



> i've improved and simplified it a bit more. note, i tested out a simple
> nsstring release and it crashed the thread. i also tested out nsmutable
> setstring and it doesn't leak.

Without seeing the code and based on the way you've phrased that, I'm
guessing that you released something that came into your possession
autoreleased. And I don't believe I indicated that the setString method
was going to leak. (Checking...nope. Just asked why you were doing it.
Question was motiviated by interest in efficiency, not stability.)

>
> -(void)playsound
> {
> [(QTMovie *)[soundArray lastObject] play];

Why are you casting? Especially since the object may not be a QTMovie or
anything derived from it? (Wait; I've just read further...why are you
casting to QTMovie* when you're now never putting anything except
NSSounds in the array?)

> NSLog(@"Now playing sound", nil);

Why are you passing a second argument to NSLog without any format codes
in the string?

> lastSoundIsPlaying = YES;
> lastSoundIsValid = NO;
> }
>
> - (void)loadsound: (NSString *) inSoundName
> {
// This, to me, looks much better and more maintainable.
> }

G

--
The best intentions in the world don't make a flawed argument magically valid.
Back to top
Login to vote
Santa Claus

External


Since: Sep 24, 2005
Posts: 85



(Msg. 9) Posted: Thu Jan 25, 2007 9:25 pm
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <uce-D61BAB.07140325012007.DeleteThis@comcast.dca.giganews.com>,
Gregory Weston <uce.DeleteThis@splook.com> wrote:

> In article <santa-4428F5.18174824012007.DeleteThis@news.giganews.com>,
> Santa Claus <santa.DeleteThis@northpole.com> wrote:
>
> > > Something funky with your system or data, then, since NSSound uses
> > > QuickTime to support some of the data types it works with and MP3 in
> > > particular is handled by CoreAudio as of 10.3.
> >
> > http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/C
> > lasses/NSSound_Class/Reference/Reference.html#//apple_ref/occ/instm/NSSou
> > nd/initWithContentsOfFile:byReference:
> >
> > scroll back up to the class description and you'll see:
> > The NSSound class provides a simple interface for loading and playing
> > AIFF, WAV, and NeXT .snd files. NSSound supports 16-bit, mono and
> > stereo, 44.1KHz and 22.05KHz data.
> >
> > this led me to believe that i needed something extra to play mp3 files.
>
> That needs to be updated, at least so it doesn't present the list as if
> it's exhaustive. I'll file a report.
>
> <http://developer.apple.com/qa/qa2001/qa1335.html>
>
>
>
> > i've improved and simplified it a bit more. note, i tested out a simple
> > nsstring release and it crashed the thread. i also tested out nsmutable
> > setstring and it doesn't leak.
>
> Without seeing the code and based on the way you've phrased that, I'm
> guessing that you released something that came into your possession
> autoreleased. And I don't believe I indicated that the setString method
> was going to leak. (Checking...nope. Just asked why you were doing it.
> Question was motiviated by interest in efficiency, not stability.)

NSString *myString = [NSString stringWithString: someotherstring];
....
[myString release];
myString = @"";

crashes upon pool release...

NSMutableString *buildString = [[[NSMutableString alloc] init]
autorelease];
[buildString setString: @"sometext\n"];
[buildString appendString: @"moretext\n"];
......
[buildString setString: @"something else\n"];

doesn't leak...

REAL code here.
[pathToScript setString: [[fileLocationPrefix stringByAppendingString:
@"Sample Scripts/addcruc.txt"] stringByExpandingTildeInPath]];
if (![fileManager fileExistsAtPath: pathToScript]) //create if it's
not there
{
[scriptData setString: @"#addcruc: add items to the crucible\n"];
[scriptData appendString: @"\n"];
[scriptData appendString: @"put get my %1 %2\n"];
[scriptData appendString: @"waitfor you get\n"];
[scriptData appendString: @"put put my %1 %2 in cruc\n"];
[scriptData appendString: @"waitfor you put\n"];
ignore = [scriptData writeToFile: pathToScript atomically: YES];
}
[pathToScript setString: [[fileLocationPrefix stringByAppendingString:
@"Sample Scripts/buysupplies.txt"] stringByExpandingTildeInPath]];
if (![fileManager fileExistsAtPath: pathToScript]) //create if it's
not there
{
[scriptData setString: @"#buy supplies to make one steel ingot\n"];
[scriptData appendString: @"\n"];
[scriptData appendString: @"put buy tin slug\n"];
[scriptData appendString: @"waitfor the sales clerk hands you\n"];
....


>
> >
> > -(void)playsound
> > {
> > [(QTMovie *)[soundArray lastObject] play];
>
> Why are you casting? Especially since the object may not be a QTMovie or
> anything derived from it? (Wait; I've just read further...why are you
> casting to QTMovie* when you're now never putting anything except
> NSSounds in the array?)

actually, the compiler decided to provide warnings of multiple return
values for play. qtmovie has void and works, nssound has bool and
didn't work.
[(QTMovie *)[soundArray lastObject] play]; // works
myBoolVariable = [(NSSound *)[soundArray lastObject] play]; // doesn't
seem to work
[[soundArray lastObject] play]; // gives 3 warnings

>
> > NSLog(@"Now playing sound", nil);
>
> Why are you passing a second argument to NSLog without any format codes
> in the string?

the way i was told. you must have at least a nil there for nslog.

>
> > lastSoundIsPlaying = YES;
> > lastSoundIsValid = NO;
> > }
> >
> > - (void)loadsound: (NSString *) inSoundName
> > {
> // This, to me, looks much better and more maintainable.
> > }

you should see how the locater works now. it's so much better than it
used to be.
Back to top
Login to vote
Gregory Weston

External


Since: Jun 06, 2005
Posts: 660



(Msg. 10) Posted: Thu Jan 25, 2007 11:51 pm
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <santa-10BFB6.21255125012007.RemoveThis@news.giganews.com>,
Santa Claus <santa.RemoveThis@northpole.com> wrote:

> In article <uce-D61BAB.07140325012007.RemoveThis@comcast.dca.giganews.com>,
> Gregory Weston <uce.RemoveThis@splook.com> wrote:
>
> > Without seeing the code and based on the way you've phrased that, I'm
> > guessing that you released something that came into your possession
> > autoreleased. And I don't believe I indicated that the setString method
> > was going to leak. (Checking...nope. Just asked why you were doing it.
> > Question was motivated by interest in efficiency, not stability.)
>
> NSString *myString = [NSString stringWithString: someotherstring];
> ...
> [myString release];
> myString = @"";
>
> crashes upon pool release...

Yes, it would. You're doing exactly what I predicted; releasing
something that it's not your responsibility to release. As a general
guideline, you only have to release an object if you got it from an
alloc/init... pair or some method with "copy" in the name.

But of course the follow-up is that at least in the degenerate sample
above you didn't even really need the factory method stringWithString.
You could have just done a straight assignment. And if you had assigned
[someotherstring retain] you'd be golden (with your release line in
there). On the other hand, if your intent to make a new string based on
an existing one but then to manipulate it...


> NSMutableString *buildString = [[[NSMutableString alloc] init]
> autorelease];
> [buildString setString: @"sometext\n"];


I'd replaced the above lines with something like:

NSMutableString* buildString = [NSMutableString
stringWithString:@"sometext\n"];

Or at the very least I'd replace the first line with:

NSMutableString* buildString = [NSMutableString string];

> [buildString appendString: @"moretext\n"];
> .....
> [buildString setString: @"something else\n"];
>
> doesn't leak...

Correct. It doesn't. But I never said it would and then confirmed
(above) that I had never said it. But the fact that it merely doesn't
leak doesn't mean it's best practice.


> > > -(void)playsound
> > > {
> > > [(QTMovie *)[soundArray lastObject] play];
> >
> > Why are you casting? Especially since the object may not be a QTMovie or
> > anything derived from it? (Wait; I've just read further...why are you
> > casting to QTMovie* when you're now never putting anything except
> > NSSounds in the array?)
>
> actually, the compiler decided to provide warnings of multiple return
> values for play. qtmovie has void and works, nssound has bool and
> didn't work.

But if there's a discrepancy, and all you're ever putting in there is
NSSounds, then certainly it makes sense to treat them as NSSounds, yeah?


> [(QTMovie *)[soundArray lastObject] play]; // works
> myBoolVariable = [(NSSound *)[soundArray lastObject] play]; // doesn't
> seem to work

In what way?

> [[soundArray lastObject] play]; // gives 3 warnings

What warnings?

> > > NSLog(@"Now playing sound", nil);
> >
> > Why are you passing a second argument to NSLog without any format codes
> > in the string?
>
> the way i was told. you must have at least a nil there for nslog.

You were told wrong. If there are no format codes in the format string
it's at best superfluous to pass any additional arguments. (At worst
it's not really much worse than that since the caller is responsible for
cleaning up after the function call.)

G

--
The best intentions in the world don't make a flawed argument magically valid.
Back to top
Login to vote
Santa Claus

External


Since: Sep 24, 2005
Posts: 85



(Msg. 11) Posted: Fri Jan 26, 2007 7:35 am
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <uce-8CB362.23513225012007 DeleteThis @comcast.dca.giganews.com>,
Gregory Weston <uce DeleteThis @splook.com> wrote:

> > > > -(void)playsound
> > > > {
> > > > [(QTMovie *)[soundArray lastObject] play];
> > >
> > > Why are you casting? Especially since the object may not be a QTMovie or
> > > anything derived from it? (Wait; I've just read further...why are you
> > > casting to QTMovie* when you're now never putting anything except
> > > NSSounds in the array?)
> >
> > actually, the compiler decided to provide warnings of multiple return
> > values for play. qtmovie has void and works, nssound has bool and
> > didn't work.
>
> But if there's a discrepancy, and all you're ever putting in there is
> NSSounds, then certainly it makes sense to treat them as NSSounds, yeah?

actually, i'd prefer to NOT need qtkit.

>
>
> > [(QTMovie *)[soundArray lastObject] play]; // works
> > myBoolVariable = [(NSSound *)[soundArray lastObject] play]; // doesn't
> > seem to work
>
> In what way?

well, the first time i tried it, i heard nothing. now i tested it and i
heard the sounds.

>
> > [[soundArray lastObject] play]; // gives 3 warnings
>
> What warnings?

/Users/robertde/scriptomatic/ YASSE/playsound.m:259: warning: multiple
methods named '-play' found
/System/Library/Frameworks/AppKit.framework/Headers/NSSound.h:47:
warning: using '-(BOOL)play'
/System/Library/Frameworks/QTKit.framework/Headers/QTMovie.h:264:
warning: also found '-(void)play'

after careful consideration, i think i don't need to #include
<QTKit/QTKit.h>

i just ripped out the include and all the warnings went away. and
what's better, it works still.

lastSoundIsPlaying = [[soundArray lastObject] play];
lastSoundIsPlaying = YES;
lastSoundIsValid = NO;
Back to top
Login to vote
Santa Claus

External


Since: Sep 24, 2005
Posts: 85



(Msg. 12) Posted: Sat Jan 27, 2007 9:24 am
Post subject: Re: multi threading, not unloading threads [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <santa-CF0023.07351826012007.TakeThisOut@news.giganews.com>,
Santa Claus <santa.TakeThisOut@northpole.com> wrote:

> after careful consideration, i think i don't need to #include
> <QTKit/QTKit.h>
>
> i just ripped out the include and all the warnings went away. and
> what's better, it works still.
>
> lastSoundIsPlaying = [[soundArray lastObject] play];
> lastSoundIsPlaying = YES;
> lastSoundIsValid = NO;

blast it, i'm encountering errors where it wouldn't play a sound it was
playing just previously and also noticed later some errors.

2007-01-26 23:34:44.748 Avalon[9494] Now playing sound -->
/Users/robertde/Music/iTunes/iTunes Music/REO Speedwagon/The
Ballads/Time For Me To Fly.aif
Unsupported MP3 file
Unsupported MP3 file

odd that it's not a mp3 file. i quit the avalon program and rerun it
and it plays.

---

2007-01-27 08:45:14.136 Avalon[14748] Looking for sound --> keep on
loving you
2007-01-27 08:45:14.773 Avalon[14748] Now playing sound -->
/Users/robertde/Music/iTunes/iTunes Music/REO Speedwagon/Hi
Infidelity/Keep On Loving You.aif
Avalon(14748,0xa000ed88) malloc: *** vm_allocate(size=2147487744) failed
(error code=3)
Avalon(14748,0xa000ed88) malloc: *** error: can't allocate region
Avalon(14748,0xa000ed88) malloc: *** set a breakpoint in szone_error to
debug
Avalon(14748,0xa000ed88) malloc: *** error for object 0x96640f81:
Non-aligned pointer being freed
Avalon(14748,0xa000ed88) malloc: *** set a breakpoint in szone_error to
debug
2007-01-27 08:48:39.122 Avalon[14748] Looking for sound --> can't fight
this feeling

this time it actually played a song but issued these messges.

i see no reason it should issue these messages or suddenly not play a
sound it played 20 minutes ago.

----

source code:
-(void)playsound
{
lastSoundIsPlaying = [[soundArray lastObject] play];
lastSoundIsPlaying = YES;
lastSoundIsValid = NO;
}

- (void)loadsound: (NSString *) inSoundName
{
isFinishedLoadingSound = NO;
lastSoundIsValid = NO;
NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init];
BOOL listIsNotValid = NO;
NSLog(@"Looking for sound --> %@", inSoundName);
NSString *theSoundPath = [self locateSound: inSoundName];
id theSound = nil;
if([theSoundPath length] > 0)
{
theSound = [[NSSound alloc] initWithContentsOfFile: theSoundPath
byReference:YES];
if (!theSound)
{
listIsNotValid = YES;
}
[theSound autorelease];
NSLog(@"Now playing sound --> %@", theSoundPath);
}
else
{
theSound = [NSSound soundNamed: inSoundName];
NSLog(@"Now playing sound --> %@", inSoundName);
}
if(theSound)
{
[soundArray addObject: theSound];
lastSoundIsValid = YES;
lastSoundIsPlaying = NO;
}
else
{
if (listIsNotValid)
{
[self createSoundList];
BOOL listIsNotValid = NO;
NSLog(@"Looking again for sound --> %@", inSoundName);
theSoundPath = [self locateSound: inSoundName];
id theSound = nil;
if([theSoundPath length] > 0)
{
theSound = [[NSSound alloc] initWithContentsOfFile: theSoundPath
byReference:YES];
if (!theSound)
{
listIsNotValid = YES;
}
[theSound autorelease];
NSLog(@"Now playing sound --> %@", theSoundPath);
}
else
{
theSound = [NSSound soundNamed: inSoundName];
NSLog(@"Now playing sound --> %@", inSoundName);
}
if(theSound)
{
[soundArray addObject: theSound];
lastSoundIsValid = YES;
lastSoundIsPlaying = NO;
}
else
{
NSLog(@"Unable to play sound --> %@", inSoundName);
[yasse_link echoTextToGameScreen: [NSString stringWithFormat:
@"Unable to locate the sound --> %@\n", inSoundName]];
}
}
else
{
NSLog(@"Unable to play sound --> %@", inSoundName);
[yasse_link echoTextToGameScreen: [NSString stringWithFormat:
@"Unable to locate the sound --> %@\n", inSoundName]];
}
}
isFinishedLoadingSound = YES;
[thePool release];
}
-----
this is the code i've used for calling the routines in the main thread.

-(void)mySoundTimer
{
BOOL okToLoadAnotherSound = NO;
if (isFinishedLoadingSound)
{
if (lastSoundIsValid)
{
[soundStuff playsound];
}
okToLoadAnotherSound = YES;
}
if (okToLoadAnotherSound && isFinishedLoadingPlaysound)
{
if ([playlist count] > 0)
{
isFinishedLoadingSound = NO;
[NSThread detachNewThreadSelector: @selector(loadsound:) toTarget:
soundStuff withObject: [NSString stringWithString: [playlist
objectAtIndex: 0]]];
//[soundStuff loadsound: (NSString *)[playlist objectAtIndex: 0]];
[playlist removeObjectAtIndex: 0];
}
}
[soundStuff checkForSoundsEnded];
}


-----

you folks may not understand THIS code but it's the high level (user
level) script code i've used for the playlist. it may help you
understand what i'm trying to do.

//
// keep playing a set of iTunes songs starting at a certain song.
//
// this script is designed for Avalon with YASSE version 5.3.0 or better.
//

set trigger on

container 1 set [$soundsavailable$]

start:
// if the user entered a parameter, use that else use zero
if_1 goto setindex
counter clear
goto setsongs
setindex:
// ensure the parameter is not below zero
counter set %1
if_c < 0
begin
counter clear
end
setsongs:
setvariable songs 0
// build a playlist
// song 0
gosub addsong [unchained melody]
// song 1
gosub addsong [all i wanna do is make love to you]
// song 2
gosub addsong [magic man]
// song 3
gosub addsong [keep on loving you]
// song 4
gosub addsong [can't fight this feeling]
// song 5
gosub addsong [take it on the run]
// song 6
gosub addsong [time for me to fly]
// song 7
gosub addsong [unchained melody (orchestral)]
// ensure the parameter is not above the total in the playlist
if_c > $songs$
begin
counter clear
end

loop1:
// loop through all items in the playlist and playing then in sequence
pause
// don't play another sound until the all other sounds are finished.
if %isplayingsounds == 1
goto loop1
// go to the next sound in the array
counter inc
// play the sound
command -playsound $song%c$
// wait 5 seconds to allow for large sounds to load and begin playing
pause 5
if_c < $songs$
goto loop1
// list completed, start over from zero
counter clear
goto setsongs


addsong:
calculate songs inc
setvariable song$songs$ %w
return
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Carbon, threads, and windoww... - Hi, I'm porting a Win32 application to the Mac using C++ and the Carbon framework. The application must display a window in a non blocking way, i.e. when a specific object is constructed a window must pop up on the screen, display something until the..

Quark XTension, C/C++, CW 8.3: Threads - Hi I am developing a Quark XTension (CW 8.3, C/C++, Mach-O). Now I should create a thread in this XTension for TCP/IP-Communication via Socket. - How can I do that? - Can I use the method NewThread? - Or CFRunLoop? - Is any sample code available? ..

How to remove all submenu in hierachical multi-level menu .. - Something like [NSPopUpButton removeAllItems] (but for menu bar item) ? Or each submenu/item menu must be removed one each at time ? How do this ? Thank you.

How to type in ASCII? - Stupid question #2 of the week. I'm trying to avoid writing a printer driver for a barcode label printer. It responds to reasonable commands, and I want to embed a command in a page that tells the printer to cut the paper. It's <STX> o STX, of c...

applications and windows - Hello. I'm primarily a system programmer, unix one. Currently I have to implement the following logic: On Mac OS X enumerate all running application only those that are displaying windows. Find which of them is "active", where "active&qu...
       Mac (Home) -> Programmer Help All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
 Linux Forums
  Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact