Skip to content

Commit

Permalink
Added handling of OSC address wildcards.
Browse files Browse the repository at this point in the history
This addresses #3.
  • Loading branch information
Barinzaya committed Jul 20, 2023
1 parent 33f23c7 commit 1714bc5
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions OscInputPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using OscCore;
using System.Collections.Concurrent;
using OscCore.Address;
using System;
using System.Collections.Generic;
using Warudo.Core.Attributes;
using Warudo.Core.Plugins;

[PluginType(Id = "com.barinzaya.oscinput", Name = "OSC Input", Version = "0.2.2", Author = "Barinzaya", Description = "Adds an On OSC Message node.",
[PluginType(Id = "com.barinzaya.oscinput", Name = "OSC Input", Version = "0.2.3", Author = "Barinzaya", Description = "Adds an On OSC Message node.",
NodeTypes = new[] { typeof(OscInputNode) })]
public class OscInputPlugin : Plugin {
public const int OSC_SERVER_PORT = 19190;
Expand All @@ -28,12 +29,7 @@ public override void OnPreUpdate() {
base.OnPreUpdate();

while(listener.TryGetMessage(out var message)) {
HashSet<OscMessageHandler> addressHandlers;
if (handlers.TryGetValue(message.Address, out addressHandlers)) {
foreach (var handler in addressHandlers) {
handler(message);
}
}
DispatchMessage(message);
}
}

Expand Down Expand Up @@ -61,4 +57,30 @@ public bool RemoveHandler(string address, OscMessageHandler action) {

return result;
}

private void DispatchMessage(OscMessage message) {
OscAddress address;
try {
address = new(message.Address);
} catch (ArgumentException) {
return;
}

if(address.IsLiteral) {
HashSet<OscMessageHandler> addressHandlers;
if(handlers.TryGetValue(message.Address, out addressHandlers)) {
foreach (var handler in addressHandlers) {
handler(message);
}
}
} else {
foreach(var pair in handlers) {
if (address.Match(pair.Key)) {
foreach (var handler in pair.Value) {
handler(message);
}
}
}
}
}
}

0 comments on commit 1714bc5

Please sign in to comment.