Hello,
I would like to propose the addition of method "update" for the
Function class as follows:
update { arg theChanged, theChanger;
^this.value(theChanged, theChanger);
}
This makes it possible to add a Function directly as dependant to
any Object. This has the effect of radically generalizing and
simplifying the usage of the Observer pattern: A Function can act
as simple and direct "Adapter" to react to a change happening in
any object that wishes to notify its dependants with:
this.changed(whatChanged, this)
One of the many uses I have found for this is for example the
ability to add functions to execute when a Server starts or quits,
or when any Node or EventStreamPlayer ends (code attached). It is
part of a small reliable scheme for broadcasting any changes in the
run state of Nodes and EventStreamPlayers with any object that
might need to be notification.
If this could be included in 3.2 then I would like to document it
in the upcoming sc-book.
Iannis Zannos
======================================================================
=
onEnd { | argFunc |
var cmdPeriodFunc;
NodeWatcher.register(this);
// this is needed to add this to catch synths stopped by
Command-Period:
cmdPeriodFunc = {
NodeWatcher.unregister(this);
CmdPeriod.remove(cmdPeriodFunc);
argFunc.value;
};
CmdPeriod.add(cmdPeriodFunc);
// This evaluates argFunc when notified by NodeWatcher
this.addDependant { | me, whatHappened |
if (whatHappened == \n_end) {
argFunc.(this);
this.removeDependant(argFunc);
// see CmdPeriod above
CmdPeriod.remove (cmdPeriodFunc);
}
};
}
}
+ EventStreamPlayer {
onEnd { | argFunc |
this.addDependant { | me, whatHappened |
if (whatHappened == \stopped) {
argFunc.(this);
this.removeDependant(argFunc);
}
}
}
_______________________________________________
Sc-devel mailing list
Sc-devel@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-devel