Is there a way to only update some variables of a cloned control

So I’ve been playing with cloned controls and for the life of me can’t figure out a way to update some but not all values on a cloned control.

For example let’s say I had the following definition on a hidden tab that I plan on using as a template for multiple cloned controls on other tabs of the UI. (I’ve stripped irrelevant properties for clarity).
{
“type”: “panel”,
“id”: “pan_fader_volume”,
“variables”: {
“cc”: 0,
“channel”: “@{parent.variables.channel}”,
“default”: 63,
“max”: 127,
“min”: 0,
“name”: “Fader”,
“target”: “@{parent.variables.target}”
}
}

If I I clone this into another tab without any changes it works as expected and I can send midi messages no problem via a fader I have inside of the widgets of this control. I based my logic on the example available at

However, every single clone will reference the exact same variables. Not a problem I think, I’ll just define my overrides in the props and everything should work as expected.

{
“type” : “clone”,
“widgetId” : “pan_fader_volume”,
“id” : “gainVolume”,
“props”: {
“variables” : {
“name” : “Master Gain”
}
}

With these props I’m expecting the variables in my cloned control when evaluated to look like:
“variables”: {
“cc”: 0,
“channel”: “1”,
“default”: 63,
“max”: 127,
“min”: 0,
“name”: “Master Gain”,
“target”: “midi:mymid”
}

Instead it appears that I end up with:
“variables”: {
“name”: “Master Gain”
}

I get why what I’m doing won’t work. What I’m hoping to find out if there is some kind of alternative formatting or scripting I could employ to get the result I’m expecting.

I understand that it might not be possible to do a deep merge of the objects. In such a case I’d be curious if an alternative syntax is available or could be employed to single out a specific nested property. Something like one of the following:

“props”: {
“variables.name” : “Master Gain”,
“variables[‘name’]” : “Master Gain”
}

I’d be fine employing a little scripting as well to get around it, but I’m trying to keep my configs as light as possible. I’d really rather avoid having to redefine all my variables for every object and have random things break when I forget.

Thanks

If I understand corrctly, this is what you’re looking for: How to inherit @{parent.variables} and add new variables

I wasn't allowed to upload so I've attached my full config to a Gist

This exhibits the same problem.
I tried using

        "props": {
          "variables": "#{Object.assign(@{this.variables}, {name: \"Pre Gain\"})}"
        }

as well but that didn't work. My problem is the variables I want to reference aren't on the parent but rather the control I am cloning. I am also referencing variables from my the parent, but pulling and updating variables from the clone would be more useful.

This works:

{
  "variables": #{
     Object.assign(@{pan_fader_volume.variables}, {
       color: "cyan", 
       name: "Test",
       target: @{parent.variables.target},
       channel: @{parent.variables.channel}
     })
   }
}
  • escaping the double quotes in the #{} block results in a syntax error
  • the #{} block should not be enquoted here since it return a json object (edit: that’s true only in the editor, in the session file the quotations mark will indeed end up escaped)
  • the @{} calls in the template widgets are resolved before the cloning happens, they can’t be resolved dynamically depending on where the clone is (hence the manual override for target & channel here

This sheds some light on the current clone logic’s limitation, I’ll keep that in mind next time I work on this part of O-S-C.

Tried the snippet you sent and got it working. Yeah I was trying to edit in this in VS code which is why I had some of the bad syntax. I’ll keep that in mind in the future.

Thanks

Just an FYI I found something slightly better:

{
"variables": #{
Object.assign(@{pan_fader_volume.variables}, @{parent.variables}, {name:"In Gain", cc:2})
}
}

Doing this I can merge both the variables of the object I'm inheriting from, the parent's variables, and add my own custom variables. It' not perfect, but it shoul still cut down on a good amount of copy and paste.

1 Like