midimonster icon indicating copy to clipboard operation
midimonster copied to clipboard

Wildcard matching in OSC path configuration?

Open mnemonicly opened this issue 8 years ago • 2 comments

Hello,

I found myself today needing to output a lot of similar osc paths.

Basically:

/channel/1/red = f 0.0 1.0
/channel/1/green = f 0.0 1.0
/channel/1/blue = f 0.0 1.0
/channel/2/red = f 0.0 1.0
/channel/2/green = f 0.0 1.0
etc

It would be great if there was a way of doing something like

/channel/*/red = f 0.0 1.0

or even better
/channel/*/[red,green,blue] = f 0.0 1.0

But I'm not sure of a good way to do that that does not interfere with those characters being part of the path--or even if that format is the right way to do things. I'd like to look at implementing something like this, but wanted to get some thoughts first.

mnemonicly avatar Feb 24 '18 01:02 mnemonicly

Hi, and thanks for the great work!

There's actually a comment in the code for that kind of thing at https://github.com/cbdevnet/midimonster/blob/master/osc.c#L722 , though it's really just a FIXME yet.

But yes, with proper OSC path matching, that would be possible.

Currently, path preconfiguration in the instance configuration creates an entry in the instance's channel array (this is at https://github.com/cbdevnet/midimonster/blob/master/osc.c#L426 and should probably be factored out into a procedure by itself, because as it is it looks pretty bad. The relevant structures are defined in osc.h.).

The index of a channel's configuration within that array is used as instance-global channel identifier (with some magic dust for multi-parametric channels).

This could (and probably should) be extended to allow just the behaviour you described. One particular thing to watch for are the aforementioned multi-parametric channels though.

One solution I can think of is changing the channel-spec matching (in backend_channel on https://github.com/cbdevnet/midimonster/blob/master/osc.c#L520), which is predominantly called in the [map] section, to use the proper OSC path match (on https://github.com/cbdevnet/midimonster/blob/master/osc.c#L537), and when a wildcard match is found, have it create a new channel entry with the complete path and a copy of the prototype/wildcard channel parameters. Of course, with multi-parametric channels, one channel entry for every parameter (with the param_index members correctly set) will have to be created.

As for using * within the path, the OSC spec actually says exactly what you describe in the OSC Message Dispatching and Pattern Matching section (and thats why the comment is there in the code, but when writing that backend I just wanted it to work at all :D)

cbdevnet avatar Feb 24 '18 01:02 cbdevnet

Implemented in 26ee2eacc7d60aa379c9e4b9b9c6b8bcdcd4bc6b.

See https://github.com/cbdevnet/midimonster/blob/master/configs/flying-faders.cfg for an example ;)

cbdevnet avatar Jul 27 '19 17:07 cbdevnet