using System; /// /// Descrizione di riepilogo per Counter. /// public class Counter: PureData.External { int i_count,i_down,i_up; float step; public Counter(PureData.AtomList args) { this.step = args.Count >= 3?(float)args[2]:1; float f2 = args.Count >= 2?(float)args[1]:0; float f1 = args.Count >= 1?(float)args[0]:0; if(args.Count < 2) f2 = f1; this.i_down = (int)((f1f2)?f1:f2); this.i_count = this.i_down; AddInlet(_list,new PureData.Symbol("bound")); AddInlet(ref step); AddOutlet(_float); AddOutlet(_bang); } // this function MUST exist private static void Setup(Counter obj) { AddMethod(0,new Method(obj.Bang)); AddMethod(0,"reset",new Method(obj.Reset)); AddMethod(0,"set",new MethodFloat(obj.Set)); AddMethod(0,"bound",new MethodList(obj.Bound)); } protected void Bang() { float f = this.i_count; int step = (int)this.step; this.i_count += step; if(this.i_down-this.i_up != 0) { if(step > 0 && this.i_count > this.i_up) { this.i_count = this.i_down; Outlet(1); } else if(this.i_count < this.i_down) { this.i_count = this.i_up; Outlet(1); } } Outlet(0,f); } protected void Reset() { this.i_count = this.i_down; } protected void Set(float f) { this.i_count = (int)f; } protected void Bound(PureData.AtomList args) { float f1 = (float)args[0]; float f2 = (float)args[1]; this.i_down = (int)((f1f2)?f1:f2); } }