Sending color to a button

Hi, there are multiple issues here:

  • the button’s address is meant to receive either its on or its off value, not arbitrary string values. What you need to use is the osc listener syntax which is slightly different than the inheritance syntax (ie @{widget_id.property_name}).
  • your javascript code inside the #{} is not valid: @{} blocks only work if written according to the rules defined in the documentation, it looks like you wrote a mix of javascript object notatation and OSC’s inheritance syntax.

Here is a working snippet:

JS{{
var buttonState = OSC{/loop/0/01/rec};
var colors = {"cleared": "#222222", "play": "#00FF00", "rec": "#FF0000", "willPlay": "#004400", "willRec": "#440000"}

return colors[buttonState] || "auto"
}}

Note that colorBg has been removed from non-container widgets in v1.5.0, but you can still use the code in colorWidget for example, or use it to change the widget’s background color with css:

JS{{
var buttonState = OSC{/loop/0/01/rec};
var colors = {"cleared": "#222222", "play": "#00FF00", "rec": "#FF0000", "willPlay": "#004400", "willRec": "#440000"}

return "background-color:" + (colors[buttonState] || "auto") +';'
}}
3 Likes