[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sc-devel] add change notification when EventStreamPlayer stops




On Dec 27, 2007, at 8:10 AM, ronald kuivila wrote:
Hi Iani,

 I did an update and commit on Streams.sc last night.  I did not see the notification code. If you are waiting to commit, pleaase go ahead!

RJK

Here's my suggestion, open to revision. It's more flexible because it gives dependents the choice whether they are interested in play and stop requests from the user, or when those requests actually take effect in the scheduler, or both. So, this approach would send four notification types:

\waitingToPlay: user requested play, but the thread hasn't started physically yet

\play: thread started running on the clock

\waitingToStop: user requested stop, but the thread still is active in the scheduler and won't completely stop until it wakes up and finds that the stream variable is nil

\stop: the thread is completely inactive and removed from the scheduler (this includes when the stream terminates on its own)

One other thing to watch out for is that you're not actually monitoring the pattern's state. Patterns don't play; they manufacture another object which does. In the GUI scenario Iannis mentioned, you would not be able to add a dependent to the pattern and then repeatedly play it, because you get a new event stream player every time you do aPattern.play -- so you have to watch a different model every time.

hjh


Index: Stream.sc
===================================================================
--- Stream.sc   (revision 6840)
+++ Stream.sc   (working copy)
@@ -348,17 +348,20 @@
                        if(isWaiting and: { nextBeat.isNil }) {
                                clock.sched(0, this);
                                isWaiting = false;
+                               this.changed(\play);
                        };
                        nil
                }, quant);
+               this.changed(\waitingToPlay);
                ^this
        }
        reset { ^originalStream.reset }
-       stop {
+       stop { |notify = true|
                stream = nil;
                isWaiting = false;
+               if(notify) { this.changed(\stop, \waitingToStop) };
        }
-       removedFromScheduler { nextBeat = nil; this.stop }
+       removedFromScheduler { nextBeat = nil; this.stop(false) }
        streamError { stream = nextBeat = nil;  streamHasEnded = true; isWaiting = false; }
 
        wasStopped { 
@@ -367,8 +370,9 @@
        }
 
        pause {
-               stream = nil;
-               isWaiting = false;
+               this.stop;
+//             stream = nil;
+//             isWaiting = false;
        }
        resume { arg argClock, quant=1.0; 
                ^this.play(clock ? argClock, false, quant) 
@@ -387,8 +391,12 @@
 
        next { arg inval; 
                var nextTime = stream.next(inval);
-               if (nextTime.isNil) { streamHasEnded = stream.notNil; stream = nextBeat = nil }
-                       { nextBeat = inval + nextTime };        // inval is current logical beat
+               if (nextTime.isNil) {
+                       streamHasEnded = stream.notNil;
+                       stream = nextBeat = nil;
+                       this.changed(\stop);
+               }
+               { nextBeat = inval + nextTime };        // inval is current logical beat
                ^nextTime
        }
        awake { arg beats, seconds, inClock;
@@ -418,8 +426,11 @@
                ^super.new(stream).event_(event ? Event.default).cleanup_(EventStreamCleanup.new);
        }
 
-       stop { stream = nextBeat = nil; isWaiting = false; 
-               cleanup.terminate
+       stop { |notify = true|
+               stream = nextBeat = nil;
+               isWaiting = false; 
+               cleanup.terminate;
+               if(notify) { this.changed(\waitingToStop) };
         }
 
        mute { muteCount = muteCount + 1; }
@@ -431,7 +442,8 @@
                if (outEvent.isNil) {
                        streamHasEnded = stream.notNil;
                        cleanup.clear;
-                       this.stop;
+                       this.stop(false);
+                       this.changed(\stop);
                        ^nil
                }{
                        outEvent = cleanup.update(outEvent);
@@ -446,7 +458,7 @@
 
        asEventStreamPlayer { ^this }
 
-               play { arg argClock, doReset = (false), quant=0.0, phase = 0, offset = 0;
+       play { arg argClock, doReset = (false), quant=0.0, phase = 0, offset = 0;
                if (stream.notNil, { "already playing".postln; ^this });
                if (doReset, { this.reset });
                clock = argClock ? clock ? TempoClock.default;
@@ -466,9 +478,11 @@
                        if(isWaiting and: { nextBeat.isNil }) {
                                clock.sched(0, this);
                                isWaiting = false;
+                               this.changed(\play);
                        };
                        nil
                }, [quant, phase - offset]);
+               this.changed(\waitingToPlay);
                ^this
        }


: H. James Harkins

: jamshark70@xxxxxxxxxxxxxxxxx

: http://www.dewdrop-world.net

.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:


"Come said the Muse,

Sing me a song no poet has yet chanted,

Sing me the universal."  -- Whitman