Dropdown values set by osc

Hi,

I'm stuck on this one. I wish to set values of a dropdown menu with the name of source from software.

so for this I need to send in a loop of number of source a message like this

send('/adm/obj/'+i+'/name/?')

and then output the name I get from this message to set the dropdown values.
But I'm not able to send this message as I get an error "send is not defined"

JS{
var n_values = OSC{/global/project/adm/obj/count} || 12
var values = {}

for (var i = 0; i < n_values; i++){
  console.log(i)
  return values = {"test" : i }
 }
console.log(n_values)
}

Where are you calling send() from ? It can only be called in scripting properties.

inside the values property
I looked at some thread in the forum and saw it was possible to send inside values
but maybe it's no more possible ?

dropdownValues.json (3.6 KB)

It has never been possible, sorry.

ok I think it's was thread before the implementation of onValue / onCreate
my bad, so I even more stuck than before

at least for my knowledge what would be the correct syntax to set the values with

{"test 1" : 1, "test 2": 2 ...}

using a loop ?

Something like this would do

var values = {}
for (var i = 0; i < 5; i++) {
  values['test ' + i] = i
}

Reference: Working with objects - JavaScript | MDN


You can't use send() in a script and use an hypothetical osc response on the next line (send() doesn't "return" anything), you have to listen to that response somehow (using a widget) and then decide what to do with it.

1 Like

thank you
I have to found a solution, when I'll do will post, maybe it will help somebody else.

well I tried to found a solution, and for now I have to do it using static solution. With that solution I'm able to get the name but the dropdown is stuck to first value when selecting

JS{
var n_values = OSC{/global/project/adm/obj/count} || 16
var values = {}


var name1 = OSC{/adm/obj/1/name}
var name2 = OSC{/adm/obj/2/name}
var name3 = OSC{/adm/obj/3/name}
var name4 = OSC{/adm/obj/4/name}
var name5 = OSC{/adm/obj/5/name}

for (var i = 0; i < n_values; i++) {
 values[name1] = i
 values[name2] = i
 values[name3] = i
 values[name4] = i
 values[name5] = i
 
}
return values
}

@jean-emmanuel Could it be possible to add the possibility to use inside a JS{} using OSC{} a concatenation like '+i+' in the message ?

No it's not possible, the OSC{} block is parsed before the JS{} block and can't use javascript itself. I'd recommend writing a custom module to handle these messages, store the values and update the widgets accordingly. However if you really want to keep in in the session you could try creating a variable matrix to receive all these messages, with quantity set to the maximum number of possible values and props to

{
  "address": "/adm/obj/#{$ + 1}/name"
  "id": "name_#{$ + 1}"
}

then you should be able to loop over these variables with something like:

for (var i = 0; i < n_values; i++) {
  var name = get('name_' + (i + 1))
  values[name] = i
}

so I managed to get the variable's matrix working,
but when I set the dropdown menu with :

JS{
var n_values = OSC{/global/project/adm/obj/count} || 16
for (var i = 0; i < n_values; i++) {
  var name = get('name_' + (i + 1))
  values[name] = i
 }
}

but I get the in the console (get is undefined)

so I tried to get the value from my variable matrix in a matrix button with :

JS{
  var props = {};
  var index = $+1
   

  
  props.label = "@{name_#{$ + 1}}"

  console.log(@{name_1})
  return props
}

but it seems that I didn't managed to use the index to increment (I did a lot of test using different syntax)
what am I doing wrong ?

dropdownValues2.json (8.5 KB)

[...] but I get the in the console (get is undefined)

The example code I posted will indeed only work in a scripting property such as onValue.

what am I doing wrong ?

It's not possible to use the #{} syntax nested in a @{} block.

ok so this is a solution for this problem, using two variables one matrix of variables, the quantity of variables inside the matrix is set dynamically by the number of sources. (received by an OSC message)
Unfortunately it can be used for my setup

hope it can help someone one day !!

dropdownValues2.json (11.3 KB)

2 Likes