I’m trying to create a queue of Pbinds that will be triggered one after the other - so when (if) one finishes it will send a message that will start the next (if there is one)
Whether or not that’s a good idea - I’m trying to figure out how to use the depandants/changed/update features of Object - and I can’t find any examples.
I’m familiar with the pub/sub pattern in other languages, but SC’s implementation is eluding me. Are there any examples?
To @semiquaver’s point - I’m not sure I understand your objective, as the Pseq will play each Pbind through in series, and once a Pbind is finished, it will give control back to the Pseq, which will select the next Pbind, or finish playing.
I’m already using Pdefs (actually EventPatternProxy),and these are definitely interesting ideas - condition was new to me, and there are always lots of ways to do things in SuperCollider.
But over and above the way to solve this specific problem, I’d really like to understand how to use SC’s pub/sub. It’s a powerful pattern and it has wide application.
p = Pbind(\degree, Pseries(0, 1, 8), \dur, 0.5);
(
var watcher;
q = p.play; // an EventStreamPlayer
// q, not p, because you're watching the *player* (not the pattern)
watcher = SimpleController(q)
.put(\stopped, {
watcher.remove; // mandatory cleanup
"here is where you'd do whatever you need".postln;
});
)
right!
Object takes care of maintaining a Dictionary of IdentitySets - so any objects that use pub/sub can maintain a list, without every single object having the overhead - so far so reasonable, but update does nothing!
update { arg theChanged, theChanger; // respond to a change in a model
}
are you supposed to override this? is it only usable in classes implement their own override?
It’s not really documented but yes, I believe that the idea is that you implement “update” for your own classes. At least, that’s how I’ve been using it.
Update is used if you want to implement your own subscriber. It is called on each of the object’s dependents, not on the object itself. When you are using something like SimpleController - that simple controller gets added to the object’s dependants and update is being called on the SimpleController instance (and update is implemented for SimpleController).
update is an example of a “protocol” – a set of messages that are expected to behave consistently over a wide range of objects.
It’s quite common for a widespread protocol to implement no-op methods at the top level (see also Object:stop – you wouldn’t see stop {} and assume that stop is somehow undefined or meaningless elsewhere).
The meaning of this is, “objects may safely ignore this message without throwing an error.”
Object:update isn’t the ultimate destination of this message. E.g., SimpleController:update does use the arguments.