Using a function to translate incoming Velocity messages (MIDI) , to some widget parameters

Hi there,

So after being succesfull making my first replica of a MIDI controller , a BCR2000 behringer, I'm trying to make other virtual replica now of a Novation-Launchpad.

(skip next 2 paragraphs to skip intro)

This one is a bit more tricky, as it has LED's on it that respond to MIDI in messages in the device.
Basically for each Note in that receive the device from the in port, the Note Pitch will determine which pad will be turned on.

The Velocity will correspond to the way these LED's will behave, so the Launchpad is got 2 LED's per PAD (1 Red and 1 Green) and it's got 4 different intensities.
Without getting much into details about the way this internally work ( more info: https://fael-downloads-prod.focusrite.com/customer/prod/s3fs-public/novation/downloads/4700/launchpad-s-prm.pdf)

So basically I need to write a function to translate the velocity values to adjust the LED's widget in a certain way such as:

For Velocity = 15 = "colorWidget": "rgba(253,109,109"
For Velocity = 60 = "colorWidget": "rgba( 0 , 253 , 0)"

Something like that
I am aware I can create the widget the following way

led
        mode: color
        range {
                "min": 0,
                "max": 127
              }
        value : [r, g, 0]
        address: /note
        preArgs: [1, 0]
        target: midi:virtual-launchpad

I'm not really sure of how I can continue

Has anyone done something similar?

Thanks!!

I'm getting closer to my objective.

As per : Sending color to a button - #2 by jean-emmanuel

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

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

I can adapt this to do my own such as

JS{{
var velocityReceived = OSC{/note};
var colors = { 12: "#000000", 13: "#5f0000", 14: "#af0000" 15: "##ff0000" 29: "#ffdf00" 46: "#808000" 63: "#ffffaf" 28: "#005f0" 44: "#00af00" 60: "#00ff87" }

return colors[velocityReceived] || "#000000";
}}

And embedding that in the properties object on the .JSON file it would be

        "type": "button",
        "top": 40,
        "left": 10,
        "id": "1-1",
        "visible": true,
        "interaction": true,
        "width": 80,
        "height": 50,
        "expand": "false",
        "colorText": "auto",
        "colorWidget": "JS{{\n\nvar velocityReceived = OSC{/note};\nvar colors = { 12: "#000000", 13: "#5f0000", 14: "#af0000" 15: "##ff0000" 29: "#ffdf00" 46: "#808000" 63: "#ffffaf" 28: "#005f0" 44: "#00af00" 60: "#00ff87" }\nreturn colors[velocityReceived] || "#000000";\n\n}}",

But it is not working

Could not open file(SyntaxError: Unexpected token # in JSON at position 1105)

Quite strange cause line 1105 I got

        "colorStroke": "auto",

I know the syntax may be not correct, but I don't understand the error message

The json error is due to the double quotes not being escaped with a backslash and thus breaking the json syntax. Good job on learning the advanced syntaxes :+1:

1 Like