2D array in Matrix button

Hi,

I'm using a dropdown menu to change the label of a matrix button using a 2d array
But When the first and second array has the first same name( in this case "Hz"), the dropdown menu is no more able to change the array.
Is it a commun restriction ?

Best

2D-array.json (5.8 KB)

JS{{
var props = {}
var cc = [10,11,12,13,14,15,16,17]
var names = [
["Hz","Rez","Hz Attack","Delay","Porta Time","Unison","Reverb","Volume"],
["Hz Cut", "Rez", "Echo", "Reverb", "Attack", "Release", "Wave Position", "Unison"],
["Hz", "Filter Decay", "Filter Release", "Amp Release", "Reverb Decay", "Reverb Freeze", "WReverb HiShelf", "Reverb Dry/Wet"]
]
var defaults = [
[52,53,69,38,62,116,43,107],
[31,31,23,16,11,58, 59,11],
[0,0,111,119,85,0,90,51]
]

props.html = names[@{dropdown_@{parent.variables.device}_instrument}-1][$]
props.alphaFillOn = 1
props.default = defaults[@{dropdown_@{parent.variables.device}_instrument}-1][$]
props.range =  { "min": 0,"max": 127}
props.doubleTap = true
props.address =  "/control"
props.preArgs = [@{variable_@{parent.variables.device}_mc}, cc[$]+(8*(@{dropdown_@{parent.variables.device}_instrument}-1))]
props.target = @{variable_midi_port}
return props
}}

With this code I have incoming error message

matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '0' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '0' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '1' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '2' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '3' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '4' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '5' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '6' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '7' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '0' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '7' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '6' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '5' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '4' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '3' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '2' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '1' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '0' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '0' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '0' of undefined
matrix_minilab_macro.props JS{{}} error at line 14: TypeError: Cannot read property '0' of undefined

Is it possible to set every button to it's defaults position each time I select an instrument in the dropdown menu

something like :

props.script = set('matrix_id/*', 0)

I didn't manage to find the solution for this one :confused:

There no such restriction in javascript, the error only happens when the dropdown's value is undefined. You can avoid that by defining the index with a fallback:

var index = @{dropdown_@{parent.variables.device}_instrument} || 0

something like :
props.script = set('matrix_id/*', 0)

Exactly, but since you want that to happen when the dropdown updates, you just have to write the "set()" part in its script property (with the appropriate matrix id of course).

thank you the var index worked well.

so I set the dropdown menu's script with : but nothing happen

var defaults = [
[52,53,69,38,62,116,43,107],
[31,31,23,16,11,58, 59,11],
[0,0,111,119,85,0,90,51]
]
if (@{this.value == 1}) set('@{matrix_@{parent.variables.device}_macro}/*', defaults[1][$])
if (@{this.value == 2}) set('@{matrix_@{parent.variables.device}_macro}/*', defaults[2][$])
if (@{this.value == 3}) set('@{matrix_@{parent.variables.device}_macro}/*', defaults[3][$])

You can't dispatch different values to multiple widgets with set(). On a sidenote, you should not use @{] in a script.

1 Like

What you could do however is load a state object:

var state = {
  'widget_id1': 1,
  'widget_id2': 2,
}
stateSet(state)

(this is a very basic example, to be extended to your needs)

isn't it `stateSet(state) ?
I should use this in the dropdown menu ?
Btw I think it's too complicated for my current knowledge

My bad, post edited.

1 Like

Hey
I came back to open stage after a small break and my 2d array which was working fine is now broken.
Looking to the update log to see what has changed since my last connection ...

JS{{
var props = {}
var cc = [5,6,7,8,9,10,11,12]
var names = [
["Hz","Rez","Tone","Drive","Time","Glide","Delay","Sub Chain"],
["Hz","Rez","Resonate","RvB Amount","Attack","Decay","RvB Time","Volume"],
["RvB","Rvb Time","Tone","Release Volume","Key Noise","Sustain Noise","Fine Tune","Velocity Sens"],
["Sub","Osc2 Pos","FM","Drive","Low Hz","Hi Hz","Unison Amount","Release"],
["Hz", "Rez", "Env Amount", "Env Decay", "Colour", "Distort", "Fold", "Volume"]
]

var defaults = [
[31,88,127,74,63,0,9,50],
[45,94,36,27,0,62,65,89],
[0,87,64,52,63,88,63,79],
[0,0,0,0,0,127,0,0],
[41, 26, 66, 66, 29, 39, 0, 107]
]

var index = @{dropdown_@{parent.variables.device}_instrument} || 1

props.html = names[index-1][$]
props.alphaFillOn = 1
props.default = defaults[index-1][$]
props.range =  { "min": 0,"max": 127}
props.doubleTap = true
props.address =  "/control"
props.preArgs = [@{variable_@{parent.variables.device}_mc}, cc[$]+(8*(@{dropdown_@{parent.variables.device}_instrument}-1))]
props.target = @{variable_midi_port}
return props
}}

2D_Array.json (6.2 KB)

Your file upload didn't work. Copy-pasting your code and manually setting the index variable seems to work though.

I re uploaded the file I search in the update change log didn't find something

I found it, the fix is in sources.

je don't get it ? c'est un bug ou ... ?

Yes, it's a regression in v1.9.8 caused by this change:

matrix: update children when props is modified even when the result for $ = 0 doesn't change

so will wait for the correction ^^'

thank you for 1.9.10 :slight_smile: