Hi,
It feels like only yesterday I was on this forum, and I too knew very little about coding. I definitely have to thank OSC as it gets you motivated to learn coding to take your OSC to the next level.
Saving JSON
If you're getting the values already from the folder(s) toggles you created, on the widget, you could use the OnValue
to send the value to an address of your choosing.
// value is a local variable that grabs the current value of the widget
// id is a local variable that grabs the current id of the widget
send("/testing", {type: "s", value: {value, id}})
In your custom module js file, under the method oscFilterOut
in the module.exports
, you'll need to listen for your custom address, to grab that data, and save it to your JSON file using saveJSON.
// Filter outgoing osc messages
const { address, args, host, port, clientId } = data
if (address === "/toggleFolderAddress") {
let value = args[0].value.value
let nameOfFolder = args[0].value.id
let saveToggleValue = {}
saveToggleValue[nameOfFolder] = value
// saveJSON(pathToYourJSONFile, dataObject)
saveJSON("./toggleFolder.json", saveToggleValue)
}
Load JSON
In your custom module, at the start of the session, you could load the json data into a variable to use. Then for each id saved, you could send a receive to the value of each widget.
app.on("sessionOpened", () => {
let toggleFolderJSON = loadJSON("./toggleFolder.json")
// iterate over each key value pair in the object
Object.keys(toggleFolderJSON).forEach((key) => {
let id = key
let value = toggleFolderJSON[key]
receive(`/${id}`, value)
})
})
Then at the start of your OSC session, the values will be read from the JSON file, and sent to each button.