mirror of
https://github.com/jwetzell/qController.git
synced 2026-08-16 21:03:35 +00:00
Implement notes, and work on updating cue info
This commit is contained in:
@@ -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<object> arguments = new List<object>();
|
||||
List<object> 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", "");
|
||||
|
||||
@@ -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<byte> responseData = new List<byte>();
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user