From 886fe0cf0bdb0c92e8af517911ae428395195ea4 Mon Sep 17 00:00:00 2001 From: jwetzell Date: Tue, 9 Apr 2019 16:04:59 -0500 Subject: [PATCH] Implement notes, and work on updating cue info --- iOS/Info.plist | 2 +- .../Classes/Cell/QSelectedCueCell.cs | 2 +- .../Classes/Communication/QClient.cs | 16 +++++---- .../Classes/Communication/QController.cs | 6 ++-- .../Classes/Communication/QParser.cs | 3 +- .../Classes/Communication/QReceiver.cs | 33 ++++++++----------- .../Communication/SharpOSC/OscPacket.cs | 12 ++++--- .../Communication/SharpOSC/TCPSender.cs | 32 ++++++++++-------- .../Communication/SharpOSC/UDPListener.cs | 1 + qController.Standard/Classes/Cues/QCue.cs | 1 + .../Classes/Cues/QWorkSpace.cs | 8 +++++ .../Pages/ControlPage.xaml.cs | 16 ++++++++- 12 files changed, 79 insertions(+), 53 deletions(-) diff --git a/iOS/Info.plist b/iOS/Info.plist index dcdf932..8a16236 100644 --- a/iOS/Info.plist +++ b/iOS/Info.plist @@ -36,7 +36,7 @@ XSAppIconAssets Assets.xcassets/AppIcon.appiconset CFBundleShortVersionString - 2.0.1 + 2.0.2 CFBundleVersion 1.0 ITSAppUsesNonExemptEncryption diff --git a/qController.Standard/Classes/Cell/QSelectedCueCell.cs b/qController.Standard/Classes/Cell/QSelectedCueCell.cs index a88968b..9a4ce61 100644 --- a/qController.Standard/Classes/Cell/QSelectedCueCell.cs +++ b/qController.Standard/Classes/Cell/QSelectedCueCell.cs @@ -113,7 +113,7 @@ namespace qController name.Text = cue.name; number.Text = cue.number; type.Text = cue.type; - //notes.Text = cue.notes; + notes.Text = cue.notes; } } } diff --git a/qController.Standard/Classes/Communication/QClient.cs b/qController.Standard/Classes/Communication/QClient.cs index 2b8b664..29e5659 100644 --- a/qController.Standard/Classes/Communication/QClient.cs +++ b/qController.Standard/Classes/Communication/QClient.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading; using SharpOSC; using Newtonsoft.Json; namespace qController @@ -49,14 +50,14 @@ namespace qController { udpSender.Send(new OscMessage(address, args)); } - public OscMessage sendAndReceiveString(string address) + public void sendAndReceiveString(string address) { - return tcpSender.SendAndReceive(new OscMessage(address)); + tcpSender.SendAndReceive(new OscMessage(address)); } - public OscMessage sendAndReceiveStringArgs(string address, params object[] args) + public void sendAndReceiveStringArgs(string address, params object[] args) { - return tcpSender.SendAndReceive(new OscMessage(address, args)); + tcpSender.SendAndReceive(new OscMessage(address,args)); } @@ -91,14 +92,15 @@ namespace qController public void UpdateSpecificCue(string cue_id) { Console.WriteLine("Cue needs to be updated: " + cue_id); - string valuesForKeys = "[\"displayName\",\"number\",\"type\",\"isBroken\",\"isLoaded\",\"isPaused\",\"isRunning\",\"preWait\",\"duration\",\"postWait\",\"translationX\",\"translationY\",\"opacity\",\"scaleX\",\"scaleY\",\"uniqueID\",\"flagged\",\"listName\",\"colorName\",\"name\",\"armed\"]"; - string address = "/cue/" + cue_id + "/valuesForKeys"; + string valuesForKeys = "[\"displayName\",\"number\",\"type\",\"isBroken\",\"isLoaded\",\"isPaused\",\"isRunning\",\"preWait\",\"duration\",\"postWait\",\"translationX\",\"translationY\",\"opacity\",\"scaleX\",\"scaleY\",\"uniqueID\",\"flagged\",\"listName\",\"colorName\",\"name\",\"armed\",\"notes\"]"; + string address = "/cue_id/" + cue_id + "/valuesForKeys"; + sendAndReceiveStringArgs(address, valuesForKeys); } 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\"]"; + string valuesForKeys = "[\"displayName\",\"number\",\"type\",\"isBroken\",\"isLoaded\",\"isPaused\",\"isRunning\",\"preWait\",\"duration\",\"postWait\",\"translationX\",\"translationY\",\"opacity\",\"scaleX\",\"scaleY\",\"uniqueID\",\"flagged\",\"listName\",\"colorName\",\"name\",\"armed\",\"notes\"]"; sendAndReceiveStringArgs("/cue/selected/valuesForKeys", valuesForKeys); } diff --git a/qController.Standard/Classes/Communication/QController.cs b/qController.Standard/Classes/Communication/QController.cs index e8ca4c8..bb36f7b 100644 --- a/qController.Standard/Classes/Communication/QController.cs +++ b/qController.Standard/Classes/Communication/QController.cs @@ -23,10 +23,9 @@ namespace qController qClient.qParser.SelectedCueUpdated += this.OnSelectedCueUpdated; qClient.qParser.WorkspaceUpdated += this.OnWorkspaceUpdated; qClient.qParser.PlaybackPositionUpdated += this.OnPlaybackPositionUpdated; - + qClient.qParser.CueInfoUpdated += this.OnCueUpdateReceived; qClient.sendArgsUDP("/updates", 1); qClient.sendAndReceiveString("/cueLists"); - } @@ -48,6 +47,7 @@ namespace qController { qWorkspace = args.UpdatedWorkspace; Console.WriteLine("Workspace updated in QController: " + qWorkspace.workspace_id); + qWorkspace.PrintStats(); } public void OnPlaybackPositionUpdated(object source, PlaybackPositionArgs args) @@ -59,7 +59,7 @@ namespace qController public void OnCueUpdateReceived(object source, CueEventArgs args) { qWorkspace.UpdateCue(args.Cue); - Console.WriteLine("Cue updated: " + args.Cue.uniqueID ); + Console.WriteLine("Cue updated in QController: " + args.Cue.uniqueID ); } public void Kill(){ qUpdater.Kill(); diff --git a/qController.Standard/Classes/Communication/QParser.cs b/qController.Standard/Classes/Communication/QParser.cs index e446a04..ae640b1 100644 --- a/qController.Standard/Classes/Communication/QParser.cs +++ b/qController.Standard/Classes/Communication/QParser.cs @@ -100,7 +100,6 @@ namespace qController public void ParseCueUpdateInfo(OscMessage msg) { JToken cueUpdate = OSC2JSON(msg); - Console.WriteLine("Cue Update Received"); QCue cue = JsonConvert.DeserializeObject(cueUpdate.ToString()); OnCueInfoUpdated(cue); } @@ -152,7 +151,7 @@ namespace qController } protected virtual void OnCueInfoUpdated(QCue cue) - { + { if (CueInfoUpdated != null) CueInfoUpdated(this, new CueEventArgs() { Cue = cue }); } diff --git a/qController.Standard/Classes/Communication/QReceiver.cs b/qController.Standard/Classes/Communication/QReceiver.cs index 9b52a7f..8fe781a 100644 --- a/qController.Standard/Classes/Communication/QReceiver.cs +++ b/qController.Standard/Classes/Communication/QReceiver.cs @@ -15,40 +15,33 @@ namespace qController static Thread thread; static UDPListener udpListener; - + static int Port; public QReceiver(int port) { - 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, callback); + Port = port; + thread = new Thread(new ThreadStart(ListenLoop)); + thread.Start(); } public void ListenLoop() { - /*while (true) + HandleOscPacket callback = delegate (OscPacket packet) { - OscMessage messageReceived = null; - while(messageReceived == null) - { - messageReceived = (OscMessage)udpListener.Receive(); - Thread.Sleep(1); - } - OnUpdateMessageReceived(messageReceived); + var messageReceived = (OscMessage)packet; + if (messageReceived != null) + OnUpdateMessageReceived(messageReceived); + else + Console.WriteLine("Message came back null"); + }; - }*/ + udpListener = new UDPListener(Port, callback); } public void Close(){ udpListener.Close(); + thread.Abort(); } protected virtual void OnUpdateMessageReceived(OscMessage msg) diff --git a/qController.Standard/Classes/Communication/SharpOSC/OscPacket.cs b/qController.Standard/Classes/Communication/SharpOSC/OscPacket.cs index f4eaeee..2467e8c 100755 --- a/qController.Standard/Classes/Communication/SharpOSC/OscPacket.cs +++ b/qController.Standard/Classes/Communication/SharpOSC/OscPacket.cs @@ -27,8 +27,8 @@ namespace SharpOSC private static OscMessage parseMessage(byte[] msg) { int index = 0; - - string address = null; + //Console.WriteLine("Raw OSC DATA: " + System.Text.Encoding.ASCII.GetString(msg)); + string address = null; 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 @@ -287,8 +287,12 @@ namespace SharpOSC break; } } - - if (i >= msg.Length && output == null) + if (output == null) + { + byte[] term = { 0 }; + output = Encoding.ASCII.GetString(term); + } + if (i >= msg.Length && output == null) throw new Exception("No null terminator after type string"); return output.Replace("\0", ""); diff --git a/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs b/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs index 554a2c0..9279821 100644 --- a/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs +++ b/qController.Standard/Classes/Communication/SharpOSC/TCPSender.cs @@ -56,12 +56,15 @@ namespace SharpOSC client.Close(); } - public OscMessage Receive() + public async void Receive() { + Random random = new Random(); + int num = random.Next(1000); + OscMessage response = new OscMessage("/null"); + NetworkStream netStream = client.GetStream(); try { - NetworkStream netStream = client.GetStream(); netStream.ReadTimeout = 250; List responseData = new List(); if (netStream.CanRead) @@ -71,36 +74,37 @@ namespace SharpOSC int bytesRead = 0; do { - bytesRead = netStream.Read(buffer, 0, buffer.Length); + bytesRead = await netStream.ReadAsync(buffer, 0, buffer.Length); responseData.AddRange(buffer); + Thread.Sleep(1); + //Console.WriteLine( "Thread " + num + ": Bytes read: " + bytesRead + " - " + Encoding.ASCII.GetString(buffer)); } while (netStream.DataAvailable); + + Console.WriteLine("Raw TCP In: " + System.Text.Encoding.ASCII.GetString(responseData.ToArray())); response = (OscMessage)OscPacket.GetPacket(responseData.Skip(1).ToArray()); - netStream.Close(); - client.Close(); } } catch(Exception e) { - //Console.WriteLine(e.ToString()); + Console.WriteLine(e.ToString()); } - return response; + netStream.Close(); + client.Close(); + OnMessageReceived(response); } - public OscMessage SendAndReceive(byte[] message) + public void SendAndReceive(byte[] message) { client = new TcpClient(Address, Port); byte[] slipData = SlipEncode(message); NetworkStream netStream = client.GetStream(); netStream.Write(slipData.ToArray(), 0, slipData.ToArray().Length); - OscMessage response = Receive(); - return response; + Receive(); } - public OscMessage SendAndReceive(OscPacket packet) + public void SendAndReceive(OscPacket packet) { byte[] data = packet.GetBytes(); - OscMessage response = SendAndReceive(data); - OnMessageReceived(response); - return response; + SendAndReceive(data); } public void Send(OscPacket packet) diff --git a/qController.Standard/Classes/Communication/SharpOSC/UDPListener.cs b/qController.Standard/Classes/Communication/SharpOSC/UDPListener.cs index 992c15e..9f75be8 100755 --- a/qController.Standard/Classes/Communication/SharpOSC/UDPListener.cs +++ b/qController.Standard/Classes/Communication/SharpOSC/UDPListener.cs @@ -100,6 +100,7 @@ namespace SharpOSC Console.WriteLine(e.ToString()); // If there is an error reading the packet, null is sent to the callback } + Console.WriteLine("Raw UDP In: " + System.Text.Encoding.ASCII.GetString(bytes)); OscPacketCallback(packet); } else diff --git a/qController.Standard/Classes/Cues/QCue.cs b/qController.Standard/Classes/Cues/QCue.cs index b98b675..d523532 100644 --- a/qController.Standard/Classes/Cues/QCue.cs +++ b/qController.Standard/Classes/Cues/QCue.cs @@ -25,5 +25,6 @@ namespace qController public bool isBroken { get; set; } public string displayName { get; set; } public bool isLoaded { get; set; } + public string notes { get; set; } } } diff --git a/qController.Standard/Classes/Cues/QWorkSpace.cs b/qController.Standard/Classes/Cues/QWorkSpace.cs index 02ec011..c69cbb8 100644 --- a/qController.Standard/Classes/Cues/QWorkSpace.cs +++ b/qController.Standard/Classes/Cues/QWorkSpace.cs @@ -39,5 +39,13 @@ namespace qController } } } + public void PrintStats() + { + foreach (var cueList in data) + { + Console.WriteLine(cueList.listName + "("+ cueList.cues.Count + " cues)"); + + } + } } } diff --git a/qController.Standard/Pages/ControlPage.xaml.cs b/qController.Standard/Pages/ControlPage.xaml.cs index 7e2be56..6f19182 100644 --- a/qController.Standard/Pages/ControlPage.xaml.cs +++ b/qController.Standard/Pages/ControlPage.xaml.cs @@ -20,7 +20,7 @@ namespace qController qController.qClient.qParser.SelectedCueUpdated += SelectedCueUpdated; qController.qClient.qParser.WorkspaceUpdated += WorkspaceUpdated; qController.qClient.qParser.PlaybackPositionUpdated += PlaybackPositionUpdated; - qController.qClient.sendAndReceiveString("/cueLists"); + qController.qClient.qParser.CueInfoUpdated += OnCueUpdateReceived; NavigationPage.SetHasNavigationBar(this, false); instanceName.Text = name; @@ -183,6 +183,20 @@ namespace qController } } + public void OnCueUpdateReceived(object sender, CueEventArgs args) + { + qController.qWorkspace.UpdateCue(args.Cue); + Console.WriteLine("Cue updated in ControlPage: " + args.Cue.uniqueID); + if (args.Cue.uniqueID == qController.playbackPosition) + { + Console.WriteLine("Cue that was updated is equal to the playback position."); + Device.BeginInvokeOnMainThread(() => + { + qCell.UpdateSelectedCue(args.Cue); + }); + } + } + protected override void OnDisappearing() { base.OnDisappearing();