Save and Load states directly through editor?

Is there a way to save, load states directly from the editor? or maybe have a list of states you can choose from and load them without having to go through the three dots and choosing a location and loading it?

thanks!

The toolbar menu actions can be accessed from scripts with the toolbar function. It’s also possible to store states in the browser’s cache and recall them using storage, getState and setState, for example:

// save state script
var state = getState("root")
storage.setItem("my_state", state)

// recall state script
setState(storage.getItem("my_state"))

This is amazing! Thank you so much! You are a wizard!

Jean-Emmanuel, could you please explain how to implement this solution for dummies? I am trying to have a button which when I press it loads the state of all widgets in the current Tab. Where do I input the “toolbar” function? What widget do I need to use to paste the “save state script” and “recall state script” you mentioned in your previous post? I want to save states in my drive rather than in browser’s cache.
Thank you in advance for your help!!

You don’t need the “toolbar” function, the above example is supposed to be used in a widget’s script property, for example a button widget with mode set to tap:

// save button's script property
// save state script
var state = getState("root")
storage.setItem("my_state", state)

You’d need another button for the load script

// load button's script property
// recall state script
setState(storage.getItem("my_state"))

Now saving to the disk is different, you’ll need to write a custom module to do that, there’s no “official” way to do it.

1 Like

Thank you! I will have to find someone to write that custom module for me as my scripting abilities are zero.
I would at least double check with you my workflow: I am building controls for realtime visuals and wanting to have various looks set up as presets via States which are saved on my local drive (so I can easily copy paste them on another machine if needed). I am hoping to trigger those looks (States) during the live performance and then tweak them as I need. For the live performance I would need to have around 15-20 different States saved as Buttons on multiple Tabs (around 5 States on each Tab). Is this a good approach? Could there be potentially any issues?

Thanks again for your help!

another noob here… i can’t get it to work.

simple scenario. three buttons, one normal button to check the state (button_1) , two other buttons with -> inspector -> button -> mode set to tap.

button_2 with the following code -> inspector -> value -> script:
var state = getState("root")
storage.setItem("my_state", state)

button_3 with the following code -> inspector -> value -> script:
setState(storage.getItem("my_state"))

the console says by pressing the last two buttons:
button_2/script .script javascript error at line 1: ReferenceError: getState is not defined
button_3/script .script javascript error at line 1: ReferenceError: setState is not defined

do i have to put something else instead off ”root” and “my_state” ?

and, is it possible to save only the state of a single tab instead of the root ?

and in top of that, is it possible to exclude widgets from being saved and recalled?

any help is appreciated!

Looks like I made a mistake in my previous posts: the functions are stateSet and stateGet... :slight_smile: (Scripting - Open Stage Control)

hi jean-emmanuel
thanks for your answer, still no luck, nothing happens with the two scripts:

var state = stateGet("root")
storage.setItem("my_state", state)

stateSet(storage.getItem("my_state"))

and the most important questions for me to use the stateGet / stateSet function:

is it possible to save only the state of a single tab instead of the root ?
and, is it possible to exclude widgets from being saved and recalled?

if yes, how too do it? sorry, I'm a total noob...

thanks.

Damned, there's a bug in storage.getItem(), it doesn't return anything... it will be fixed in next release.

is it possible to save only the state of a single tab instead of the root ?

You can pass a widget id or an array of ids to stateGet, for example:

stateGet('tab_id') // state of tab's children
stateGet(['tab_id', 'button_a']) // state of tab's children + button_a

is it possible to exclude widgets from being saved and recalled?

stateGet() returns a javascript object filled with id:value pairs, somthing like:

{button_1: 1, fader_1: 0.3}

You can remove items before saving the state object:

var state = stateGet('tab_id')
delete state.fader_1
storage.setItem("my_state", state)

wow, thank you, that was fast.
I think I can manage my ideas with the explanations you did.
waiting for the next release...

:blush: