keijiro / OscJack

Lightweight C# implementation of OSC server/client
The Unlicense
465 stars 64 forks source link

Add Wild-Card osc-address option to OscMessageDispatcher() #40

Open zacksettel opened 1 year ago

zacksettel commented 1 year ago

I have to forward all OSC messages to an additional target, which would be made easy to do, with this feature

Proposition: Modify OscMessageDispatcher.cs. to be able to apply all received OSC messages to a callback , whose address is "*" as shown below:

internal void Dispatch(string address, OscDataHandle data) { lock (_callbackMap) { MessageCallback callback;

            // Process any message on wild-card match
            if (_callbackMap.TryGetValue("*", out callback))
                callback(address, data);

            // Address-specified callback
            if (_callbackMap.TryGetValue(address, out callback))
                callback(address, data);

            // Monitor callback
            if (_callbackMap.TryGetValue(string.Empty, out callback))
                callback(address, data);
        }
    }

For this to be effective, so that a callback client could parse the OscDataHandle data, the following method should be added to OscDataHandle.cs:

List OscDataHandle.GetTypeTags()

Then the client could properly access the received message and take action.