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)
}
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.
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
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 ?
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