Getting matched OSC path from wildcard sync?

I’m using wildcards to match OSC message paths with sync (as described in Section 10.3, “Pattern Matching” of the tutorial) and wondering if anyone knows whether it’s possible to determine the path that was actually matched by a wildcard path. For example, given the following code:

osc_vars = sync "/osc/*/multitoggle/**"

…which could match TouchOSC messages such as “/osc/3/multitoggle/1/8/1”, or:

osc_vars = sync "/osc/**"

…which will match any incoming OSC message, is there any way to get the exact path that was actually matched in any instance? If not, what use are wildcards for OSC handling, since you would still need a unique sync for each possible path, when you want to take different actions for different paths?


Wildcards still have use as they allow you to match against one of many inputs.

However you’re right about the benefit of knowing which osc path actually matched. Unfortunately I hadn’t figured out a super simple syntax for this by the time the deadline for getting v3 on Raspbian Stretch arrived. I therefore shipped without it with the intention of adding this functionality in a future release.

So, that said let me throw the ball back at you :slight_smile:

What kind of syntax would you like to see which would enable you to do this?

1 Like

Thanks for the reply Sam.

I just looked at the source for sync and noticed that the CueEvent does already have a path attribute, so I hacked together my own solution by having sync_event check for an extra option path, which if set causes sync to include the matched path as the 0th element of the returned array. So I suppose that’s what I would suggest for the syntax:

osc_vars = sync "/osc/**", path: true

… would cause osc_vars to be ["/osc/2/multitoggle/1/8/1", 1.0] or similar. This preserves the default return behaviour of sync.

I’ll still need to split the path on the slash to get each path segment. If you’re storing the matches for each wildcard within a path, that could be something else useful to return from sync in this situation, to avoid that split.


There is an undocumented function get_event which can do this, although as Sam would point out don’t rely on it as it may change in future versions. I used it here Using controllers with Sonic Pi 3

1 Like