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

Re: [Sc-devel] update method for Functions




Hello sciss,
I was aware of arg ... args option and I was debating with myself about it. The reason for the other form is that it copies the generic method of Object:update. But actually I agree with you. Lets be bold and go for the general form.

Iannis Zannos

On Dec 23, 2007 6:39 PM, Sciss <contact@xxxxxxxx> wrote:
i second that. !but! could we please use the general form of Updater,
so that it becomes:

       update { arg ... args;
               this.valueArray( args );
       }

this way we don't limit the usage to two arguments. To give an example:

m = Object.new;
m.addDependant({ arg obj, what, x, y; [ obj, what, x, y ].postln });
m.changed( \move, 11, 22 );

ciao, -sciss-



Am 23.12.2007 um 17:27 schrieb Iannis Zannos:

>
> 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

_______________________________________________
Sc-devel mailing list
Sc-devel@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-devel