Change PreArg and or MidiTarget using Custom Module

Hi All,

Is there a way to use the custom module to define the prearg values in a say a slider widget?

I have a custom module that will amend the text on a button depending on what CC value it receives, but was wondering if I can use the same method to define which midi channel and CC, or even better, which midi target the slider sends on?

Yes, there are multiple ways to this.

  1. Using /EDIT command to change the widget’s properties:
receive('/EDIT', 'widget_id', {preArgs: [1], target: 'midi:device_name'})
  1. Using osc listeners in the widgets properties and updating them from the custom modulle:
// assuming a widget's target is: OSC{/widget_target, midi:a, false}
receive('/widget_target', 'midi:b')
  1. Doing the routing dynamically from the custom module:
var currentTarget = 'midi_device_a'

module.exports = {

    oscInFilter: function(data) {
    
        var {address, args, host, port} = data

        if (address === '/some_address') { // match specific incoming message
            currentTarget = 'midi_device_b'
        }

        return {address, args, host, port}
        
    },

    oscOutFilter: function(data) {
    
        var {address, args, host, port} = data

        if (address === '/some_widget_address') {  // match specific outgoing message
            port = currentTarget // change target on the fly
        }

        return {address, args, host, port}
        
    }
    
}

Awesome thanks. I’ve gone tour the /Edit solution.

Slightly concerned however about the cpu hit you warn of in the wiki.

Is it a big hit? I have created a 16way switch that sends a midi channel to 8 faders and don’t want to drag the pc down too much…

No it’s just recommended to avoid editing widgets continuously (ten times per second for example)

Thanks.

(So impressed by this software btw - thanks for developing)

Thank you :slight_smile:

Ok so I’ve started looking at this again - the /EDIT method worked ok when I was looking at 8 faders but I now want to change the controller cc value that the fader sends on for 78 different faders dynamically.

Using /EDIT is way too slow and slows everything up dramatically while it works through.

I am using a custom module to control the visibility and label associated with them using OSC listeners but I can’t make that work for the preArg.

I’ve put the listener in the preArg box like this but I don’t think it’s updating correctly:

[
  1,
  #{osc{ccVal, ,false}}
]

My custom module populates the ccVal with ccInt using:

receiveOsc({
                address:Object.values(ccVal)[i],
                    args:[
                        {type:'i', value: ccInt}
                    ]
            })

The code is supposed to iterate through updating each of the faders with the ccInt.

OSC{} should be uppercase. Also the #{} wrapper is not necessary since you don't modify the received value.

address:Object.values(ccVal)[i],

Just in case, from the code quoted above the address should be something like /fader_address/ccVal

receiveOsc({...})

Using the shorthand receive function may be more readable: receive(Object.values(ccVal)[i], ccInt)


In my opinion, the best way to address this use case would be to never update the widgets themselves, and do the dynamic routing directly from the custom module.

OSC{} should be uppercase. Also the #{} wrapper is not necessary since you don't modify the received value.

address:Object.values(ccVal)[i],

Just in case, from the code quoted above the address should be something like /fader_address/ccVal

receiveOsc({...})

Using the shorthand receive function may be more readable:
receive(Object.values(ccVal)[i], ccInt)


In my opinion, the best way to address this use case would be to never update the widget properties and do the dynamic routing directly from the custom module.

Thanks for the reply @jean-emmanuel.
I will check against what I’ve done - noting the OSC vs osc as a start!

I think that you are right regarding the dynamic routing, but I am right on the limit of my very limited JavaScript knowledge here already so will have to do some learning I think!