From d2b295c328f64294059932401febb2ff1e2adb4a Mon Sep 17 00:00:00 2001 From: jwetzell Date: Mon, 8 Apr 2019 16:06:15 -0500 Subject: [PATCH] Begin implementing "/update" responses from QLab --- iOS/Info.plist | 4 +- .../Classes/Communication/QClient.cs | 54 ++++++++++++++++++- .../Classes/Communication/QController.cs | 15 +++++- .../Classes/Communication/QParser.cs | 2 - .../Classes/Communication/QReceiver.cs | 52 ++++++++---------- .../Classes/Communication/QUpdater.cs | 3 +- .../Communication/SharpOSC/OscPacket.cs | 10 ++-- .../Communication/SharpOSC/TCPSender.cs | 8 +-- .../Communication/SharpOSC/UDPListener.cs | 8 +-- .../Pages/ControlPage.xaml.cs | 2 +- qController.Standard/qController.csproj | 3 -- 11 files changed, 107 insertions(+), 54 deletions(-) diff --git a/iOS/Info.plist b/iOS/Info.plist index 8913b0d..dcdf932 100644 --- a/iOS/Info.plist +++ b/iOS/Info.plist @@ -36,8 +36,10 @@ XSAppIconAssets Assets.xcassets/AppIcon.appiconset CFBundleShortVersionString - 2.0 + 2.0.1 CFBundleVersion 1.0 + ITSAppUsesNonExemptEncryption + diff --git a/qController.Standard/Classes/Communication/QClient.cs b/qController.Standard/Classes/Communication/QClient.cs index ff0e61d..9da2654 100644 --- a/qController.Standard/Classes/Communication/QClient.cs +++ b/qController.Standard/Classes/Communication/QClient.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using SharpOSC; using Newtonsoft.Json; namespace qController @@ -6,19 +7,29 @@ namespace qController public class QClient { TCPSender tcpSender; + UDPSender udpSender; public QParser qParser; + public QReceiver qReceiver; public QClient(string address, int port) { qParser = new QParser(); + qReceiver = new QReceiver(port + 1); tcpSender = new TCPSender(address, port); + udpSender = new UDPSender(address, port); + tcpSender.MessageReceived += OnMessageReceived; + qReceiver.UpdateMessageReceived += OnMessageReceived; + } 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) @@ -30,7 +41,14 @@ namespace qController { 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) { 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(); + } } } diff --git a/qController.Standard/Classes/Communication/QController.cs b/qController.Standard/Classes/Communication/QController.cs index 4c39f1c..da45d7d 100644 --- a/qController.Standard/Classes/Communication/QController.cs +++ b/qController.Standard/Classes/Communication/QController.cs @@ -23,6 +23,8 @@ namespace qController 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) { 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) @@ -48,6 +60,7 @@ namespace qController } public void Kill(){ qUpdater.Kill(); + qClient.Close(); } } } diff --git a/qController.Standard/Classes/Communication/QParser.cs b/qController.Standard/Classes/Communication/QParser.cs index ea99ffa..8f33cdd 100644 --- a/qController.Standard/Classes/Communication/QParser.cs +++ b/qController.Standard/Classes/Communication/QParser.cs @@ -73,8 +73,6 @@ namespace qController JToken selectedCue = OSC2JSON(msg); Console.WriteLine("Selected Cue Updated"); QCue cue = JsonConvert.DeserializeObject(selectedCue.ToString()); - - Console.WriteLine(cue.uniqueID); OnSelectedCueUpdated(cue); } diff --git a/qController.Standard/Classes/Communication/QReceiver.cs b/qController.Standard/Classes/Communication/QReceiver.cs index a68cf2e..9b52a7f 100644 --- a/qController.Standard/Classes/Communication/QReceiver.cs +++ b/qController.Standard/Classes/Communication/QReceiver.cs @@ -1,42 +1,39 @@ -using System; +//this class is used for receiving workspace update messages + +using System; using SharpOSC; using System.Net; using System.Threading; namespace qController { - public class MessageEventArgs : EventArgs{ - public OscMessage Message { - get; - set; - } - } public class QReceiver { + public delegate void UpdateMessageReceivedHandler(object source, MessageEventArgs args); + public event UpdateMessageReceivedHandler UpdateMessageReceived; + static Thread thread; - private QController owner; static UDPListener udpListener; - public delegate void MessageReceivedHandler(object source, MessageEventArgs args); - public event MessageReceivedHandler MessageReceived; - - public QReceiver(int port, QController ctrl) + public QReceiver(int port) { - 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); - - thread = new Thread(new ThreadStart(ListenLoop)); - thread.Start(); + udpListener = new UDPListener(port, callback); } public void ListenLoop() { - Console.WriteLine("Loop Started"); - - while (true) + /*while (true) { OscMessage messageReceived = null; while(messageReceived == null) @@ -44,23 +41,20 @@ namespace qController messageReceived = (OscMessage)udpListener.Receive(); Thread.Sleep(1); } - OnMessageReceived(messageReceived); - - } + OnUpdateMessageReceived(messageReceived); - Console.WriteLine("Loop Ended"); + }*/ } public void Close(){ - thread.Abort(); udpListener.Close(); } - protected virtual void OnMessageReceived(OscMessage msg){ - Console.WriteLine("Message Received"); - if (MessageReceived != null) - MessageReceived(this, new MessageEventArgs(){Message = msg}); + protected virtual void OnUpdateMessageReceived(OscMessage msg) + { + if (UpdateMessageReceived != null) + UpdateMessageReceived(this, new MessageEventArgs() { Message = msg }); } } } diff --git a/qController.Standard/Classes/Communication/QUpdater.cs b/qController.Standard/Classes/Communication/QUpdater.cs index 7a59035..fb54c99 100644 --- a/qController.Standard/Classes/Communication/QUpdater.cs +++ b/qController.Standard/Classes/Communication/QUpdater.cs @@ -6,6 +6,7 @@ namespace qController { public class QUpdater { + private bool active = true; private QController qController; private Thread updateThread; @@ -32,7 +33,7 @@ namespace qController 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\"]"; - qController.qClient.sendAndReceiveStringArgs("/cue/selected/valuesForKeys", valuesForKeys); + //qController.qClient.sendAndReceiveStringArgs("/cue/selected/valuesForKeys", valuesForKeys); } public void UpdateLevels() { diff --git a/qController.Standard/Classes/Communication/SharpOSC/OscPacket.cs b/qController.Standard/Classes/Communication/SharpOSC/OscPacket.cs index fdecce4..f4eaeee 100755 --- a/qController.Standard/Classes/Communication/SharpOSC/OscPacket.cs +++ b/qController.Standard/Classes/Communication/SharpOSC/OscPacket.cs @@ -32,7 +32,6 @@ namespace SharpOSC char[] types = new char[0]; List arguments = new List(); List mainArray = arguments; // used as a reference when we are parsing arrays to get the main array back - // Get address address = getAddress(msg, index); index += msg.FirstIndexAfter(address.Length, x => x == ','); @@ -147,7 +146,7 @@ namespace SharpOSC case ('['): if (arguments != mainArray) - throw new Exception("SharopOSC does not support nested arrays"); + throw new Exception("SharpOSC does not support nested arrays"); arguments = new List(); // make arguments point to a new object array break; @@ -247,6 +246,12 @@ namespace SharpOSC } } + if (types == null) + { + byte[] term = { 0 }; + types = Encoding.ASCII.GetChars(term); + } + if (i >= msg.Length && types == null) throw new Exception("No null terminator after type string"); @@ -480,6 +485,5 @@ namespace SharpOSC } #endregion - } } diff --git a/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs b/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs index 0d9cc45..554a2c0 100644 --- a/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs +++ b/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs @@ -33,7 +33,6 @@ namespace SharpOSC string _address; TcpClient client; - Thread receivingThread; byte END = 0xc0; byte ESC = 0xdb; @@ -81,7 +80,7 @@ namespace SharpOSC } } catch(Exception e) { - Console.WriteLine(e.ToString()); + //Console.WriteLine(e.ToString()); } return response; } @@ -103,10 +102,6 @@ namespace SharpOSC OnMessageReceived(response); return response; } - public void StartReceiving() - { - receivingThread.Start(); - } public void Send(OscPacket packet) { @@ -145,7 +140,6 @@ namespace SharpOSC public void Close() { client.GetStream().Close(); - receivingThread.Abort(); client.Close(); } diff --git a/qController.Standard/Classes/Communication/SharpOSC/UDPListener.cs b/qController.Standard/Classes/Communication/SharpOSC/UDPListener.cs index 9fc2f78..992c15e 100755 --- a/qController.Standard/Classes/Communication/SharpOSC/UDPListener.cs +++ b/qController.Standard/Classes/Communication/SharpOSC/UDPListener.cs @@ -97,10 +97,10 @@ namespace SharpOSC } catch (Exception e) { - // If there is an error reading the packet, null is sent to the callback - } - - OscPacketCallback(packet); + Console.WriteLine(e.ToString()); + // If there is an error reading the packet, null is sent to the callback + } + OscPacketCallback(packet); } else { diff --git a/qController.Standard/Pages/ControlPage.xaml.cs b/qController.Standard/Pages/ControlPage.xaml.cs index aeb6115..7fee88f 100644 --- a/qController.Standard/Pages/ControlPage.xaml.cs +++ b/qController.Standard/Pages/ControlPage.xaml.cs @@ -124,7 +124,7 @@ namespace qController void sendOSC(object sender, EventArgs e) { - qController.sendCommand(((QButton)sender).OSCCommand); + qController.qClient.sendStringUDP(((QButton)sender).OSCCommand); } void Back(object sender, EventArgs e) diff --git a/qController.Standard/qController.csproj b/qController.Standard/qController.csproj index ff61a3d..facc7d0 100644 --- a/qController.Standard/qController.csproj +++ b/qController.Standard/qController.csproj @@ -36,9 +36,6 @@ - - -