Hello,
I'm using the custom-module made by Jean-Emmanuel (GitHub - jean-emmanuel/osc-state-example) and it's working perfectly.
But now I would like to make it able to only load certain parameters (define in the onValue script of the load button), and I can't figure out how to do that.
I have already asked ChatGPT, but I always get the same problem : all the state is load.
Here is the onValue script on the save button :
var slot = get('slot_switch');
if (slot) {
var state = {};
// Liste des paramètres à enregistrer
var selectedParameters = ['xmin_input', 'xmax_input', 'ymin_input', 'ymax_input', 'number_track']
// Enregistrez seulement les données sélectionnées dans l'objet state
Object.assign(state, stateGet(selectedParameters));
send('custom:module', '/state/save', slot, state);
}
The onValue script of the load button :
// get current slot
var slot = get('slot_switch')
if (slot) {
var selectedParameter = 'xmin_input';
send('custom:module', '/state/load', slot, selectedParameter);
}
And the load function of the custom module :
// function for sending a state to all clients
// if provided slot name exists
function loadState(name, selectedParameters) {
if (name in states) {
var specificState = {};
if (selectedParameters && selectedParameters.length > 0) {
// Si des paramètres spécifiques sont fournis, filtrer le state
selectedParameters.forEach(param => {
if (states[name][param] !== undefined) {
specificState[param] = states[name][param];
} else {
console.log(`Parameter ${param} not found in state ${name}`);
}
});
console.log(`Sending specific parameters for ${name}:`, specificState);
// Envoyer uniquement les paramètres spécifiés
receive('/STATE/SET', specificState);
} else {
// Si aucun paramètre spécifique n'est fourni, envoyer l'ensemble du state
console.log(`Sending entire state for ${name}:`, states[name]);
receive('/STATE/SET', states[name]);
}
} else {
console.log(`State ${name} not found`);
}
}
Any suggestions ?
Achille