Add Buttons Dynamically

I'd like to add buttons dynamically to a panel. Basically read a JSON file at startup and add the buttons - i.e. specify the id and add a function to each one.

Is this possible.

Thanks

That'd be using a custom module and the /EDIT command to :

var data = loadJSON('widget-data.json')

// assuming data is an object with the default properties for a button
// create a list of buttons that derivate from it

var buttonList = [
    {
        ...data,
        id: 'dynbutton_1',
        colorWidget: 'red'
    },
    {
        ...data,
        id: 'dynbutton_2',
        colorWidget: 'cyan'
    },
    // etc
]

app.on('sessionOpened', function(data, client) {
    // event triggered when a client finished loading a session

    receive('/EDIT', 'panel_id',
        {widgets: buttonList}, // replace content of panel (note: must not contain tabs)
        {noWarning: true}, // prevent "unsaved changes prompt"
        {clientId: client.id} // send command only to the client that just connected 
    )

})

module.exports = {
    // here go the osc filtering functions if needed
}
1 Like