I have been working on a feature to allow Routines and all types of PauseStreams to be rescheduled while playing (based on a discussion of a different issue). With it, you can call aThread.reschedule(clock, time)
and move the thread to a different clock, or a different time, or both.
Before I submit the PR, I need to write a unit test. I just tried one approach, but it isn’t correct – measuring the thread timing doesn’t work as I expected.
Issues of thread timing are, in my experience, the most difficult for unit testing. (I intend “difficult” as a euphemism here. I find the constraints, frankly, painful enough to be a disincentive to contribute.)
So I’m going to ask for advice. What would be the best way to test this feature? Code is mainly here, with some backend support.
Usage example:
c = TempoClock.new;
d = TempoClock(2); // run these at different times
(
t = Task {
loop {
[thisThread.beats, thisThread.seconds].postln;
1.0.wait;
};
}.play(c, quant: 1);
)
t.reschedule(d);
t.stop; c.stop; d.stop;
WIth output:
[ 22.0, 4128.605112713 ]
[ 23.0, 4129.605112713 ]
[ 24.0, 4130.605112713 ]
[ 25.0, 4131.605112713 ]
-> a Task
// here, the previous iteration asked to wait one beat,
// in the old tempo, before the next.
// That's one second, per c's tempo.
// So the next line shows d's beats at the next desired 'seconds' value.
[ 50.426778592, 4132.605112713 ]
[ 51.426778592, 4133.105112713 ]
[ 52.426778592, 4133.605112713 ]
[ 53.426778592, 4134.105112713 ]
[ 54.426778592, 4134.605112713 ]
hjh