Dynamic use of port setting

Hello,

is there a way to be able to use dynamically the port number?

What I need is one single place where to set the port (either in a json config file or in the OSC config) that I can use to set the port to each widget declared in the UI statically and the ones created from the custom modules.

Is there a way to access the default port from the target attribute of the UI? (if I leave it blank it does not work)
And from the source code?

thanks in advance

I assume by port you mean midi port as created with the server's midi option. You could retrieve the server's midi option in the custom module a do what you want with the port names:

var midiports = settings.read('midi') // read server's midi option
                            .filter(x => x.includes(':')) // keep only port declarations
                            .map(x => x.split(':')[0]) // keep only port names

Would that help ?

Is there a way to access the default port from the target attribute of the UI? (if I leave it blank it does not work)

I'm not sure to understand, but when the target is left blank, widgets will only send message if a default target is set using the server's "send" option. Since the "send" option affects all widgets, the ignoreDefault property can be used to ignore the default target(s).

And from the source code?

No sure to understand either, I mean you could change everything from the source code :slight_smile:

1 Like

Thanks for the answer but I was referring to the port number
I assume there is also a way to access this?

What I want is that:
one can set for example 5100 and this will be automatically set for all the OSC actions that are declared in the UI, plus the ones generated via the code is ok I know how to do it

image
so in the UI instead of declaring the target like this, let him use the one set in the config

Hope is more clear

You could create a variable widget to hold that number, define the widget's target as "localhost:@{variable_id}" and feed the variable from the custom module when the session is loaded:

var port = 5000 // or maybe var port = require('config.js').port 
app.on('sessionOpened', ()=>{
  receive('/variable_address', port)
})

Great!
I did not think at the receive, now you opened a new world of editing variables :slight_smile:

so in the end one can change the port by:

  1. setting it first in the start up window
  2. setting in a json config file that will be cascaded in all the widgets

Is there any way to access the value set in the startup of the server so that it can be edited in just one place?

above you showed this code
var midiports = settings.read('midi')

is there a
var midiports = settings.read('port') ?

what is the variable settings?

thanks :slight_smile:

settings.read('send')

Settings can be accessed by the name used in the server config.

1 Like