Re: [iemguts/savebangs] and [iemguts/canvasdelete] doesn't work as I would expect them

IOhannes m zmölnig via Pd-list <[email protected]> Fri, 29 May 2026 13:51:40 +0200
Newsgroups gmane.comp.multimedia.puredata.general
Message-ID <[email protected]>
On 5/29/26 11:55, Alexandros Drymonitis wrote:
> 
> Here's a patch (attached). It seems that I was probably wrong, still the 
> patch doesn't work as I expect it to work. Connect the right outlet of 
> [savebangs] to the message underneath it and save. In [pd test1] only 
> [osc~ 440] should remain, since the loop is set to run two times and 
> delete two objects, [phasor~] and [cos~], but only one object gets 
> deleted. The contents of [pd test2] are cleared though.
> 

thanks for the patch.

the good news is, that i do not see an issue with [savebangs].

the other observation is, that when I maunally trigger the deletion (by 
clicking on [2( instead of connecting it with [savebangs] and saving the 
patch),  iget the same results:
- pd-test1 contains both a [osc~ 440] and a [cos~] object
- pd-test2 is empty

so in both cases, only a single object is removed (the [phasor~]) from 
the [pd test1].

why?

the answer to that is not very complicated.
if we look at the source code of the subpatch, we see:
~~~
#N canvas 834 476 450 300 test1 0;
#X obj 61 52 osc~ 440;
#X obj 62 107 phasor~ 1;
#X obj 63 161 cos~;
#X restore 277 88 pd test1;
~~~

which basically translates to:
"in the test1 subpatch, the [osc~ 440] object has index#0, [phasor~ 1] 
has index#1 and [cos~] has index#2".

because you want to remove both [phasor~] and [cos~], you send two 
messages to the subpatch:
- [delete 1( to remove [phasor~ 1]
- [delete 2( to remove [cos~


now, the issue with that is, that the two messages are separate.
when you send [delete 1(, the [phasor~ 1] object is removed from the 
subpatch.
this means, that now the source code is:
~~~
#N canvas 834 476 450 300 test1 0;
#X obj 61 52 osc~ 440;
#X obj 63 161 cos~;
#X restore 277 88 pd test1;
~~~

which translates to:
"in the test1 subpatch, the [osc~ 440] object has index#0, and [cos~] 
has index#1".

more specifically, there is no object with index#2.
so when you send [delete 2(, there's no object to remove, so this is a 
no-op (the "delete" message does not emit an error when trying to remove 
a non-existant object).

conclusion:
if you want to remove both [phasor~] and [cos~], you have to take into 
account that removing an object will change the indices (of all objects 
with higher indicies than the deleted one) in the patch.

you could either do [delete 1, delete 1( (taking the index shift into 
account) or [delete 2, delete 1( (removing higher indices first).

i hope this helps.

(i guess my source-code snippets didn't really help explaining the issue)

mgfdsf
IOhannes
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/UYS5H6KGBNJZ3TZDMP6Y75NBES65WT2Z/

To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/