[PD] abstractions which have their own memory

Frank Barknecht fbar at footils.org
Tue Jul 4 18:18:09 CEST 2006


Hallo,
sokratesla hat gesagt: // sokratesla wrote:

> # I tried to build an abstraction which remembers its previous state before
> closing the patch. I put an array in the abstraction with its "save
> contents" option checked and saved the state of the abstraction in this
> array of which name starts with $0- in order to make each table unique. A
> [loadbang] outputs the values stored in the array.

Your approach has some pitfalls. First: If you use an abstraction in a
surrounding patch and then save the surrounding patch, the abstraction
itself won't get saved. Second: Even if you save the abstraction by
hand, if you use two of them, then after saving both will have the
same value stored. This is probably not what you wanted. $0 won't help
you here, because in a saved patch, it is just that: "\$0". The last
actual value of $0 of course isn't saved and you cannot rely on
getting the same value again if you open the patch again.

The only good way to save settings of (maybe nested) abstractions is
to intercept some or all messages that their objects generate and
collect them in a globally accessible space like a textfile, a global
array, global data structure subpatch, global message object, global
[pool], [coll], [msgfile] or whatever. This global saver in the end
has to be outside of the abstraction whose state you intend to save.
To differentiate between abstractions of the same type and file you
will also need to give them ids or tags. I generally abuse $1 for
this. 

[sssad], which was mentioned here several times, tries to be an easy
to use, general purpose "message interceptor". ([commun] in Memento is
similar, but specific to Memento.) In itself it doesn't deal with the
actual state saving. In the sssad-package there is an example patch
which does use a [textfile] for the saving, of course you could
replace the textfile with a message box, if you want to.  [textfile]
and message boxes share almost the same interface, so it would be a
drop-in replacement. Other candidates for saving include [pool] etc.
But regardless of what you use for the actual saving to disk, you will
need to collect the state of objects first, and for that I made
[sssad].

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__




More information about the Pd-list mailing list