Skip to content

Commit

Permalink
Removed default path
Browse files Browse the repository at this point in the history
Improved example
  • Loading branch information
EtheriVR committed Sep 24, 2022
1 parent 9cbaa64 commit 1b332f4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 25 deletions.
16 changes: 11 additions & 5 deletions Source/ExampleModule/MyOscProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

namespace ExampleModule
{
[Parameters("CoolParameter", "ParameterAddress", "ParameterAddress2")]
[Parameters(TestAddress1, TestAddress2, TestCallbackParameter, TestCallbackParameter2)]
public class MyOscProvider : IUnifiedAvatarOSCProvider
{
public const string TestAddress1 = "/avatar/parameters/ExampleModule/TestParam";
public const string TestAddress2 = "/avatar/parameters/ExampleModule/TestParam2";

public const string TestCallbackParameter = "/avatar/parameters/ExampleModule/ExampleCallback";
public const string TestCallbackParameter2 = "/avatar/parameters/ExampleModule/ExampleCallback2";

public string ProviderName => "MyProviderName";

public long UpdateRate => 1000; //How many milliseconds between each update
Expand All @@ -18,7 +24,7 @@ public class MyOscProvider : IUnifiedAvatarOSCProvider
/// <param name="osc"></param>
public void Intialize(IUnifiedAvatarOSC osc)
{
osc.Send("This is data!", "Avatar/Params/Address", this);
osc.Send("This is data!", TestAddress2, this);
}

/// <summary>
Expand All @@ -34,7 +40,7 @@ public void Uninitialize()
/// <param name="address">the address the message was sent to</param>
/// <param name="data">the data provided</param>

[OSCCallback("ParameterAddress","ParameterAddress2")]
[OSCCallback(TestCallbackParameter, TestCallbackParameter2)]
private void MyReceivingMethod(string address,IList<object> data)
{
Console.WriteLine("{0} Got Message: {1}", address,data[0].ToString());
Expand All @@ -44,8 +50,8 @@ private void MyReceivingMethod(string address,IList<object> data)

public void Update(IUnifiedAvatarOSC osc, float deltaTime)
{
//Send a cool value to the declared address
osc.Send(1337.0f, this);
//Send a cool value to the first declared address
osc.Send(1337.0f, TestAddress1, this);
}
}
}
Empty file.
18 changes: 9 additions & 9 deletions Source/UnifiedAvatarOSC/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Source/UnifiedAvatarOSC/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public MainWindow()
{
InitializeComponent();
logManager = new LogManager(logTextBox);
avatarOsc = new UnifiedAvatarSharpOSC("127.0.0.1", 9000,9001, "/avatar/parameters/UnifiedOSC/");
avatarOsc = new UnifiedAvatarSharpOSC("127.0.0.1", 9000,9001);
avatarOsc.OnAvatarChanged += Server_OnAvatarChanged;
avatarOsc.OnOscMessage += AvatarOsc_OnOscMessage;
providerManager.LoadProviders();
Expand Down
10 changes: 5 additions & 5 deletions Source/UnifiedAvatarOSC/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,10 @@
<value>NoControl</value>
</data>
<data name="OpenModulesFolderBtn.Location" type="System.Drawing.Point, System.Drawing">
<value>6, 373</value>
<value>3, 123</value>
</data>
<data name="OpenModulesFolderBtn.Size" type="System.Drawing.Size, System.Drawing">
<value>170, 23</value>
<value>173, 23</value>
</data>
<data name="OpenModulesFolderBtn.TabIndex" type="System.Int32, mscorlib">
<value>9</value>
Expand Down Expand Up @@ -1036,10 +1036,10 @@
<value>NoControl</value>
</data>
<data name="loadAllModulesBtn.Location" type="System.Drawing.Point, System.Drawing">
<value>6, 220</value>
<value>3, 94</value>
</data>
<data name="loadAllModulesBtn.Size" type="System.Drawing.Size, System.Drawing">
<value>170, 23</value>
<value>173, 23</value>
</data>
<data name="loadAllModulesBtn.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
Expand All @@ -1063,7 +1063,7 @@
<value>3, 65</value>
</data>
<data name="button1.Size" type="System.Drawing.Size, System.Drawing">
<value>170, 23</value>
<value>173, 23</value>
</data>
<data name="button1.TabIndex" type="System.Int32, mscorlib">
<value>6</value>
Expand Down
21 changes: 16 additions & 5 deletions Source/UnifiedAvatarOSC/UnifiedAvatarSharpOSC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ internal class UnifiedAvatarSharpOSC : IUnifiedAvatarOSC, IDisposable
{
UDPTransmitter client = null;
UDPReceiver server = null;
string basePrefix = "";

public delegate void AvatarIdHandler(string avatarId);
public delegate void RecievedMessageHandler(string address, IList<object> args);
Expand All @@ -24,14 +23,13 @@ internal class UnifiedAvatarSharpOSC : IUnifiedAvatarOSC, IDisposable
public event RecievedMessageHandler OnOscMessage;


public UnifiedAvatarSharpOSC(string address, int sendPort, int recieve, string basePrefix)
public UnifiedAvatarSharpOSC(string address, int sendPort, int recieve)
{
client = new UDPTransmitter(address, sendPort);
client.Connect();
server = new UDPReceiver(recieve,false);
server.Start();
server.PacketReceived += Server_PacketReceived;
this.basePrefix = basePrefix;
}

private void Server_PacketReceived(object sender, OscPacketReceivedEventArgs e)
Expand Down Expand Up @@ -59,7 +57,9 @@ public void Dispose()

public void Send(object input, string ParameterAddress, IUnifiedAvatarOSCProvider provider)
{
var message = new OscMessage(basePrefix + ParameterAddress, input);
CheckAddress(ref ParameterAddress);

var message = new OscMessage(ParameterAddress, input);
client.Send(message);
Log.Send(ParameterAddress, input.ToString(), provider.ProviderName);
}
Expand All @@ -68,7 +68,10 @@ public void Send(object input, IUnifiedAvatarOSCProvider provider)
{
var addresses = provider.GetType().GetCustomAttribute<Parameters>(true).Addresses;
var address = addresses.FirstOrDefault();
var message = new OscMessage(basePrefix + address, input);

CheckAddress(ref address);

var message = new OscMessage(address, input);
client.Send(message);

Log.Send(address, input.ToString(), provider.ProviderName);
Expand All @@ -80,9 +83,17 @@ public void Send(object input, IUnifiedAvatarOSCProvider provider)

public void SendAbsolutePath(object input, string ParameterAddress, IUnifiedAvatarOSCProvider provider)
{
CheckAddress(ref ParameterAddress);
var message = new OscMessage(ParameterAddress, input);

client.Send(message);
Log.Send(ParameterAddress, input.ToString(), provider.ProviderName);
}

private void CheckAddress(ref string address)
{
if (address.First() != '/')
address = '/' + address;
}
}
}
Empty file.
Empty file.

0 comments on commit 1b332f4

Please sign in to comment.