aboutsummaryrefslogtreecommitdiff
path: root/Counter/Counter.cs
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2006-03-09 14:34:33 +0000
committerThomas Grill <xovo@users.sourceforge.net>2006-03-09 14:34:33 +0000
commit450b54a7c21f1e7fa98249fe6b3ac4c98966f163 (patch)
treecf8cc4abbe85bc0285f957472cd5d59c5d0a9a3e /Counter/Counter.cs
parent16aa9b1f769721380ce6dca3e52fa65bf92e84ad (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/Counter.cs')
-rwxr-xr-xCounter/Counter.cs130
1 files changed, 51 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));
- }
-
-*/
}