William, I want the sound to stop when I press the "Stop Sound" button in the window. I followed (what I think was) your suggestion, moving the function containing the pieceDone function to the main thread, but that doesn't solve my problem.
When I press the "Stop" button, my calls to NSLog tell me: 2008-04-04 19:20:05.890 AttonalComposer[1178:10b] stopButtonAction invoked 2008-04-04 19:20:05.892 AttonalComposer[1178:10b] pieceDone invoked
When I press the "Play Sine" button, my calls to NSLog tell me: 2008-04-04 19:16:42.838 AttonalComposer[1173:10b] playSineButtonAction invoked 2008-04-04 19:16:42.840 AttonalComposer[1173:10b] playSine called 2008-04-04 19:16:43.006 AttonalComposer[1173:b903] playSineLoop. start
and the 440 "A" begins to sound. But if I THEN press the "Stop" button, my calls to NSLog tell me (by omission) that neither stopButtonAction nor pieceDone is invoked.
Question: Why does pressing "Stop" invoke the functions before I do anything else, but when the second thread is running, pressing "Stop" doesn't do anything?
This Sine business is just a test. When my program is doing its real stuff, playing a piece of music, I want to be able to stop it manually rather than having it time out. ------------------------------------------------------ William, you said: That CFRun loop call is pretty unusual and mainly an artifact of the demo program being a single, interface-less command-line main. Without the delay, the sound would cut off when the main exited. Usually you run start and stop a sound from your main program loop, which has a window with buttons, etc. To run a sound 2 seconds, a simple way is to: create a structure (call the pointer to it _p_) that holds the necessary audio variables; start the sound; and then set an EventTimerLoop to fire in two seconds and pass p as the userData paramenter to the event fire proc, when can then turn off the sound using the p->whatever paremeters. There are other ways but that's simplest, I think. |