[PD] dealing with arguments and inlets

Frank Barknecht fbar at footils.org
Tue Jan 31 12:16:48 CET 2006


Hallo,
Hans-Christoph Steiner hat gesagt: // Hans-Christoph Steiner wrote:

> I have written some classes for handling arguments when writing classes 
> in Pd.  They are [float_argument], [symbol_argument], and 
> [any_argument].  Currently, I am thinking in general,  inlets should be 
> matched to arguments and vice versa, 

"should match" would be oversimplyfiying, but having an extra inlet in
the argument-patches never hurts.

> so these objects all have a 
> "convenience" right inlet, to attach the [inlet] to so that the data 
> all comes from the [*_argument] object.
> 
> To use them, you add the argument you want it to handle like this:
> 
> [float_argument $1]
> 
> If you want a default value for when none is specified, you would do it 
> like this:
> 
> [float_argument $2 234]
> [symbol_argument $3 default]
> [any_argument $9 asdf]
> [any_argument $5 444]

I attached "list_argument" which does the same as "any_argument" but
doesn't require any externals and is much simpler than [any_arg...].
In fact, it's just [float_argument] where "float" is replaced by "list
append". 

Note that I would much prefer, if [list_argument] would be renamed to
be [any_argument] and replace it. 

Reason is: The name "list_argument" could lead to wrong expectations: It doesn't
handle variable length lists as arguments, because that is impossible
without externals like dollarg. It just handles one-element lists
which get auto-converted to their respective type: "symbol x" or
"float x".

Of course it won't work with Pd < 0.39.

Regarding symbol_- and float_argument: These could be implemented as: 

  [list_argument $1 $2] or [any_argument] 
  |
  [route symbol] or [route float]
  |
  [outlet]

to share more code. Because Pd autoconverts one-element lists, there
will always be a proper selector to make [route] do The Right Thing.

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__
-------------- next part --------------
#N canvas 160 304 587 350 10;
#X obj 259 234 outlet;
#X text 83 259 If the argument is not equal to 0 \, use it. Pd init
arguments to 0 so unused arguments will be 0;
#X obj 143 116 select 0;
#X text 82 296 This is useful to have internals inited \, but not reset
if there is no argument specified.;
#X obj 143 190 select 0;
#X text 275 172 if 2nd arg \, then use as default value;
#X obj 143 20 inlet;
#X obj 259 13 inlet;
#X text 297 14 convenience inlet;
#X obj 143 96 list append \$1;
#X obj 143 169 list append \$2;
#X obj 143 55 bang;
#X connect 2 0 10 0;
#X connect 2 1 0 0;
#X connect 4 1 0 0;
#X connect 6 0 11 0;
#X connect 7 0 0 0;
#X connect 9 0 2 0;
#X connect 10 0 4 0;
#X connect 11 0 9 0;
-------------- next part --------------
#N canvas 499 134 550 477 10;
#X msg 195 65 bang;
#X obj 195 132 print float;
#X msg 49 65 bang;
#X msg 51 197 bang;
#X obj 51 264 print blank;
#X msg 53 348 bang;
#X obj 53 415 print blank_with_default;
#X text 24 173 When there is a blank argument \, there is no output:
;
#X text 26 37 This object can take any kind of argument:;
#X msg 276 349 bang;
#X obj 276 416 print blank_with_default;
#X msg 204 195 bang;
#X obj 204 262 print blank;
#X obj 49 132 print non-float;
#X obj 49 101 list_argument word;
#X obj 53 384 list_argument \$1 default;
#X obj 51 233 list_argument;
#X obj 204 231 list_argument \$1;
#X obj 195 101 list_argument 5;
#X text 13 12 [list_argument];
#X obj 276 385 list_argument 0 256;
#X text 32 295 If you set a second argument \, it will be used as the
default when the argument is blank. (0 is treated as no argument \,
too.);
#X connect 0 0 18 0;
#X connect 2 0 14 0;
#X connect 3 0 16 0;
#X connect 5 0 15 0;
#X connect 9 0 20 0;
#X connect 11 0 17 0;
#X connect 14 0 13 0;
#X connect 15 0 6 0;
#X connect 16 0 4 0;
#X connect 17 0 12 0;
#X connect 18 0 1 0;
#X connect 20 0 10 0;


More information about the Pd-list mailing list