diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2006-03-09 14:34:33 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2006-03-09 14:34:33 +0000 |
commit | 450b54a7c21f1e7fa98249fe6b3ac4c98966f163 (patch) | |
tree | cf8cc4abbe85bc0285f957472cd5d59c5d0a9a3e /Counter | |
parent | 16aa9b1f769721380ce6dca3e52fa65bf92e84ad (diff) |
adapted to PD version 0.40
better handler flexibility and argument checking
added Zmolnigs counter example
svn path=/trunk/externals/clr/; revision=4663
Diffstat (limited to 'Counter')
-rwxr-xr-x | Counter/Counter.cs | 130 | ||||
-rw-r--r-- | Counter/counter-help.pd | 24 |
2 files changed, 75 insertions, 79 deletions
diff --git a/Counter/Counter.cs b/Counter/Counter.cs index 4cd1564..416cb3b 100755 --- a/Counter/Counter.cs +++ b/Counter/Counter.cs @@ -6,104 +6,76 @@ using System; public class Counter: PureData.External { - PureData.Atom[] args; - - float farg; + int i_count,i_down,i_up; + float step; 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.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 - // returns void or ClassType - private static ClassType Setup(Counter obj) + private static void 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; + 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 virtual void MyBang() - { - Post("Count-BANG "+farg.ToString()); - Outlet(0); - } - - protected virtual void MyFloat(float f) - { - Post("Count-FLOAT "+f.ToString()); + 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 virtual void MyFloat1(float f) - { - Post("Count-FLOAT1 "+f.ToString()); - } - - protected virtual void MyAny1(int ix,PureData.Symbol s,PureData.AtomList l) + protected void Reset() { - Post(ix.ToString()+": Count-ANY1 "+l.ToString()); + this.i_count = this.i_down; } - protected virtual void MySymbol(PureData.Symbol s) + protected void Set(float f) { - Post("Count-SYMBOL "+s.ToString()); - Outlet(0,s); + this.i_count = (int)f; } - protected virtual void MyList(PureData.AtomList l) + protected void Bound(PureData.AtomList args) { - Post("Count-LIST "+l.ToString()); - Outlet(0,l); + 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); } - 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)); - } - -*/ } diff --git a/Counter/counter-help.pd b/Counter/counter-help.pd new file mode 100644 index 0000000..7648acc --- /dev/null +++ b/Counter/counter-help.pd @@ -0,0 +1,24 @@ +#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; |