Begin implementing "/update" responses from QLab

This commit is contained in:
2019-04-08 16:06:15 -05:00
parent 091ea32ccc
commit d2b295c328
11 changed files with 107 additions and 54 deletions
+3 -1
View File
@@ -36,8 +36,10 @@
<key>XSAppIconAssets</key> <key>XSAppIconAssets</key>
<string>Assets.xcassets/AppIcon.appiconset</string> <string>Assets.xcassets/AppIcon.appiconset</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>2.0</string> <string>2.0.1</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.0</string> <string>1.0</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
</dict> </dict>
</plist> </plist>
@@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using SharpOSC; using SharpOSC;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace qController namespace qController
@@ -6,19 +7,29 @@ namespace qController
public class QClient public class QClient
{ {
TCPSender tcpSender; TCPSender tcpSender;
UDPSender udpSender;
public QParser qParser; public QParser qParser;
public QReceiver qReceiver;
public QClient(string address, int port) public QClient(string address, int port)
{ {
qParser = new QParser(); qParser = new QParser();
qReceiver = new QReceiver(port + 1);
tcpSender = new TCPSender(address, port); tcpSender = new TCPSender(address, port);
udpSender = new UDPSender(address, port);
tcpSender.MessageReceived += OnMessageReceived; tcpSender.MessageReceived += OnMessageReceived;
qReceiver.UpdateMessageReceived += OnMessageReceived;
} }
private void OnMessageReceived(object source, MessageEventArgs args) private void OnMessageReceived(object source, MessageEventArgs args)
{ {
qParser.ParseMessage(args.Message); if (!args.Message.Address.Contains("update"))
qParser.ParseMessage(args.Message);
else
ProcessUpdate(args.Message);
} }
public void sendString(string address) public void sendString(string address)
@@ -30,7 +41,14 @@ namespace qController
{ {
tcpSender.Send(new OscMessage(address, args)); tcpSender.Send(new OscMessage(address, args));
} }
public void sendStringUDP(string address)
{
udpSender.Send(new OscMessage(address));
}
public void sendArgsUDP(string address, params object[] args)
{
udpSender.Send(new OscMessage(address, args));
}
public OscMessage sendAndReceiveString(string address) public OscMessage sendAndReceiveString(string address)
{ {
return tcpSender.SendAndReceive(new OscMessage(address)); return tcpSender.SendAndReceive(new OscMessage(address));
@@ -42,6 +60,38 @@ namespace qController
} }
public void ProcessUpdate(OscMessage msg)
{
if (msg.Address.Contains("cue_id"))
{
var updateID = msg.Address.Split('/').Last();
Console.WriteLine("Cue needs to be updated: " + updateID);
}else if (msg.Address.Contains("playbackPosition"))
{
if (msg.Arguments.Count > 0)
{
Console.WriteLine("Playback position to be updated: " + msg.Arguments[0]);
UpdateSelectedCue();
}
}
}
public void UpdateSpecificCue(string cue_id)
{
Console.WriteLine(cue_id);
}
public void UpdateSelectedCue()
{
string valuesForKeys = "[\"displayName\",\"number\",\"type\",\"isBroken\",\"isLoaded\",\"isPaused\",\"isRunning\",\"preWait\",\"duration\",\"postWait\",\"translationX\",\"translationY\",\"opacity\",\"scaleX\",\"scaleY\",\"uniqueID\",\"flagged\",\"listName\",\"colorName\",\"name\",\"armed\"]";
sendAndReceiveStringArgs("/cue/selected/valuesForKeys", valuesForKeys);
}
public void Close()
{
udpSender.Close();
qReceiver.Close();
}
} }
} }
@@ -23,6 +23,8 @@ namespace qController
qClient.qParser.WorkspaceUpdated += this.OnWorkspaceUpdated; qClient.qParser.WorkspaceUpdated += this.OnWorkspaceUpdated;
qClient.sendArgsUDP("/updates", 1);
qClient.sendAndReceiveString("/cueLists");
} }
@@ -37,7 +39,17 @@ namespace qController
public void OnSelectedCueUpdated(object source, CueEventArgs args) public void OnSelectedCueUpdated(object source, CueEventArgs args)
{ {
selectedCue = args.SelectedCue; selectedCue = args.SelectedCue;
//Console.WriteLine("Selected Cue Updated: Name=" + selectedCue.listName); Console.WriteLine("Selected cue updated: " + selectedCue.uniqueID);
foreach (var cueList in qWorkspace.data)
{
foreach( var cue in cueList.cues)
{
if(cue.uniqueID == selectedCue.uniqueID)
{
Console.WriteLine("Cue found in local workspace");
}
}
}
} }
public void OnWorkspaceUpdated(object source, WorkspaceEventArgs args) public void OnWorkspaceUpdated(object source, WorkspaceEventArgs args)
@@ -48,6 +60,7 @@ namespace qController
} }
public void Kill(){ public void Kill(){
qUpdater.Kill(); qUpdater.Kill();
qClient.Close();
} }
} }
} }
@@ -73,8 +73,6 @@ namespace qController
JToken selectedCue = OSC2JSON(msg); JToken selectedCue = OSC2JSON(msg);
Console.WriteLine("Selected Cue Updated"); Console.WriteLine("Selected Cue Updated");
QCue cue = JsonConvert.DeserializeObject<QCue>(selectedCue.ToString()); QCue cue = JsonConvert.DeserializeObject<QCue>(selectedCue.ToString());
Console.WriteLine(cue.uniqueID);
OnSelectedCueUpdated(cue); OnSelectedCueUpdated(cue);
} }
@@ -1,42 +1,39 @@
using System; //this class is used for receiving workspace update messages
using System;
using SharpOSC; using SharpOSC;
using System.Net; using System.Net;
using System.Threading; using System.Threading;
namespace qController namespace qController
{ {
public class MessageEventArgs : EventArgs{
public OscMessage Message {
get;
set;
}
}
public class QReceiver public class QReceiver
{ {
public delegate void UpdateMessageReceivedHandler(object source, MessageEventArgs args);
public event UpdateMessageReceivedHandler UpdateMessageReceived;
static Thread thread; static Thread thread;
private QController owner;
static UDPListener udpListener; static UDPListener udpListener;
public delegate void MessageReceivedHandler(object source, MessageEventArgs args);
public event MessageReceivedHandler MessageReceived; public QReceiver(int port)
public QReceiver(int port, QController ctrl)
{ {
owner = ctrl; HandleOscPacket callback = delegate (OscPacket packet)
{
var messageReceived = (OscMessage)packet;
if(messageReceived != null)
OnUpdateMessageReceived(messageReceived);
else
Console.WriteLine("Message came back null");
};
udpListener = new UDPListener(port); udpListener = new UDPListener(port, callback);
thread = new Thread(new ThreadStart(ListenLoop));
thread.Start();
} }
public void ListenLoop() public void ListenLoop()
{ {
Console.WriteLine("Loop Started"); /*while (true)
while (true)
{ {
OscMessage messageReceived = null; OscMessage messageReceived = null;
while(messageReceived == null) while(messageReceived == null)
@@ -44,23 +41,20 @@ namespace qController
messageReceived = (OscMessage)udpListener.Receive(); messageReceived = (OscMessage)udpListener.Receive();
Thread.Sleep(1); Thread.Sleep(1);
} }
OnMessageReceived(messageReceived); OnUpdateMessageReceived(messageReceived);
} }*/
Console.WriteLine("Loop Ended");
} }
public void Close(){ public void Close(){
thread.Abort();
udpListener.Close(); udpListener.Close();
} }
protected virtual void OnMessageReceived(OscMessage msg){ protected virtual void OnUpdateMessageReceived(OscMessage msg)
Console.WriteLine("Message Received"); {
if (MessageReceived != null) if (UpdateMessageReceived != null)
MessageReceived(this, new MessageEventArgs(){Message = msg}); UpdateMessageReceived(this, new MessageEventArgs() { Message = msg });
} }
} }
} }
@@ -6,6 +6,7 @@ namespace qController
{ {
public class QUpdater public class QUpdater
{ {
private bool active = true; private bool active = true;
private QController qController; private QController qController;
private Thread updateThread; private Thread updateThread;
@@ -32,7 +33,7 @@ namespace qController
public void UpdateSelected() public void UpdateSelected()
{ {
string valuesForKeys = "[\"displayName\",\"number\",\"type\",\"isBroken\",\"isLoaded\",\"isPaused\",\"isRunning\",\"preWait\",\"duration\",\"postWait\",\"translationX\",\"translationY\",\"opacity\",\"scaleX\",\"scaleY\",\"uniqueID\",\"flagged\",\"listName\",\"colorName\",\"name\",\"armed\"]"; string valuesForKeys = "[\"displayName\",\"number\",\"type\",\"isBroken\",\"isLoaded\",\"isPaused\",\"isRunning\",\"preWait\",\"duration\",\"postWait\",\"translationX\",\"translationY\",\"opacity\",\"scaleX\",\"scaleY\",\"uniqueID\",\"flagged\",\"listName\",\"colorName\",\"name\",\"armed\"]";
qController.qClient.sendAndReceiveStringArgs("/cue/selected/valuesForKeys", valuesForKeys); //qController.qClient.sendAndReceiveStringArgs("/cue/selected/valuesForKeys", valuesForKeys);
} }
public void UpdateLevels() public void UpdateLevels()
{ {
@@ -32,7 +32,6 @@ namespace SharpOSC
char[] types = new char[0]; char[] types = new char[0];
List<object> arguments = new List<object>(); List<object> arguments = new List<object>();
List<object> mainArray = arguments; // used as a reference when we are parsing arrays to get the main array back List<object> mainArray = arguments; // used as a reference when we are parsing arrays to get the main array back
// Get address // Get address
address = getAddress(msg, index); address = getAddress(msg, index);
index += msg.FirstIndexAfter(address.Length, x => x == ','); index += msg.FirstIndexAfter(address.Length, x => x == ',');
@@ -147,7 +146,7 @@ namespace SharpOSC
case ('['): case ('['):
if (arguments != mainArray) if (arguments != mainArray)
throw new Exception("SharopOSC does not support nested arrays"); throw new Exception("SharpOSC does not support nested arrays");
arguments = new List<object>(); // make arguments point to a new object array arguments = new List<object>(); // make arguments point to a new object array
break; break;
@@ -247,6 +246,12 @@ namespace SharpOSC
} }
} }
if (types == null)
{
byte[] term = { 0 };
types = Encoding.ASCII.GetChars(term);
}
if (i >= msg.Length && types == null) if (i >= msg.Length && types == null)
throw new Exception("No null terminator after type string"); throw new Exception("No null terminator after type string");
@@ -480,6 +485,5 @@ namespace SharpOSC
} }
#endregion #endregion
} }
} }
@@ -33,7 +33,6 @@ namespace SharpOSC
string _address; string _address;
TcpClient client; TcpClient client;
Thread receivingThread;
byte END = 0xc0; byte END = 0xc0;
byte ESC = 0xdb; byte ESC = 0xdb;
@@ -81,7 +80,7 @@ namespace SharpOSC
} }
} catch(Exception e) } catch(Exception e)
{ {
Console.WriteLine(e.ToString()); //Console.WriteLine(e.ToString());
} }
return response; return response;
} }
@@ -103,10 +102,6 @@ namespace SharpOSC
OnMessageReceived(response); OnMessageReceived(response);
return response; return response;
} }
public void StartReceiving()
{
receivingThread.Start();
}
public void Send(OscPacket packet) public void Send(OscPacket packet)
{ {
@@ -145,7 +140,6 @@ namespace SharpOSC
public void Close() public void Close()
{ {
client.GetStream().Close(); client.GetStream().Close();
receivingThread.Abort();
client.Close(); client.Close();
} }
@@ -97,10 +97,10 @@ namespace SharpOSC
} }
catch (Exception e) catch (Exception e)
{ {
// If there is an error reading the packet, null is sent to the callback Console.WriteLine(e.ToString());
} // If there is an error reading the packet, null is sent to the callback
}
OscPacketCallback(packet); OscPacketCallback(packet);
} }
else else
{ {
@@ -124,7 +124,7 @@ namespace qController
void sendOSC(object sender, EventArgs e) void sendOSC(object sender, EventArgs e)
{ {
qController.sendCommand(((QButton)sender).OSCCommand); qController.qClient.sendStringUDP(((QButton)sender).OSCCommand);
} }
void Back(object sender, EventArgs e) void Back(object sender, EventArgs e)
-3
View File
@@ -36,9 +36,6 @@
<Compile Remove="Bespoke.Net\Properties\AssemblyInfo.cs" /> <Compile Remove="Bespoke.Net\Properties\AssemblyInfo.cs" />
<Compile Remove="Classes\QButton.cs" /> <Compile Remove="Classes\QButton.cs" />
<Compile Remove="Classes\Cues\QDefinitions.cs" /> <Compile Remove="Classes\Cues\QDefinitions.cs" />
<Compile Remove="Classes\Communication\QReceiver.cs" />
<Compile Remove="Classes\Communication\SharpOSC\UDPListener.cs" />
<Compile Remove="Classes\Communication\SharpOSC\UDPSender.cs" />
<Compile Remove="Classes\Communication\QSender.cs" /> <Compile Remove="Classes\Communication\QSender.cs" />
<Compile Remove="Classes\Communication\QSender.cs" /> <Compile Remove="Classes\Communication\QSender.cs" />
</ItemGroup> </ItemGroup>