Update of /cvsroot/pure-data/externals/clr/Counter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22039/clr/Counter
Modified Files: Counter.cs Added Files: counter-help.pd Log Message: adapted to PD version 0.40 better handler flexibility and argument checking added Zmölnigs counter example
--- NEW FILE: counter-help.pd --- #N canvas 0 0 458 308 12; #X obj 233 204 Counter; #X msg 306 91 2 7; #X floatatom 372 91 5 0 0 0 - - -; #X obj 284 241 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X floatatom 226 240 5 0 0 0 - - -; #X floatatom 90 55 5 0 0 0 - - -; #X msg 17 113 reset; #X obj 19 68 bng 25 250 50 0 empty empty empty 0 -6 0 8 -258699 -1 -1; #X text 296 70 bounds; #X msg 164 80 bound 0 4; #X text 376 72 step; #X msg 90 79 set $1; #X connect 0 0 4 0; #X connect 0 1 3 0; #X connect 1 0 0 1; #X connect 2 0 0 2; #X connect 5 0 11 0; #X connect 6 0 0 0; #X connect 7 0 0 0; #X connect 9 0 0 0; #X connect 11 0 0 0;
Index: Counter.cs =================================================================== RCS file: /cvsroot/pure-data/externals/clr/Counter/Counter.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Counter.cs 9 Mar 2006 01:48:21 -0000 1.5 --- Counter.cs 9 Mar 2006 14:34:33 -0000 1.6 *************** *** 7,109 **** PureData.External { ! PureData.Atom[] args; ! ! float farg;
public Counter(PureData.AtomList args) { ! Post("Count.ctor "+args.ToString());
! // that's the way to store args (don't just copy an AtomList instance!!) ! this.args = (PureData.Atom[])args;
! // AddInlet(s_list,new PureData.Symbol("list2")); ! AddInlet(); ! AddInlet(ref farg); ! AddInlet(); ! AddOutletBang(); }
// this function MUST exist ! // returns void or ClassType ! private static ClassType Setup(Counter obj) { ! AddMethod(0,new MethodBang(obj.MyBang)); ! AddMethod(0,new MethodFloat(obj.MyFloat)); ! AddMethod(0,new MethodSymbol(obj.MySymbol)); ! AddMethod(0,new MethodList(obj.MyList)); ! AddMethod(0,"set",new MethodAnything(obj.MySet)); ! AddMethod(0,"send",new MethodAnything(obj.MySend)); ! AddMethod(0,new MethodAnything(obj.MyAnything)); ! AddMethod(1,new MethodFloat(obj.MyFloat1)); ! AddMethod(1,new MethodAnything(obj.MyAny1)); ! ! Post("Count.Main"); ! return ClassType.Default; }
! protected virtual void MyBang() ! { ! Post("Count-BANG "+farg.ToString()); ! Outlet(0); ! } ! ! protected virtual void MyFloat(float f) ! { ! Post("Count-FLOAT "+f.ToString()); Outlet(0,f); }
! protected virtual void MyFloat1(float f) ! { ! Post("Count-FLOAT1 "+f.ToString()); ! } ! ! protected virtual void MyAny1(int ix,PureData.Symbol s,PureData.AtomList l) ! { ! Post(ix.ToString()+": Count-ANY1 "+l.ToString()); ! } ! ! protected virtual void MySymbol(PureData.Symbol s) ! { ! Post("Count-SYMBOL "+s.ToString()); ! Outlet(0,s); ! } ! ! protected virtual void MyList(PureData.AtomList l) ! { ! Post("Count-LIST "+l.ToString()); ! Outlet(0,l); ! } ! ! protected virtual void MySet(int ix,PureData.Symbol s,PureData.AtomList l) { ! Post("Count-SET "+l.ToString()); ! Outlet(0,new PureData.Symbol("set"),l); }
! protected virtual void MySend(int ix,PureData.Symbol s,PureData.AtomList l) { ! Send(new PureData.Symbol("receiver"),l); ! Send(new PureData.Symbol("receiver2"),(PureData.Atom[])l); }
! protected virtual void MyAnything(int ix,PureData.Symbol s,PureData.AtomList l) { ! Post(ix.ToString()+": Count-("+s.ToString()+") "+l.ToString()); ! Outlet(0,s,l); } - /* - public void SendOut() - { - pd.SendToOutlet(x, 0, new Atom(curr)); - }
- public void Sum(float f) - { - curr += (int) f; - pd.SendToOutlet(x, 0, new Atom(curr)); - } - - */ } --- 7,81 ---- 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)((f1<f2)?f1:f2); ! this.i_up = (int)((f1>f2)?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)((f1<f2)?f1:f2); ! this.i_up = (int)((f1>f2)?f1:f2); }
}