Custom Module, Matrix labels

Hi there,

I'm trying to change buttons labels in a matrix, with a Custom Module.

Until now, it's working with buttons widgets. And i'm trying to use now a matrix.
Here's a part of the code, working with button's widgets :

ConstruisTaMap().then(cequilmefaut => {
        var buttons = {'b1': '/b1/show','b2': '/b2/show',....};
        var labels = {'b1': '/b1/label','b2': '/b2/label',....};
        var TousmesBoutons=mesArticulations.length;
        var labelTexts = Object.values(mesArticulations);                
        for (var i = 0 ; i<TousmesBoutons;i++)
            {
            var label = mesArticulations[i];
            receiveOsc({address: Object.values(buttons)[i], args: [{type: 'i', value: 1}]});
            receiveOsc({address: Object.values(labels)[i], args: [{type: 's', value: label}]});
            }

So, i tried a few thing, like :

receive('/EDIT', 'matrix_1', {'props': {'id':'b#{$+1}','label':labelTexts}});

Which returns, as expected, the whole array :
array

In the for loop, i tried to use [i], but as expected too, it can't work this way, it ends up showing only the last item in every buttons...

I tried to use matrix_1/INDEX as a children id in the receive function, as found somewhere here, but no result.
I tried using JS{} in the receive function :

receive('/EDIT', 'matrix_1', {'props': {JS{var props = {}....}});

But i have token errors...

So here am i... lost again... :woozy_face:

h.. e.. l.. p.. :upside_down_face: p.. l.. e.. a.. s.. e..

This can't work, the JS{} syntax is not pure javascript and will fail in a custom module, unless you make sure to send it as string:

receive('/EDIT', 'matrix_1', {'props': `
JS{
var props = {}
// ...
return props
`})

I tried to use matrix_1/INDEX as a children id in the receive function, as found somewhere here, but no result.

It works, but if you override the id in the matrix' props, then you have to use whatever id you defined.

Gosh... So, i was just missing the backticks... :crazy_face:

Thank you !

One more step to go...
I'm not so far to get what i want...
But i'm missing stg to redistribute labels..

So, i'm here :

 receive('/EDIT', 'matrix_1', {'props': `JS{
                var props={}
                let Index=parseInt($)+1
                props.id="b"+Index
                var labs = "` + mesArticulations + `"
                props.label= labs[$]
               ...
                return props
                }`});

Trying to get the good stuff, i could have returned in the props :

var labs = "a,b,c,d"

or

var labs = [a,b,c,d]

or

var labs = ["a,b,c,d"]

Which gives some funny results... by the way...

But still not

var labs = ["a","b","c","d"]

I've console.logged 'mesArticulations', and it's well returned as ['a','b',...]

What am i missing there ?

`
var labs = ${JSON.stringify(mesArticulations)}
`

${} is used to avoid closing and opening the string (see template litterals) it has nothing to do with the other widget advanced syntaxes like @{}.

Thank you very much.

Ok, so... sorry... it's so frustrating to be asking for help at each step... Trying, searching, reading... and still have to ask for help...

I'm now trying to hide the unused buttons in my matrix. As i only need the "labeled ones" (how many : depends on selected track in Cubase), i'm trying to compare Index value, and length of my labels array... And as you know... not working...

I tried again a lot of things... using #_{}, or #{}... and so many others...
I tried to use typeTags too... but not sure how to do

Now i stay with this non-working thing :

                var props={}
                let Index=parseInt($)+1
                props.id="b"+Index
                var labs = ${JSON.stringify(mesArticulations)} 
                props.label= labs[$]
                var max = labs.length
                props.visible = "#_{@_{Index} > @{max} ? 'false':'true'}"

Is the idea correct, or am i absolutely on a wrong way ?...

Kind of, what you're doing is possible but requires a good understanding of the different executions scopes for your scripts, here you have many levels of execution:

  • the custom module
  • the JS{} block
  • the #_{} block

These scopes are all different and cannot access each other's variables at runtime, for instance Index is not defined when props.visible is resolved by each widget in the matrix. Also, @{max} will attempt to return the value of widget with id max, it cannot be used to retreive the variable named max defined on previous line.
This would probably work better, but I didn't test it:

props.visible = Index > max ? false : true
// or even simpler
// props.visible = Index <= max // returns true or false

simpler as you might think actually !

OMG.... :upside_down_face: :partying_face: :crazy_face:

Both solutions are perfect ! Thank you... again :smiley:

1 Like