On loading of template, send osc?

Is it possible to send an osc/midi command when loading/opening a template (before hitting any buttons etc, just load template and bam, command is sent)?

Something like --state ? https://openstagecontrol.ammd.net/docs/getting-started/#options

If you’re looking for a way to send arbitrary commands (not emitted by the widgets in your session), you need to write a custom module, here’s a basic example:

module.exports = {

    init: function(){

        // executed once when the server starts
        send('127.0.0.1', 5555, '/server/started')

        app.on('sessionOpened', (data, client)=>{

            // executed each time a session is opened
            // as from v0.44.0, this will only apply
            // for sessions loaded from the server's filesystem 
            
            send('127.0.0.1', 5555, '/session/opened', data.path)

        })

    }

}

https://openstagecontrol.ammd.net/docs/custom-module/

1 Like

Worked perfectly. Thank you!

Hi Jean,
I have only just started to look at OSC and I am really enjoying it

It has been many years since I did any Javascript, I have the app.on working perfectly to load control values on the main screen. Could you complete the example by showing how to do the same for when a modal dialogue opens from the modal control.

Many thanks

Hi, you’d handle that in the oscOutFilter function:


app.on('some-event', ()=>{
  // etc
})

module.exports = {

    init: function(){
        // executed when the server starts
    },

    oscOutFilter: function(data){

       var {address, args, host, port} = data

        // Assuming the modal's address is /modal_address
        if (address == '/modal_address' and args[0].value == 1) {
            send('127.0.0.1', 5555, '/modal_opened')

            return // empty return to bypass original osc message
        }

        return data

    }

}

Note that widgets must send an osc message to trigger this function (they need a target, or a global target set with the server send option).

Thanks, that is where I had got to but though there may be another solution.

A similar usage with a script widget was described here : Two or more osc address on a toggle button

Is there a way to send the server/started and session/opened messages without manually specifying the IP and port inside the custom-module file?

without manually specifying the IP and port

What do you mean ? What port and IP would you use ?

Sorry for the slow answer, I did not get a notification from the message.

I would like to use the same IP/port which is set in OSC and used by all the commands.
I just do not want to specify it inside the custom-module file as well, because that way everyone would need to modify the js file to set their own IPs.

In the custom module you can retreive the server's "send" options using like this:

var serverTargets = settings.read('send') // array of "ip:port" strings
var [host1, port1] = serverTargets[0].split(':')

Since v1.8.11 it's also possible to use a script widget with mode set to "once" to run a script when the widget is created.

1 Like