How to save pattr objects (absractions included) into a single pattrstorage file

cerup's icon

I'm trying to figure out if it's possible to save pattr objects within an abstraction into a single global write file.

I've only been able to get things saved by putting a [pattrstorage] in each abstraction. However, if I then want to save to a file, it saves a file per abstraction instance which takes forever. If there's 10 instances of an abstraction, I have to click save 10 times, etc.

Is there a way to have a single pattrstorage in the main patch that can save all the pattr objects within abstraction? A single file is the most ideal.

lsprice's icon

Try putting an [autopattr] object into each abstraction, rather than [pattrstorage], then put a single [pattrstorage] inside your top level patch. I think you may need an [autopattr] within the main patch as well - easy to check.

If you're using multiple instances of the same abstraction (or just as a best practice), use the #1 convention to give a unique name to each abstraction instance, and include this argument as part of the scripting name(s) for the controls within the abstraction (e.g. #1-myAbstractionPatchParameter).

cerup's icon

Thanks! I'll give it a try. I'm not saving UI element states though and when I tried autopattr before it seemed to only be for UI objects. I need to save symbols (like names of files that need to load).

I'll try again though and report back. Will #0 also work or does it have to #1?

lsprice's icon

Then instead of substituting [autopattr] for [pattr], just add [autopattr] objects to each abstraction. [autopattr] should automatically 'see' each [pattr] object and offer its storage to the higher-level [pattrstorage]

You actually don't need the names, as [autopattr] will generate a name for each [pattr], but the arguments are nice if you want to control the naming. #1 will take the first argument to your abstraction (#2 will take the 2nd argument, and so on). #0 will give an automatically generated number specific to each instance.

I've included a simple example. I hope this helps.

2615.mainPatch.maxpat
Max Patch
cerup's icon

Thanks! I seem to have it half-working working now. All the parameters are showing up in [pattrsorage] and changing correct when I change them.

It seems to save correctly if I [write] message to pattrstorage. The json file looks correct. However, if I try to read that file back in when I restart (or without a restart), it doesn't change all the parameters.

cerup's icon

Ah, I forgot you have to set the preset recal number when you want to load a preset. Now it's working! Thanks a lot for you help! :D