[Gridflow-cvs] [svn] commit: r5827 - in /trunk: doc/flow_classes/setargs-demo.pd doc/flow_classes/setargs-demo2.pd doc/flow_classes/setargs-help.pd src/classes2.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Wed Jul 28 18:52:00 EDT 2010


Author: matju
Date: Wed Jul 28 18:51:58 2010
New Revision: 5827

Log:
[setargs]: adding adddollsym2

Modified:
    trunk/doc/flow_classes/setargs-demo.pd
    trunk/doc/flow_classes/setargs-demo2.pd
    trunk/doc/flow_classes/setargs-help.pd
    trunk/src/classes2.cxx

Modified: trunk/doc/flow_classes/setargs-demo.pd
==============================================================================
--- trunk/doc/flow_classes/setargs-demo.pd (original)
+++ trunk/doc/flow_classes/setargs-demo.pd Wed Jul 28 18:51:58 2010
@@ -1,14 +1,9 @@
-#N canvas 0 0 655 327 10;
-#X obj 87 274 setargs;
+#N canvas 0 123 611 441 10;
+#X obj 87 334 setargs;
 #X obj 87 173 list prepend set setargs-demo;
 #X msg 97 146 bang;
 #X obj 87 192 list trim;
 #X msg 87 123 list hello world;
-#X obj 23 106 # rand;
-#X obj 23 51 tgl 15 0 empty empty empty 17 7 0 10 -204786 -1 -1 0 1
-;
-#X msg 23 87 10 # 1000;
-#X obj 23 125 #to_list;
 #X obj 346 13 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
 -1;
 #X obj 346 49 display;
@@ -19,24 +14,21 @@
 #X obj 346 104 display;
 #X msg 97 212 adddollar 0 \, adddollar 666 \, addcomma \, addsemi;
 #X text 82 104 TURN OFF CHECKBOX AND TRY THIS;
-#X obj 23 32 loadbang;
-#X obj 23 68 metro 500;
 #X text 127 147 (reset);
 #X msg 101 232 adddollsym 0-queqchose \, adddollsym 1-stuff \, adddollar
-2 \, adddollsym 6-basouelle;
+2 \, adddollsym 6-dondaine;
+#X msg 106 300 adddollsym2 foo-%1-bar % \, adddollsym2 @0-zut- at 3 @
+;
+#X obj 36 56 inlet;
 #X connect 1 0 3 0;
 #X connect 2 0 1 0;
 #X connect 3 0 0 0;
 #X connect 4 0 1 0;
-#X connect 5 0 8 0;
-#X connect 6 0 18 0;
-#X connect 7 0 5 0;
-#X connect 8 0 1 0;
-#X connect 9 0 11 0;
-#X connect 11 0 10 0;
-#X connect 12 0 14 0;
-#X connect 13 0 12 0;
+#X connect 5 0 7 0;
+#X connect 7 0 6 0;
+#X connect 8 0 10 0;
+#X connect 9 0 8 0;
+#X connect 11 0 0 0;
+#X connect 14 0 0 0;
 #X connect 15 0 0 0;
-#X connect 17 0 6 0;
-#X connect 18 0 7 0;
-#X connect 20 0 0 0;
+#X connect 16 0 1 0;

Modified: trunk/doc/flow_classes/setargs-demo2.pd
==============================================================================
--- trunk/doc/flow_classes/setargs-demo2.pd (original)
+++ trunk/doc/flow_classes/setargs-demo2.pd Wed Jul 28 18:51:58 2010
@@ -1,3 +1,3 @@
 #N canvas 595 387 450 300 10;
-#X obj 63 42 setargs-demo 858 11 800 553 805 485 248 282 975 377;
 #X text 67 20 this one is for testing dollars and dollsyms;
+#X obj 63 42 setargs-demo;

Modified: trunk/doc/flow_classes/setargs-help.pd
==============================================================================
--- trunk/doc/flow_classes/setargs-help.pd (original)
+++ trunk/doc/flow_classes/setargs-help.pd Wed Jul 28 18:51:58 2010
@@ -1,53 +1,81 @@
 #N canvas 596 24 632 642 10;
 #X obj 0 0 doc_h;
-#X obj 3 587 doc_also;
-#X obj 0 607 doc_f;
-#X obj 103 587 args;
-#X obj 3 204 doc_c 0;
-#X obj 3 244 doc_i 1;
-#X obj 14 274 doc_ii 0;
-#X obj 97 454 doc_m i0 set;
-#X obj 97 296 doc_m i0 add2;
-#X obj 97 318 doc_m i0 addcomma;
-#X obj 97 384 doc_m i0 addsemi;
-#X obj 3 547 doc_o 0;
-#X text 232 384 just like messageboxes;
-#X text 232 318 just like messageboxes;
-#X text 232 296 just like messageboxes;
+#X obj 3 852 doc_also;
+#X obj 0 872 doc_f;
+#X obj 103 852 args;
+#X obj 3 281 doc_c 0;
+#X obj 3 321 doc_i 1;
+#X obj 14 351 doc_ii 0;
+#X obj 97 719 doc_m i0 set;
+#X obj 97 373 doc_m i0 add2;
+#X obj 97 395 doc_m i0 addcomma;
+#X obj 97 597 doc_m i0 addsemi;
+#X obj 3 812 doc_o 0;
+#X text 232 597 just like messageboxes;
+#X text 232 395 just like messageboxes;
+#X text 232 373 just like messageboxes;
 #X obj 30 52 setargs;
-#X text 89 138 for a demonstration \, please open this abstraction
+#X text 90 234 for a demonstration \, please open this abstraction
 instance;
-#X obj 93 157 setargs-demo 728 489 912 16 650 204 114 534 260 898 \$0-something
-\$0-something;
-#X obj 97 340 doc_m i0 adddollar;
-#X obj 97 362 doc_m i0 adddollsym;
+#X obj 97 417 doc_m i0 adddollar;
+#X obj 97 439 doc_m i0 adddollsym;
 #X text 90 43 set abstraction instance arguments using a messagebox-like
 interface. this updates the binbuf \, the objectbox's appearance \,
 the canvas-environment \, and the titlebar of the patch window \, whenever
 one of its five methods are called.;
-#X obj 97 274 doc_m i0 add;
-#X obj 139 587 gf/propertybang;
-#X text 232 340 just like messageboxes;
-#X text 232 274 just like messageboxes;
-#X text 232 454 just like messageboxes;
-#X text 232 476 don't forget to write the classname! If you use it
+#X obj 97 351 doc_m i0 add;
+#X obj 139 852 gf/propertybang;
+#X text 232 417 just like messageboxes;
+#X text 232 351 just like messageboxes;
+#X text 232 719 just like messageboxes;
+#X text 232 741 don't forget to write the classname! If you use it
 without arguments \, make sure that the classname is the next thing
 that you add. But the classname will only be applied at the next reload
 \, delete/undo \, copy/paste \, or duplicate.;
-#X text 232 362 just like messageboxes;
-#X obj 97 406 doc_m i0 args;
-#X text 232 406 INTERNAL USE ONLY : this sets the \$1 \, \$2 \, \$3
+#X text 232 439 just like messageboxes;
+#X obj 97 619 doc_m i0 args;
+#X obj 437 262 setargs-demo2 a 37 b 42 c 53;
+#X text 232 619 INTERNAL USE ONLY : this sets the \$1 \, \$2 \, \$3
 \, ... variables of the instance and the titlebar of the instance.
-this is called automatically by any of the other methods here.;
-#X obj 437 185 setargs-demo2 a 37 b 42 c 53;
+this is called automatically by any of the other methods here. This
+part is what happens AFTER the $-substitution \, so \, it does not
+set the contents of the objectbox \, which is BEFORE the \$0-substitution
+and is done directly by every other method here.;
+#X obj 97 461 doc_m i0 adddollsym2;
+#X text 232 483 \$2 is a symbol containing a single character;
+#X text 232 461 \$1 is a symbol representing a mangled dollsym;
+#X text 232 505 \$1 is demangled by replacing every occurrence of the
+\$2 character by a dollar sign. no leading dollarsign is implied.;
+#X text 232 553 thus adddollsym2 foo-%1-bar % gives foo-\$1-bar;
+#X text 232 575 and adddollsym2 @0-zut- at 3 @ gives \$0-zut-\$3;
+#X obj 93 217 setargs-demo 574 457 223 573 591 363 276 967 206 315
+;
+#X obj 93 179 # rand;
+#X obj 93 124 tgl 15 0 empty empty empty 17 7 0 10 -204786 -1 -1 0
+1;
+#X msg 93 160 10 # 1000;
+#X obj 93 198 #to_list;
+#X obj 93 105 loadbang;
+#X obj 93 141 metro 500;
 #X connect 1 1 3 0;
-#X connect 1 1 22 0;
+#X connect 1 1 21 0;
+#X connect 7 1 24 0;
 #X connect 7 1 25 0;
-#X connect 7 1 26 0;
 #X connect 8 1 14 0;
 #X connect 9 1 13 0;
 #X connect 10 1 12 0;
-#X connect 18 1 23 0;
-#X connect 19 1 27 0;
-#X connect 21 1 24 0;
-#X connect 28 1 29 0;
+#X connect 17 1 22 0;
+#X connect 18 1 26 0;
+#X connect 20 1 23 0;
+#X connect 27 1 29 0;
+#X connect 30 1 32 0;
+#X connect 30 1 31 0;
+#X connect 30 1 33 0;
+#X connect 30 1 34 0;
+#X connect 30 1 35 0;
+#X connect 37 0 40 0;
+#X connect 38 0 42 0;
+#X connect 39 0 37 0;
+#X connect 40 0 36 0;
+#X connect 41 0 38 0;
+#X connect 42 0 39 0;

Modified: trunk/src/classes2.cxx
==============================================================================
--- trunk/src/classes2.cxx (original)
+++ trunk/src/classes2.cxx Wed Jul 28 18:51:58 2010
@@ -199,6 +199,17 @@
 	\decl 0 addcomma (...) {BOF;                  t_atom a; SETCOMMA(&a); binbuf_add(b,1,&a);  mom_changed();}
 	\decl 0 adddollar(float f)      {BOF; t_atom a; SETDOLLAR(&a, max(int(f),0));              binbuf_add(b,1,&a); mom_changed();}
 	\decl 0 adddollsym(t_symbol *s) {BOF; t_atom a; SETDOLLSYM(&a,symprintf("$%s",s->s_name)); binbuf_add(b,1,&a); mom_changed();}
+	\decl 0 adddollsym2(t_symbol *s, t_symbol *t) {
+		BOF;
+		if (strlen(t->s_name)!=1) RAISE("substitution character must have a single letter");
+		char tt = *t->s_name;
+		t_atom a;
+		char *d = strdup(s->s_name);
+		for (char *e=d; *e; e++) if (*e==tt) *e='$';
+		SETDOLLSYM(&a,gensym(d));
+		free(d);
+		binbuf_add(b,1,&a); mom_changed();
+	}
 };
 \end class {install("setargs",1,1);}
 
@@ -1492,6 +1503,17 @@
 #endif
 }
 
+// pas vite vite
+string string_replace (string victim, string from, string to) {
+	for (size_t i=0;;) {
+	  i = victim.find(from,i);
+	  if (i==string::npos) break;
+	  victim = victim.replace(i,from.length(),to);
+	  i += to.length();
+	}
+	return victim;
+}
+
 \class GFStringReplace : FObject {
 	t_symbol *from;
 	t_symbol *to;
@@ -1502,12 +1524,7 @@
 	string a = string(victim->s_name);
 	string b = string(from->s_name);
 	string c = string(to->s_name);
-	for (size_t i=0;;) {
-	  i = a.find(b,i);
-	  if (i==string::npos) break;
-	  a = a.replace(i,b.length(),c);
-	  i += c.length();
-	}
+	a = string_replace(a,b,c);
 	outlet_symbol(outlets[0],gensym(a.c_str()));
 }
 \end class {install("gf/string_replace",1,1);}



More information about the Gridflow-cvs mailing list