Receive MIDI, output OSC

How can I setup a button that toggles and outputs 1 or 0 to an osc target when it receives a specific noteOn midi message?

Widgets can't send message in reply to incoming messages, you'll need to write a custom module to do that, this example should help.

1 Like

I'll look into it, thanks!

hi everyone,

be indulgent it's my first try with custom modules :wink:

si i propose that

module.exports = {
    

	init: function()
	{
        console.log("Youpi init")		        // this will be executed once when the osc server starts
    },

    oscInFilter:function(data){
    // Filter incoming osc messages
    var {address, args, host, port} = data
    // do what you want
    // address = string
    // args = array of {value, type} objects
    // host = string
    // port = integer
    console.log("inside oscOutFilter")
    console.log(data)
    if (host === 'midi') {
 
        console.log(" midi détecté via la valeur de host !")
        console.log('adresse du message : ' + address)
        // on teste si c'est un message midi /note via la variable address
        // comparaison avec l'opérateur ===
        if(address === '/note'){

            // on dispatche les valeurs de args dans tes variables différentes
             // assign args to variables
             // https://openstagecontrol.ammd.net/docs/custom-module/examples/#midi-routing

            var [channel, ctrl, value] = args.map(arg=>arg.value)

                // simple condition
                // on my apc i press the button sending /note 1, 32, 127
                // when released sending /note 1, 32, 0

                if (ctrl === 32) 
        {               
                // receive('/button_1', value / 127)
                receive('/SET', 'button_1', value / 127)
                }
                else console.log('autre touche')
                
        }

            return // bypass original message


    }
    
    // return data if you want the message to be processed
    return {address, args, host, port}
    }
}

It will send an osc message /somewhere with value 1 when a push button is pressed on my apckey25 (Akai). This button is sending a /note 1, 32, 127 when pressed.

But i don't know how to keep the toggle button keep working...

I get also an error

(DEBUG, OSC) In:  { address: '/SET', args: [ 'button_1', 1 ] } From: undefined:undefined
(DEBUG, OSC) Out:  { address: '/somewhere', args: [ { type: 'f', value: 1 } ] } To: 127.0.0.1:4560

as you see a true newbie issue :slight_smile:

So there are the files :
first-custom-module.js (2.7 KB)
session-wip.json (1.9 KB)