Sending multiple messages inside matrix

Hi everyone !

Getting back into using a matrix after a while.

I currently have these simple buttons set up:

I would like each of the buttons to send multiple messages as follow:

//for "CHECK" button 1
send("midi:my_midi_device", "/control", 1, 15, 2)
send("midi:my_midi_device", "/control", 1, 47, 67)
send("midi:my_midi_device", "/control", 1, 15, 2)
send("midi:my_midi_device", "/control", 1, 47, 3)
//For "CHECK" button 2
send("midi:my_midi_device", "/control", 2, 36, 5)
send("midi:my_midi_device", "/control", 2, 12, 3)
send("midi:my_midi_device", "/control", 2, 24, 10)
send("midi:my_midi_device", "/control", 2, 17, 27)

etc...

My current props is:

JS{{
var props = {}
var labels = ["CHECK"]
var colors = ["purple"]

props.mode = "toggle"
props.label = labels
props.colorWidget = colors

props.address = "/control"
props.preArgs = ???
props.target = "midi:my_midi_device"

return props
}}

I tried to create a variable for the preArgs but couldn't find a way to make it happen.

Any ideas ?

Since the scripts look a bit long, I suggest you use the matrix' onValue script directly:

var index = getIndex(id)
if (index === 0) { // first button
  // send some messages
} else if (index === 1) { // second button
  // send some other messages
} // etc
1 Like

Wonderful, thank you @jean-emmanuel !

I have a question following that, in the case where there is just 2 buttons as followed to make it simple:
Screenshot 2022-09-18

I was able to switch between button_0 and button_1 with:

var index = getIndex(id)
if (index === 0) { // first button
set ("matrix_widget/0", 1)
set ("matrix_widget/1", 0)
} else if (index === 1) { // second button
set ("matrix_widget/0", 0)
set ("matrix_widget/1", 1)
} // etc...

How can I unselect button_0 when I select it again like a toggle button ?
In other words I guess something like returning its value to 0 ?

props.mode = "toggle" is already applied.

A matrix is quite challenging but interesting :grinning:

If you want the buttons to be exclusive, put this in the props (this bit won't work in the matrx' onValue);

props.onValue =  `set('matrix_widget/*', 0, {sync:false})`

and only do the message sending in the matrix' onValue.

1 Like