[Gridflow-cvs] [svn] commit: r6102 - in /trunk/src: classes2.cxx classes_gui.cxx gridflow.cxx gridflow.hxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Sat Aug 14 20:41:38 EDT 2010


Author: matju
Date: Sat Aug 14 20:41:38 2010
New Revision: 6102

Log:
\decl void anything (...) now takes two special args: argv[0] = which inlet; argv[1] = which selector; argv+2 : real args start here; argc is two more than the number of args in the message.

Modified:
    trunk/src/classes2.cxx
    trunk/src/classes_gui.cxx
    trunk/src/gridflow.cxx
    trunk/src/gridflow.hxx

Modified: trunk/src/classes2.cxx
==============================================================================
--- trunk/src/classes2.cxx (original)
+++ trunk/src/classes2.cxx Sat Aug 14 20:41:38 2010
@@ -144,7 +144,7 @@
 			if (v->a_type==A_LIST) {
 				t_binbuf *b = *v;
 				out[i](binbuf_getnatom(b),binbuf_getvec(b));
-			} else if (v->a_type==A_SYMBOL) out[i](v);
+			} else if (v->a_type==A_SYMBOL) out[i](*v);
 			else outlet_anything2(out[i],1,v);
 		}
 	}
@@ -221,9 +221,9 @@
 	}
 	\decl 0 remove (t_symbol *s=0) {if (s) table.erase(s); else table.clear();}
 	\decl void anything (...) {
-		t_symbol *sel = argv[0]; sel = gensym(sel->s_name+3);
+		t_symbol *sel = argv[1];
 		table[sel].clear();
-		for (int i=1; i<argc; i++) table[sel].push_back(argv[i]);
+		for (int i=2; i<argc; i++) table[sel].push_back(argv[i]);
 	}
 };
 \end class {install("attr",1,1);}
@@ -261,37 +261,27 @@
 };
 \end class {install("listflatten",1,1);}
 
-// does not do recursive comparison of lists.
-static bool atom_eq (const t_atom2 &a, const t_atom2 &b) {
-	if (a.a_type!=b.a_type) return false;
-	if (a.a_type==A_FLOAT)   return a.a_float   ==b.a_float;
-	if (a.a_type==A_SYMBOL)  return a.a_symbol  ==b.a_symbol;
-	if (a.a_type==A_POINTER) return a.a_gpointer==b.a_gpointer;
-	if (a.a_type==A_LIST)    return a.a_gpointer==b.a_gpointer;
-	RAISE("don't know how to compare elements of type %d",a.a_type);
-}
-
 \class ListFind : FObject {
 	int ac;
-	t_atom *at;
+	t_atom2 *at;
 	~ListFind() {if (at) delete[] at;}
 	\constructor (...) {ac=0; at=0; _1_list(argc,argv);}
 	\decl 0 list(...) {if (argc<1) RAISE("empty input"); else find(*argv);}
 	\decl 1 list(...) {
 		if (at) delete[] at;
 		ac = argc;
-		at = new t_atom[argc];
+		at = new t_atom2[argc];
 		for (int i=0; i<argc; i++) at[i] = argv[i];
 	}
 	\decl 0 float (t_atom2 a) {find(a);}
 	\decl 0 symbol(t_atom2 a) {find(a);}
-	void find (const t_atom2 &a) {int i=0; for (; i<ac; i++) if (atom_eq(at[i],a)) break; out[0](i==ac?-1:i);}
+	void find (const t_atom2 &a) {int i=0; for (; i<ac; i++) if (at[i]==a) break; out[0](i==ac?-1:i);}
 };
 \end class {install("listfind",2,1);}
 
 \class ListRead : FObject { /* sounds like tabread */
 	int ac;
-	t_atom *at;
+	t_atom2 *at;
 	~ListRead() {if (at) delete[] at;}
 	\constructor (...) {ac=0; at=0; _1_list(argc,argv);}
 	\decl 0 float(float f) {
@@ -303,7 +293,7 @@
 	\decl 1 list(...) {
 		if (at) delete[] at;
 		ac = argc;
-		at = new t_atom[argc];
+		at = new t_atom2[argc];
 		for (int i=0; i<argc; i++) at[i] = argv[i];
 	}
 };
@@ -362,14 +352,12 @@
 	\decl void anything (...) {
 		ostringstream text;
 		text << prefix << ":";
-		t_symbol *l = gensym("_0_list");
-		t_symbol *f = gensym("_0_float");
-		if      (argv[0]==f && argc==2 && argv[1].a_type==A_FLOAT  ) {/* don't show the selector. */}
-		else if (argv[0]==l && argc>=2 && argv[1].a_type==A_FLOAT  ) {/* don't show the selector. */}
-		else if (argv[0]==l && argc==2 && argv[1].a_type==A_SYMBOL ) {text << " symbol" ;}
-		else if (argv[0]==l && argc==2 && argv[1].a_type==A_POINTER) {text << " pointer";}
-		else if (argv[0]==l && argc==1) {text << " bang";}
-		else {text << " " << argv[0].a_symbol->s_name+3; /* as is */}
+		if      (argv[1]==&s_float && argc==3 && argv[2].a_type==A_FLOAT  ) {/* don't show the selector. */}
+		else if (argv[1]==&s_list  && argc>=3 && argv[2].a_type==A_FLOAT  ) {/* don't show the selector. */}
+		else if (argv[1]==&s_list  && argc==3 && argv[2].a_type==A_SYMBOL ) {text << " symbol" ;}
+		else if (argv[1]==&s_list  && argc==3 && argv[2].a_type==A_POINTER) {text << " pointer";}
+		else if (argv[1]==&s_list  && argc==2) {text << " bang";}
+		else {text << " " << argv[1];}
 		for (int i=1; i<argc; i++) {text << " " << argv[i];}
 		post("%s",text.str().data());
 	}
@@ -484,9 +472,9 @@
 	~Route2() {if (sels) delete[] sels;}
 	\constructor (...) {nsels=0; sels=0; _1_list(argc,argv); noutlets_set(1+nsels);}
 	\decl void anything(...) {
-		t_symbol *sel = argv[0]; sel = gensym(sel->s_name+3);
+		t_symbol *sel = argv[1];
 		int i=0; for (i=0; i<nsels; i++) if (sel==sels[i]) break;
-		out[i](sel,argc-1,argv+1);
+		out[i](sel,argc-2,argv+2);
 	}
 	\decl 1 list(...) { // in the future, this could be a one-liner, right ?
 		for (int i=0; i<argc; i++) if (argv[i].a_type!=A_SYMBOL) {delete[] sels; RAISE("$%d: expected symbol",i+1);}
@@ -502,10 +490,10 @@
 	~Route3() {if (sels) delete[] sels;}
 	\constructor (...) {nsels=0; sels=0; _1_list(argc,argv); noutlets_set(1+nsels);}
 	\decl void anything(...) {
-		t_symbol *sel = argv[0]; sel = gensym(sel->s_name+3);
+		t_symbol *sel = argv[1];
 		int i=0; for (i=0; i<nsels; i++) if (sel==sels[i]) break;
-		if (sel!=&s_bang && sel!=&s_float && sel!=&s_symbol && sel!=&s_pointer) sel=&s_list;
-		out[i](sel,argc-1,argv+1);
+		if (sel!=&s_bang && sel!=&s_float && sel!=&s_symbol && sel!=&s_pointer) sel=&s_list; // what about grid,blob ?
+		out[i](sel,argc-2,argv+2);
 	}
 	\decl 1 list(...) {
 		for (int i=0; i<argc; i++) if (argv[i].a_type!=A_SYMBOL) {delete[] sels; RAISE("$%d: expected symbol",i+1);}
@@ -521,20 +509,15 @@
 	int n;
 	\attr int index;
 	\attr int mode;
+	\attr int lo;
 	\attr int hi;
-	\attr int lo;
 	\constructor (int n=2, int i=0) {
-		this->n=n;
-		this->hi=n-1;
-		this->lo=0;
-		this->mode=0;
-		this->index=i;
+		this->n=n; index=i; mode=0; lo=0; hi=n-1;
 		noutlets_set(n);
 	}
 	\decl 1 float(int i) {index = mod(i,n);}
 	\decl void anything(...) {
-		t_symbol *sel = argv[0]; sel = gensym(sel->s_name+3);
-		out[index](sel,argc-1,argv+1);
+		out[index](argv[1],argc-2,argv+2);
 		if (mode) {
 			index += sgn(mode);
 			if (index<lo || index>hi) {
@@ -611,7 +594,7 @@
 	\decl 0 list (...)  {
 		if (binbuf_getnatom(list) != argc) {out[0](0); return;}
 		t_atom2 *at = (t_atom2 *)binbuf_getvec(list);
-		for (int i=0; i<argc; i++) if (!atom_eq(at[i],argv[i])) {out[0](0); return;}
+		for (int i=0; i<argc; i++) if (at[i]!=argv[i]) {out[0](0); return;}
 		out[0](1);
 	}
 };
@@ -725,7 +708,7 @@
 
 \class ForEach : FObject {
 	\constructor () {}
-	\decl 0 list (...) {for (int i=0; i<argc; i++) out[0](argv+i);}
+	\decl 0 list (...) {for (int i=0; i<argc; i++) out[0](argv[i]);}
 };
 \end class {install("foreach",1,1);}
 
@@ -1083,7 +1066,7 @@
 
 \class GFSelector : FObject {
 	\constructor () {}
-	\decl void anything (...) {out[0](gensym(argv[0].a_symbol->s_name+3));}
+	\decl void anything (...) {out[0](argv[1]);}
 };
 \end class {install("gf/selector",1,1);}
 

Modified: trunk/src/classes_gui.cxx
==============================================================================
--- trunk/src/classes_gui.cxx (original)
+++ trunk/src/classes_gui.cxx Sat Aug 14 20:41:38 2010
@@ -183,13 +183,13 @@
 		sys_vgui(".x%x.c itemconfigure %sTEXT -fill %s\n",c,self->rsym->s_name,self->selected?"#0000ff":"#000000");
 	}
 	\decl void anything (...) {
-		string sel = string(argv[0]).data()+3;
+		t_symbol *sel = argv[1];
 		text.str("");
-		if (sel=="float") {}
-		else if (sel=="list" && argc>=2 && argv[1].a_type==A_FLOAT) {}
-		else {text << sel; if (argc>1) text << " ";}
+		if (sel==&s_float) {}
+		else if (sel==&s_list && argc>=3 && argv[2].a_type==A_FLOAT) {}
+		else {text << sel; if (argc>2) text << " ";}
 		long nl=0;
-		for (int i=1; i<argc; i++) {
+		for (int i=2; i<argc; i++) {
 			text << argv[i];
 			if (i!=argc-1) {
 				text << " ";
@@ -248,10 +248,7 @@
 		rcv = r==s_empty?0:r;
 		if (rcv) pd_bind((t_pd *)bself,rcv);
 	}
-	\decl void anything (...) {
-		t_symbol *sel = argv[0]; sel = gensym(sel->s_name+3); // this is getting tiring
-		if (snd) pd_anything(snd,sel,argc-1,argv+1);
-	}
+	\decl void anything (...) {if (snd) pd_anything(snd,argv[1],argc-2,argv+2);}
 	void set_rcv (t_symbol *rcv_=0) {
 		if (rcv) pd_unbind((t_pd *)bself,rcv);
 		rcv=rcv_;

Modified: trunk/src/gridflow.cxx
==============================================================================
--- trunk/src/gridflow.cxx (original)
+++ trunk/src/gridflow.cxx Sat Aug 14 20:41:38 2010
@@ -189,11 +189,11 @@
 }
 
 // adapted from desiredata/src/kernel.c
-void PtrOutlet::operator () (t_atom *a) {
-    if      (a->a_type==A_FLOAT  ) (*this)(a->a_float);
-    else if (a->a_type==A_SYMBOL ) (*this)(a->a_symbol);
-    else if (a->a_type==A_POINTER) (*this)(a->a_gpointer);
-    else error("can't send atom whose type is %d",a->a_type);
+void PtrOutlet::operator () (t_atom &a) {
+    if      (a.a_type==A_FLOAT  ) (*this)(a.a_float);
+    else if (a.a_type==A_SYMBOL ) (*this)(a.a_symbol);
+    else if (a.a_type==A_POINTER) (*this)(a.a_gpointer);
+    else error("can't send atom whose type is %d",a.a_type);
 }
 void outlet_atom2 (PtrOutlet self, t_atom *av) {
 	if (av->a_type==A_FLOAT)   self(av->a_float);    else
@@ -202,6 +202,15 @@
 	self(1,av);
 }
 
+bool t_atom2::operator == (const t_atom2 &b) {
+	const t_atom2 &a = *this;
+	if (a.a_type!=b.a_type) return false;
+	if (a.a_type==A_FLOAT)   return a.a_float   ==b.a_float;
+	if (a.a_type==A_SYMBOL)  return a.a_symbol  ==b.a_symbol;
+	if (a.a_type==A_POINTER) return a.a_gpointer==b.a_gpointer;
+	if (a.a_type==A_LIST)    return a.a_gpointer==b.a_gpointer;
+	RAISE("don't know how to compare elements of type %d",a.a_type);
+}
 //----------------------------------------------------------------
 // Dim
 
@@ -598,19 +607,17 @@
     #ifdef DES_BUGS
 	post("BFObject_anything bself=%08lx magic=%08lx self=%08lx",long(bself),bself->magic,long(bself->self));
     #endif
+    const char *s = selector->s_name;
     try {
-	t_atom2 argv[ac+1];
-	for (int i=0; i<ac; i++) argv[i+1] = at[i];
-	int argc = handle_braces(ac,argv+1);
-	argv[0]=winlet;
+	t_atom2 argv[ac+2]; for (int i=0; i<ac; i++) argv[i+2] = at[i];
+	int argc = handle_braces(ac,argv+2);
 	FMethod m;
 	char buf[64], bof[64];
-
-	sprintf(buf,"_%d_%s",winlet,selector->s_name); m=funcall_lookup(bself,buf); if (m) {m(bself->self,argc  ,argv+1); return;}
-	sprintf(bof,"_n_%s",        selector->s_name); m=funcall_lookup(bself,bof); if (m) {m(bself->self,argc+1,argv  ); return;}
-	m = funcall_lookup(bself,"anything");                  if (m) {argv[0]=gensym(buf); m(bself->self,argc+1,argv  ); return;}
-	pd_error((t_pd *)bself, "method '%s' not found for inlet %d in class '%s'",selector->s_name,winlet,pd_classname(bself));
-    } catch (Barf &oozy) {oozy.error(bself,winlet,selector->s_name);}
+	sprintf(buf,"_%d_%s",winlet,s); m=funcall_lookup(bself,buf);                 if (m) {m(bself->self,argc+0,argv+2); return;}
+	sprintf(bof,"_n_%s",        s); m=funcall_lookup(bself,bof); argv[1]=winlet; if (m) {m(bself->self,argc+1,argv+1); return;}
+	m = funcall_lookup(bself,"anything");      if (m) {argv[0]=winlet; argv[1]=selector; m(bself->self,argc+2,argv+0); return;}
+	pd_error((t_pd *)bself, "method '%s' not found for inlet %d in class '%s'",s,winlet,pd_classname(bself));
+    } catch (Barf &oozy) {oozy.error(bself,winlet,s);}
 }
 static void BFObject_anything0 (BFObject *self, t_symbol *s, int argc, t_atom2 *argv) {
 	BFObject_anything(self,0,s,argc,argv);

Modified: trunk/src/gridflow.hxx
==============================================================================
--- trunk/src/gridflow.hxx (original)
+++ trunk/src/gridflow.hxx Sat Aug 14 20:41:38 2010
@@ -248,6 +248,9 @@
 
 // trick to be able to define methods in t_atom
 struct t_atom2 : t_atom {
+	// does not do recursive comparison of lists.
+	bool operator == (const t_atom2 &b);
+	bool operator != (const t_atom2 &b) {return !(*this==b);}
 	bool operator == (t_symbol *b) {return this->a_type==A_SYMBOL && this->a_symbol==b;}
 	bool operator != (t_symbol *b) {return !(*this==b);}
 	operator float32 () const {if (a_type!=A_FLOAT) RAISE("expected float"); return a_float;}
@@ -825,7 +828,7 @@
 	void operator () (t_gpointer *g) {outlet_pointer(p,g);}
 	void operator () (             int argc, t_atom *argv) {outlet_list(p,&s_list,argc,argv);}
 	void operator () (t_symbol *s, int argc, t_atom *argv) {outlet_anything(p,s,  argc,argv);}
-	void operator () (t_atom *a);
+	void operator () (t_atom &a);
 };
 void outlet_atom2 (PtrOutlet self, t_atom *av);
 



More information about the Gridflow-cvs mailing list