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

Re: [sc-users] routine buildup



Found the bug, so here's the class.

There's one small change. When you stop the better task, the stream variable will still be nil (so myTask.isPlaying will be false, which is the same as task), BUT nextBeat will still hold the next time on the scheduler. (Task sets that variable to nil at the time of stopping.)

Thinking it over further, I think that's a bug in PauseStream's handling of nextBeat. If the object is still on the scheduler, nextBeat should hold the time. It should only become nil when the scheduler fires and sees that the object's stream has become nil. Currently there is no way for a PauseStream to know if it's still scheduled, which seems a problem.

Okay to integrate these changes into PauseStream?

Test case:
<x-tad-smaller>
t = </x-tad-smaller><x-tad-smaller>BetterTask</x-tad-smaller><x-tad-smaller>({
</x-tad-smaller><x-tad-smaller>var</x-tad-smaller><x-tad-smaller> x = 0;
</x-tad-smaller><x-tad-smaller>"reset"</x-tad-smaller><x-tad-smaller>.debug;
loop {
</x-tad-smaller><x-tad-smaller>thisThread</x-tad-smaller><x-tad-smaller>.clock.beats.debug(x);
x = x + 1;
1.0.wait;
}
});

t.play;

t.stop; t.reset; t.play;

// when playing
t.stop; t.play; // this would not work before

// when stopped
t.play; t.play; t.play; // this already worked</x-tad-smaller>


Class def:
<x-tad-smaller>
</x-tad-smaller><x-tad-smaller>BetterTask</x-tad-smaller><x-tad-smaller> : </x-tad-smaller><x-tad-smaller>Task</x-tad-smaller><x-tad-smaller> {
</x-tad-smaller><x-tad-smaller>var</x-tad-smaller><x-tad-smaller> <isWaiting = </x-tad-smaller><x-tad-smaller>false</x-tad-smaller><x-tad-smaller>;

play { </x-tad-smaller><x-tad-smaller>arg</x-tad-smaller><x-tad-smaller> argClock, doReset = (</x-tad-smaller><x-tad-smaller>false</x-tad-smaller><x-tad-smaller>), quant=0.0;
if (stream.notNil, { </x-tad-smaller><x-tad-smaller>"already playing"</x-tad-smaller><x-tad-smaller>.postln; ^</x-tad-smaller><x-tad-smaller>this</x-tad-smaller><x-tad-smaller> });
if (doReset, { </x-tad-smaller><x-tad-smaller>this</x-tad-smaller><x-tad-smaller>.reset });
clock = argClock ? clock ? </x-tad-smaller><x-tad-smaller>TempoClock</x-tad-smaller><x-tad-smaller>.default;
streamHasEnded = </x-tad-smaller><x-tad-smaller>false</x-tad-smaller><x-tad-smaller>;
stream = originalStream;
isWaiting = </x-tad-smaller><x-tad-smaller>true</x-tad-smaller><x-tad-smaller>;
clock.play({
if(isWaiting and: { nextBeat.isNil }) {
clock.sched(0, </x-tad-smaller><x-tad-smaller>this</x-tad-smaller><x-tad-smaller>);
isWaiting = </x-tad-smaller><x-tad-smaller>false</x-tad-smaller><x-tad-smaller>;
};
</x-tad-smaller><x-tad-smaller>nil</x-tad-smaller><x-tad-smaller>
}, quant);
^</x-tad-smaller><x-tad-smaller>this</x-tad-smaller><x-tad-smaller>
}

stop {
stream = </x-tad-smaller><x-tad-smaller>nil</x-tad-smaller><x-tad-smaller>;
isWaiting = </x-tad-smaller><x-tad-smaller>false</x-tad-smaller><x-tad-smaller>;
}

pause { </x-tad-smaller><x-tad-smaller>this</x-tad-smaller><x-tad-smaller>.stop }
}

</x-tad-smaller>
hjh

: 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