Saving parameters to User Defaults

kraftwerk's icon

Hi all,

is there any way of saving single parameters (like e.g. the content of a text box) to some kind of user defaults?
I mean, if a user changes a parameter it should be automatically saved somewhere with no file prompt or anything related.

Thanks in advance

KrisW's icon

yes sure ! , please take a look at the [pattr] object family . have fun !

kraftwerk's icon

Thanks for the reply, I already did look at the pattr / pattrstorage stuff. My patch will run in standalone mode - the autorestore features of the pattr family only seem to work if the concerning patcher is saved. I'm honestly a bit confused by the documentation..

KrisW's icon

yes , it will recall the state after running the patcher . is it what you desired ? . you can alternatively use [coll] or [dict] and "embed" em to the patcher . you will be able to provide your own preset logic too ,do defaults or whatever else . but as i said you need to implement system that hits your controls while certain conditions are fulfilled (on loadbang or whenever you want) .

kraftwerk's icon

Yep, that's what I want to achieve. But the internal state only seems to be saved if I save my patcher document. If I compile my patch and run it as a standalone application (or just run the patch in non-edit mode) the [pattr] object doesn't seem to overwrite the states.

KrisW's icon

yes because you need to save your changes. it wont remember if you did not saved it . this would be destructive in some cases .
but if you will look at the [pattrstorage] help file , you will find that SAVE section ,there you can find how to autosave settings to a file . you can force your patch to rely on that stored file . perhaps it should work for you

Gregory Taylor's icon

If you're working in Max 6, have you considered clicking on "Parameter Mode Enable" in the Inspector for your UI object and then checking the "Initial Enable" checkbox which then appears and typing in a value in the "Initial" space directly below it in the Inspector?

KrisW's icon

i suppose that OP wants to save last changes without resaving the patcher .

Gregory Taylor's icon

Ah. They want the *last* setting. Then it's most definitively savemode in pattr.

kraftwerk's icon

Sorry maybe it helps to describe the concrete Use-Case. In my patch there is a textbox which displays the current port for incoming OSC messages. If a user types in a different port, the patch should replace its internal setting - if possible without writing a new .xml file for this single value. And yes, without re-saving the patcher because it will be compiled as a standalone application.

My question was, if Max has some sort of "User defaults" feature to store certain parameters internally.

Gregory Taylor's icon

What would be wrong with taking the output of a UI object and using an ordinary message box to store whatever value a user types in (via a set message to the right inlet) which could then be triggered with a loadbang object (for outputting the value the next time the app is launched)? It's not exactly rocket surgery, but....

kraftwerk's icon

...but to store the message the patch still needs to be saved (?)

Gregory Taylor's icon

Oh, right. No way to do it that I can think of, then. Oh - but this isn't just an ordinary standalone, is it? You're thinking App Store, I suppose. D'oh! Sorry - time for coffee!

Gregory Taylor's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I apologize if I was a bit vague with the message box solution [love those backchannel email things]. While it won't help kraftwerk any, here's a simple example *will* save initial states or states a user changes and fire up with that setting next time [of course, you'll need to save the program]....

KrisW's icon

oh coffee , i forgot ,its cold now .

Max Patch
Copy patch and select New From Clipboard in Max.

@kraft . check this

edit : read is connected now

Gregory Taylor's icon

Elegant read/writes on the fly!

KrisW's icon

@ gregory : thanks :)

@kraft : if you like this solution ,you can use [thispatcher] to retrieve current patch path to store the file where your patcher is placed

kraftwerk's icon

Thanks, looks good. [thispatcher] doesn't seem to work properly if you use it in a Max-standalone application - here is a workaround that I also found somewhere in the forum a while ago:

Max Patch
Copy patch and select New From Clipboard in Max.

KrisW's icon

oh it is a wrong patch , please repost the code

misho's icon

I guess you can do it with coll but that seems cumbersome if you want to store multiple variables....

Why not just use [preset]? I mean, that's what it's there for, no? :)

The idea is this, on patch close you use a [closebang] to do -
- send a "store 1" message to [preset] to save current values
- then send a "write (path)/usersettings.maxpresets" to [preset] to save to disk

Then on patch open you use [loadbang] to:
- send a "read (path)/usersettings.maxpresets" to [preset]
- send a "1" to recall the preset slot.

On Mac, it's ideal to read/write to Macintosh HD/Users/Shared to avoid permissions problems.
On Windows, you can write to "C:Documents and SettingsAll UsersApplication Data". On XP at least... later versions of Windows are slightly different paths, I think.

Hope this helps!

4701.savingSettings.maxpat
Max Patch
kraftwerk's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Sorry I just re-posted your patch @KrisW. Here is what I meant to post:

kraftwerk's icon

Thanks misho this looks like a convenient solution!