Save, scroll, open State files

Dear all
I created a controller. What I would like to achieve:

  • Save the current state of all widget to the hard disk, by using the "Save" button (see pix-1). It should perform the same operation as using the menu "Save as ..." (see pix-2).

pix-1:

pix-2
pix-2

The name of the state file should be the one in the input widget (Preset 1).

  • Scroll through the saved state file by dialing the "Preset" knob (bottom right) and the state file name should be displayed by the input widget. With the "Load" button, the corresponding state file should be opened. (see pix-3).

It should perform the same operation as using the menu "Open" (see pix-4).

pix-3:

pix-4:
pix-4

Any hint is highly appreciated :slight_smile:

Thank you a lot for your support in advance
Kind regards
Andreas

Calling the menu's actions can be done via scripting with the toolbar() function, for example calling toolbar(1,3) will call "State > Open". However to get exactly what you described here it's more complicated and there's no built-in solution: you'll need to write a custom module to read/write the state files and use file widgets to display the file browser.

Thank you jean-emmanuel,
I supposed that. I am fiddling around with saving/loading state. I try to do the following:

Save Button 1:
var state = stateGet("root")
storage.setItem("p001", state)
Load Button 1:
storage.getItem("p001")

Save Button 2:
var state = stateGet("root")
storage.setItem("p002", state)
Load Button 2:
storage.getItem("p002")

I save a state with save button 1, I save an other state with save button 2. My assumption is, when I press load button 1, it recalls p001 and when I press load button 2, it recalls p002.
But whatever load button I press, it loads the p001 saved state.
Thanks in advance :slight_smile:

Are you calling stateSet(state) at some point ? (uploading your session may help spotting the issue)

Yes I tried: stateSet(storage.getItem("p001")) / stateSet(storage.getItem("p002")) for the load buttons, but no luck...

Now, it works :slight_smile: I had a typo in the load button script :slight_smile:

Still fiddling around with state file saving. I found an example in the documentation for a custom module:

var fs = nativeRequire('fs')
module.exports = {
oscOutFilter:function(data){
// Filter outgoing osc messages
var {address, args, host, port} = data
if (address === '/file') {
fs.readFile(args[0].value, 'utf8' , (err, data) => {
if (err) {
console.error(err)
return
}
receive('/html', data)
})
return // bypass original message
}
// return data if you want the message to be processed
return {address, args, host, port}
}
}

At the end of the script it returns an array (return {address, args, host, port}). My question is, how do I access it from the editor? For example: I read a state file in with this custom module, I would like then to have a text widget which diplays the filename.

Thanks in advance for your support. :grinning:

hi sorry for bumping an old thread, but did you get anywhere with this? Trying to achieve the same thing :sweat_smile:

im gonna bump this