Send OSC with multiple values

I have devices that requires OSC message:

/$index/set/color min max val

For example:

/5/set/color 0 100 0
/5/set/color 0 100 50
/5/set/color 0 100 100

In supercollider this works:

b.sendMsg("/"++15.rrand(0)++"/set/color",0,100,100.rrand(0));

In O-S-C can a button send this type of message?

Not sure how to send multiple values.

Did try to send the button on field to:

"on": "0 100 50"

Any example would be very greatly appreciated. Thanks.

Here is my test (I cannot upload files due to being a new user):

{
  "createdWith": "Open Stage Control",
  "version": "1.25.0",
  "type": "session",
  "content": {
    "type": "root",
    "lock": false,
    "id": "root",
    "visible": true,
    "interaction": true,
    "comments": "",
    "width": "auto",
    "height": "auto",
    "colorText": "auto",
    "colorWidget": "auto",
    "alphaFillOn": "auto",
    "borderRadius": "auto",
    "padding": "auto",
    "html": "",
    "css": "",
    "colorBg": "auto",
    "layout": "default",
    "justify": "start",
    "gridTemplate": "",
    "contain": true,
    "scroll": true,
    "innerPadding": true,
    "tabsPosition": "top",
    "hideMenu": false,
    "variables": "@{parent.variables}",
    "traversing": false,
    "value": "",
    "default": "",
    "linkId": "",
    "address": "auto",
    "preArgs": "",
    "typeTags": "",
    "decimals": 2,
    "target": "",
    "ignoreDefaults": false,
    "bypass": false,
    "onCreate": "",
    "onValue": "",
    "widgets": [
      {
        "type": "button",
        "top": 100,
        "left": 100,
        "lock": false,
        "id": "button_1",
        "visible": true,
        "interaction": true,
        "comments": "",
        "width": "auto",
        "height": "auto",
        "expand": "false",
        "colorText": "auto",
        "colorWidget": "auto",
        "colorStroke": "auto",
        "colorFill": "auto",
        "alphaStroke": "auto",
        "alphaFillOff": "auto",
        "alphaFillOn": "auto",
        "lineWidth": "auto",
        "borderRadius": "auto",
        "padding": "auto",
        "html": "",
        "css": "",
        "colorTextOn": "auto",
        "label": "auto",
        "vertical": false,
        "wrap": false,
        "on": "0 100 50",
        "off": null,
        "mode": "tap",
        "doubleTap": false,
        "decoupled": false,
        "value": "",
        "default": "",
        "linkId": "qqq",
        "address": "/5",
        "preArgs": "/set/color",
        "typeTags": "",
        "decimals": 2,
        "target": "",
        "ignoreDefaults": false,
        "bypass": false,
        "onCreate": "",
        "onValue": ""
      },
      {
        "type": "text",
        "top": 150,
        "left": 220,
        "lock": false,
        "id": "textarea_1",
        "visible": true,
        "comments": "",
        "width": "auto",
        "height": "auto",
        "expand": "false",
        "colorText": "auto",
        "colorWidget": "auto",
        "colorStroke": "auto",
        "colorFill": "auto",
        "alphaStroke": "auto",
        "alphaFillOff": "auto",
        "alphaFillOn": "auto",
        "lineWidth": "auto",
        "borderRadius": "auto",
        "padding": "auto",
        "html": "",
        "css": "",
        "value": "",
        "default": "",
        "linkId": "qqq",
        "address": "/string1",
        "preArgs": "",
        "decimals": 2,
        "target": "",
        "onCreate": "",
        "onValue": "",
        "vertical": false,
        "wrap": false,
        "align": "center"
      },
      {
        "type": "button",
        "top": 180,
        "left": 100,
        "lock": false,
        "id": "button_2",
        "visible": true,
        "interaction": true,
        "comments": "",
        "width": "auto",
        "height": "auto",
        "expand": "false",
        "colorText": "auto",
        "colorWidget": "auto",
        "colorStroke": "auto",
        "colorFill": "auto",
        "alphaStroke": "auto",
        "alphaFillOff": "auto",
        "alphaFillOn": "auto",
        "lineWidth": "auto",
        "borderRadius": "auto",
        "padding": "auto",
        "html": "",
        "css": "",
        "colorTextOn": "auto",
        "label": "auto",
        "vertical": false,
        "wrap": false,
        "on": "0 100 100",
        "off": null,
        "mode": "tap",
        "doubleTap": false,
        "decoupled": false,
        "value": "",
        "default": "",
        "linkId": "qqq",
        "address": "/5",
        "preArgs": "/set/color",
        "typeTags": "",
        "decimals": 2,
        "target": "",
        "ignoreDefaults": false,
        "bypass": false,
        "onCreate": "",
        "onValue": ""
      }
    ],
    "tabs": []
  }
}

Aha, I worked it out! Sent an array with this syntax:

"on": [0,100,50]

Now I need to send a random number as the third value.
Is it possible to mix in some JS or is it much more complex?:

"on": [0,100,Math.round(Math.random()*101)]

Good job figuring it out !

To send random numbers you'll need to use scripting instead, try setting on to 1, off to 0, bypass to true (to prevent the default messages) and onValue to

if (value === 1) {
  send('/address', 0, 100, Math.round(Math.random()*101))
} else {
  // maybe something else when value === 0 (if the button is a push or a toggle
}
1 Like

Very nice, I am learning lots, thank you very much. The @ syntax works well too:

Advanced syntaxes should be avoided in scripts, write this instead:

send(getProp(this, 'address'), 0, 100, Math.round(Math.random()*101))
1 Like

Wow, thanks @jean-emmanuel, I missed that note! All of your hints are a great help in learning this.

Is it possible to move the random value to a variable widget? From reading the documentation, it looks like one should be able to create a variable widget, set the value of that to the Math.random...().

Then call the value as send(getProp(this, 'address'), 0, 100, @{variable_name}) from various buttons, but I cannot find any example. Is this even possible?

You could create a variable widget and assign a random value to it by setting its value property to
#{Math.random()} and use it in script (using get("variable_id") insted of @{variable_id}) but then the value wouldn't be randomized each time the script is called.

@jean-emmanuel you are a true wealth of information, thank you again.

That is such a shame, I was hoping to avoid code duplication within many buttons by using the variable as a pseudo-function.

I shall continue to read the forum and documentation, any further tid-bits of advice would be greatly appreciated.

I was hoping to avoid code duplication within many buttons by using the variable as a pseudo-function.

You could declare a global function in some widget's onCreate, just make sure it's located before any widget using it in the tree. It doesn't work well with the root's onCreate because this script is executed after children are created (I might need to add a special script to the root widget that really runs before any other widget is created).

// declare it once
globals.rrand = ()=>{
  return Math.round(Math.random() * 101))
}

// use it anywhere
console.log(globals.rrand())

(It's not possible to "smuggle" scripting functions such as send() into advanced syntax in regular properties using globals.)