How can I determine if a Pbind of finite length inside a Pdef has ended?
(
x = Pbind(\dur, Pseq([1]));
y = x.play;
y.isPlaying; // true
)
// wait 1 second
y.isPlaying; // false
(
Pdef(\test, Pbind(\dur, Pseq([1]))).play;
Pdef(\test).isPlaying; // true
)
// wait 1 second
Pdef(\test).isPlaying; // still true, how can I determine if the Pbind inside the Pdef has ended?
Pdef(\test).player.isPlaying
accesses the Pdef
’s EventStreamPlayer
and asks if it is still playing. Pdef(\test).isActive
returns true if both the EventStreamPlayer
’s stream has not ended yet and the Pdef
itself is playing.
Pdef(\test).isPlaying
by itself isn’t enough because it refers to the status of the Pdef
itself, not the EventStreamPlayer
that actually plays the enclosed Pbind
.
x = Pbind(\dur, Pseq([1]));
y = x.play;
y.class; // -> EventStreamPlayer
Pdef(\test, Pbind(\dur, Pseq([1]))).play;
Pdef(\test).player.class; // -> EventStreamPlayer
Pdef.findRespondingMethodFor('isActive'); // -> TaskProxy:isActive
TaskProxy : PatternProxy {
...
isPlaying { ^player.notNil and: { player.wasStopped.not } } // does not check if enclosed stream has ended
isActive { ^this.isPlaying and: { player.streamHasEnded.not } }
...
}
Also try… Pdef(\test).isActive;
A Pdef
is always “playing” after you .play
it, until you call .stop
or Cmd-period (and possibly some other methods that I’m not thinking of at the moment). The always-playing state is necessary so that when you give it a new source pattern, it will automatically start playing it at the next quant interval. The .isActive
method is a way to see if the source is still playing.
1 Like
Thanks @PitchTrebler and @bovil43810 - .isActive is what I needed!