Skip to content

Commit

Permalink
v3.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
shells-dw committed Dec 12, 2022
1 parent 989c7db commit 7d97769
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 180 deletions.
20 changes: 0 additions & 20 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,4 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CommandLine" publicKeyToken="5a870481e358d379" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
File renamed without changes.
18 changes: 14 additions & 4 deletions Models/HelperFunctions.cs → Helper/HelperFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace streamdeck_totalmix

internal class HelperFunctions
{
public static void UpdateDeviceSettingDict()
public static async void UpdateDeviceSettingDict()
{
if (Globals.backgroundConnection)
{
Expand All @@ -20,9 +20,19 @@ public static void UpdateDeviceSettingDict()
Globals.listeningActive = true;
while (true)
{
Listener.Listen("Input", $"/1/busInput", 1).Wait();
Listener.Listen("Output", $"/1/busOutput", 1).Wait();
Listener.Listen("Playback", $"/1/busPlayback", 1).Wait();
try
{
await Listener.Listen("Input", $"/1/busInput", 1);
await Task.Delay(100);
await Listener.Listen("Output", $"/1/busOutput", 1);
await Task.Delay(100);
await Listener.Listen("Playback", $"/1/busPlayback", 1);
await Task.Delay(100);
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "UpdateDeviceSettingDict: " + ex.Message);
}
}
}
}
Expand Down
161 changes: 161 additions & 0 deletions Helper/OSCCommunicator/Listener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// OSC Listener

namespace streamdeck_totalmix
{
using BarRaider.SdTools;
using Rug.Osc;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
internal class Listener
{
// assign variables
static OscReceiver receiver;
private static readonly object threadLock = new object();
// main listener Task
public static Task Listen(String bus, String address, Single value)
{
try
{
// Create the receiver
receiver = new OscReceiver(Globals.interfaceBackgroundSendPort);
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Listener: new OscReceiver: " + ex.Message);
}

// Connect the receiver
try
{
// connect to the socket
receiver.Connect();
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Listener: receiver.Connect(): " + ex.Message);
receiver.Dispose();
receiver = null;
Task.FromException(ex);
}

try
{
// Start the listen thread
Sender.Send(address, value, Globals.interfaceIp, Globals.interfaceBackgroundPort).Wait();
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Listener: Sender.Send(): " + ex.Message);
}

try
{
lock (threadLock)
{
ListenLoop(bus).Wait();
}
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Listener: Listenloop(): " + ex.Message);
}
// close the Reciver
lock (threadLock)
{
receiver.Close();
}
return Task.CompletedTask;
}

private static Task ListenLoop(object bus)
{
try
{
while (receiver.State != OscSocketState.Closed)
{
// making sure to add the key if it doesn't exist already (we need it anyway and don't like exceptions)
if (!Globals.bankSettings.ContainsKey($"{bus}"))
{
Globals.bankSettings.Add($"{bus}", new Dictionary<String, String>());
}
// if we are in a state to recieve
if (receiver.State == OscSocketState.Connected)
{
// get the next message
// this will block until one arrives or the socket is closed
// OscPacket packet = receiver.Receive();
OscPacket packet;

// abort condition RegEx - the device sends a heartbeat of sorts ("/") every second
String snapRegEx = @"^\/$";
var r = new Regex(snapRegEx, RegexOptions.IgnoreCase);
try
{
while (receiver.TryReceive(out packet) == true)
{
// we're expecting only bundles at this time, so define the received packet as bundle
OscBundle bundle = packet as OscBundle;

if (packet.Error == OscPacketError.None)
{
if (bundle != null)
{
// match for abort condition
Match m = r.Match(((Rug.Osc.OscMessage)bundle[0]).Address.ToString());

// add every received bundle to the Global Dict
for (var i = 0; i < bundle.Count; i++)
{
Match uninterestingValues = Regex.Match(((Rug.Osc.OscMessage)bundle[i]).Address.ToString(), "^.{3}(?>label|select)");
if (uninterestingValues.Success == false)
{
Globals.bankSettings[$"{bus}"][$"{((Rug.Osc.OscMessage)bundle[i]).Address}"] = ((Rug.Osc.OscMessage)bundle[i])[0].ToString();
if (((Rug.Osc.OscMessage)bundle[i]).Address == $"/1/micgain{Globals.channelCount}Val")
{
return Task.CompletedTask;
}
}
}

// matched
if (m.Success)
{
return Task.CompletedTask;
}
}
}
else
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Listener: Error reading packet: " + packet.Error);
Logger.Instance.LogMessage(TracingLevel.INFO, "Listener: Error reading packet: " + packet.ErrorMessage);
return Task.CompletedTask;
}
}

}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Listener: while (receiver.TryReceive(out packet) == true): " + ex.Message);
}
}
}
}

// TODO
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Listener: catch main try: " + ex.Message);
// if the socket was connected when this happens
// then do something useful with it
if (receiver.State == OscSocketState.Connected)
{
// something useful
return Task.CompletedTask;
}
}
return Task.CompletedTask;
}
}
}
48 changes: 48 additions & 0 deletions Helper/OSCCommunicator/Sender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// OSC Sender

using BarRaider.SdTools;
using Rug.Osc;
using System;
using System.Net;
using System.Threading.Tasks;

namespace streamdeck_totalmix
{
internal class Sender
{
public static Task Send(String name, Single value, String ip, Int32 port)
{
OscSender sender = null;
try { sender = new OscSender(address: IPAddress.Loopback, localPort: 0, remotePort: port); }
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Sender: new OscSender: " + ex.Message);
sender.Dispose();
sender = null;
}
finally { sender = new OscSender(address: IPAddress.Loopback, localPort: 0, remotePort: port); }

// This is the ip address we are going to send to
IPAddress address = IPAddress.Parse(ip);

try
{
// connect to the socket
sender.Connect();
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Listener: receiver.Connect(): " + ex.Message);
sender.Dispose();
sender = null;
Task.FromException(ex);
}

// Send a new message
sender.Send(new OscMessage(name, value));

sender.Close();
return Task.CompletedTask;
}
}
}
102 changes: 0 additions & 102 deletions Models/OSCCommunicator/Listener.cs

This file was deleted.

Loading

0 comments on commit 7d97769

Please sign in to comment.