Xy pad to knob filtered by a dropdown

Hello,
I want to send xy values separately to my knobs by filtering them according to the selection of a dropdown widget to control different parts of a synth.
What is the best way to do this? JS, Script?
In the dropdown ? something like :
If dropdown_1 = LFO-Vibrato, send {xy_FM8}[0]} to Vibrato_knob, else if etc..
or in each knob
If dropdown_1 == LFO-Vibrato, receive {xy_FM8}[0]}, else if etc..

Can someone show me the way to do this
FM8

Here is a demo: xy_and_knobs.json (8.5 KB)
The xy updates the knobs using its script property and read the dropdown's state to determine which knobs should be affected. The knobs and the dropdown are all linked to a script widget that reads the dropdown's state and merges the selected knobs' values to update the xy.

See also

Thanks @jean-emmanuel , it works great.
As I use 2 differents dropdown for X and Y targets on 11 knobs, I change the script in XY widget like this :

var choice = get('dropdown_1')
if (choice == 1) { set('knob_1', value[0]) } else if (choice == 2) { set('knob_2', value[0]) } //etc..

var choice = get('dropdown_2')
if (choice == 1) { set('knob_1', value[1]) } else if (choice == 2) { set('knob_2', value[1]) } // etc..

For the script widget "knobs_to_xy" I modified with this code to be able to manage separately X and Y.
I don't know if it's very ortodox! but it works ! :grinning:

var choice = get('dropdown_1')
if (choice == 1) { set('xy_1', [get('knob_1'),'']) } else if (choice == 2) { set('xy_1', [get('knob_2'),'']) } // etc.. 
var choice = get('dropdown_2')
if (choice == 1) { set('xy_1', ['',get('knob_1')]) } else if (choice == 2) { set('xy_1', ['',get('knob_2')]) } // etc..

@jean-emmanuel I've been looking at your demo and I have a couple of questions. I've removed everything except the xy and two faders. They aren't linked and there's no script widget. For learning purposes.

Putting this in the script property of the xy works

set('fader_1', value[0])
set('fader_2', value[1])

produces this

working

Putting this on a button happily resets the xy

set('xy_1', [0, 0]) 

But none of the following on a fader/knob update the xy without linkIDs and a script widget (as per your post).

set('xy_1', [get('fader_1'), get('fader_2')])
set('xy_1', [get('fader_1'), 1])
set('xy_1', [this, 1])
set('xy_1', [value, 1])  
set('xy_1', [value, value])  

Just wondering why not? I assume it's the missing linkIDs, but I can't work out why a button works without linking, but a fader/knob doesn't.

Thank you for your patience.

Actually it's just a bug that prevents set() from working from a slider to a pad. I fixed yesterday.

Haha, that's hilarious. I spent quite some time making sure I hadn't made any schoolboy errors!

I'm slowly getting there...

This however is kind of wrong : set('xy_1', [this, 1])
(the variable this is null here, usually in js it represents the execution context, but scripts are executed in a detached context in OSC. The use of "this" in the @{} syntax and in some scripting functions as a shortcut to "this widget's id" may be misleading, it's just a sementical convenience, not an actual object reference)

Ok, thank you for explaining. It's true that this is at times hard to decipher.

I think this also threw me a little

set(id, value, options) #

  • id : widget id as a string. Can be "this" to target the host widget, or "parent" to target the parent widget. id may contains wildcards ('*').

Just wondering what I need to do to make the faders trigger output from the xy when moving them?

These are on the faders
set('xy_1', [value, null])
set('xy_1', [null, value])
They have no targets as they are only being used to move the xy.

working

If the xy has a target you have nothing to do, it will send messages.