[PD] can a [clone] instance determine the total number of clones?

IOhannes m zmoelnig zmoelnig at iem.at
Thu Mar 4 08:21:23 CET 2021


On 3/4/21 12:23 AM, William Huston wrote:
> Ideally, it would be nice to change N in*one place*. I think this might be
> possible if the first feature was implemented.

hoiw about your own little abstraction wrapper?


~~~
[inlet~]
|
[clone foo $1 $1 $0-]
|
[outlet]

[array define $0-control $1]

[array define $0-data]

[loadbang]
|
[float $1]
|
[* 10]
|
[resize $1(
|
[s $0-data]
~~~


so you only need to change [clonefoo 10] to [clonefoo 39] and it will 
create 39 clones for you, each of them knowing the total number of clones.
it will also  make sure that the "control" array has the same size as 
there are clones, and that the "data" array has 10* that size.
as you can see, "resizing" the "control" array is trivial; resizing to a 
size different from the number of elements requries a bit of code.


 > "If I am instance #1, and the number of instances has changed since
 > last time (stored in a global variable), then resize my arrays".

that's probably a misunderstanding here, how [clone] works.
1. you cannot change the number of clones dynamically.
2. if you change [clone foo 10] to [clone foo 20], this will delete all 
10 instances of [foo] and create 20 *new* instances.
the new instance #1 has no relationship with the old instance #1 (apart 
from being read from the same abstraction and sharing the same 
arguments). esp. it has no knowledge about anything that might have 
happened before the [clone] object was changed. so there is no "since 
last time".

mdgfasr
IOhannes




More information about the Pd-list mailing list