void processData(byte[] buffer) { OSCBundle bundle = OSCPacket.Unpack(buffer) as OSCBundle; if (bundle != null) { //Not currently checked, we probably should! //int fseq = TuioParser.GetSequenceNumber(bundle); if (!TuioParser.ContainsCursors(bundle)) { return; } List <int> alivecursors = TuioParser.GetAliveCursors(bundle); Dictionary <int, Tuio2DCursor> newcursors = TuioParser.GetCursors(bundle); // Remove the deleted ones removeNotAlive(alivecursors); //Process held/updated items updateSetCursors(newcursors, alivecursors); //Process new items addNewCursors(newcursors); } }
void Update() { if (queue == null) { return; } while (0 < queue.Count) { OSCPacket packet = queue.Dequeue() as OSCPacket; if (packet.IsBundle()) { // if OSCBundl OSCBundle bundle = packet as OSCBundle; foreach (OSCMessage msg in bundle.Data) { } } else { OSCMessage msg = packet as OSCMessage; if ("/unity_osc" == msg.Address) { if (onMsg != null) { onMsg(msg); } } } } }
void receiveData() //여기임 커서 정보 받는곳 { while (isrunning) { IPEndPoint ip = null; byte[] buffer = this.udpreceiver.Receive(ref ip); OSCBundle bundle = OSCPacket.Unpack(buffer) as OSCBundle; if (bundle != null) { //Not currently checked, we probably should! //int fseq = TuioParser.GetSequenceNumber(bundle); List <int> alivecursors = TuioParser.GetAliveCursors(bundle); Dictionary <int, Tuio2DCursor> newcursors = TuioParser.GetCursors(bundle); //System.Console.WriteLine("CursorTest"); // Remove the deleted ones removeNotAlive(alivecursors); //Process held/updated items updateSetCursors(newcursors, alivecursors); //Process new items addNewCursors(newcursors); this.ProcessUpdates(); } } }
public static Message FromOSC(Stream stream) { var ms = new MemoryStream(); stream.CopyTo(ms); var bytes = ms.ToArray(); var start = 0; var bundle = OSCBundle.Unpack(bytes, ref start, (int)stream.Length); var message = new Message(); foreach (OSCMessage m in bundle.Values) { var binList = new BinList(); binList.AssignFrom(m.Values); // does not clone implicitly var address = m.Address.Split('/'); var name = address[address.Length - 1]; address[address.Length - 1] = ""; var messageAddress = ""; foreach (var part in address) { if (part.Trim() != "") { messageAddress += "." + part; } } message.Address = messageAddress.Substring(1); message[name] = binList; } return(message); }
public Stream ToOSC() { OSCBundle bundle = new OSCBundle(this.TimeStamp.ToFileTime()); foreach (string name in MessageData.Keys) { string oscAddress = ""; foreach (string part in Address.Split('.')) { if (part.Trim() != "") { oscAddress += "/" + part; } } foreach (string part in name.Split('.')) { if (part.Trim() != "") { oscAddress += "/" + part; } } OSCMessage m = new OSCMessage(oscAddress); SpreadList bl = MessageData[name]; for (int i = 0; i < bl.Count; i++) { m.Append(bl[i]); } bundle.Append(m); } return(new MemoryStream(bundle.BinaryData)); // packs implicitly }
void UpdateOSC() { while (true) { OSCPacket msg = oscin.Receive(); if (msg != null) { OSCBundle b = (OSCBundle)msg; foreach (OSCPacket subm in b.Values) { parseMessage(subm, true); } //Debug.Log("message"); recognizor.received = true; //gotAMessage = false; } #region receive /*if (msg.IsBundle()) * { * OSCBundle b = (OSCBundle)msg; * foreach (OSCPacket subm in b.Values) * { * parseMessage(subm, flag_rec); * //Debug.Log("here"); * } * } * else * { * parseMessage(msg, flag_rec); * } * // }*/ #endregion } }
public Stream ToOSC() { var bundle = new OSCBundle(TimeStamp.ToFileTime()); foreach (var name in FDictionary.Keys) { var address = Address.Split('.'); var oscAddress = ""; foreach (var part in address) { if (part.Trim() != "") { oscAddress += "/" + part; } } var message = new OSCMessage(oscAddress + "/" + name); var binList = FDictionary[name]; foreach (var obj in binList) { message.Append(obj); } bundle.Append(message); } return(new MemoryStream(bundle.BinaryData)); // packs implicitly }
private void PinChanged(object sender, EventArgs e) { if ((FOSCTransmitter != null) && FFeedback[0]) { var pin = sender as IPin2; var pinPath = pin.ParentNode.GetNodePath(false) + "/" + pin.Name; var bundle = new OSCBundle(); var message = new OSCMessage(pinPath); for (int i = 0; i < pin.SliceCount; i++) { message.Append(pin[i]); } bundle.Append(message); try { FOSCTransmitter.Send(bundle); } catch (Exception ex) { FLogger.Log(LogType.Warning, "PinServer: " + ex.Message); } } }
public static Stream ToOSC(this Message message, bool extendedMode = false) { OSCBundle bundle = new OSCBundle(message.TimeStamp, extendedMode); foreach (string name in message.Fields) { string oscAddress = ""; foreach (string part in message.Topic.Split('.')) { if (part.Trim() != "") { oscAddress += "/" + part; } } foreach (string part in name.Split('.')) { if (part.Trim() != "") { oscAddress += "/" + part; } } OSCMessage msg = new OSCMessage(oscAddress, extendedMode); Bin bin = message[name]; for (int i = 0; i < bin.Count; i++) { msg.Append(bin[i]); } bundle.Append(msg); } return(new MemoryStream(bundle.BinaryData)); // packs implicitly }
// Update is called once per frame void Update() { if (!HasInit) { return; } while (queue.Count > 0) { OSCPacket packet = queue.Dequeue() as OSCPacket; if (packet.IsBundle()) { // OSCBundleの場合 OSCBundle bundle = packet as OSCBundle; foreach (OSCMessage msg in bundle.Data) { if (OSCMessageReceivedEvent != null) { OSCMessageReceivedEvent(msg); } } } else { OSCMessage msg = packet as OSCMessage; if (OSCMessageReceivedEvent != null) { OSCMessageReceivedEvent(msg); } } } }
private static void DrawBundle(OSCBundle bundle) { if (bundle != null) { if (bundle.Packets.Count > 0) { foreach (var bundlePacket in bundle.Packets) { EditorGUILayout.LabelField(_bundleContent, EditorStyles.boldLabel); EditorGUILayout.BeginVertical("box"); Packet(bundlePacket); EditorGUILayout.EndVertical(); } } else { EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField(_bundleEmptyContent, OSCEditorStyles.CenterLabel); EditorGUILayout.EndVertical(); } } }
public void UpdateListen() { if (!_isInit) { return; } while (_packets.Count > 0) { OSCPacket packet = _packets.Dequeue(); if (packet == null) { return; } if (packet.IsBundle()) { OSCBundle bundle = packet as OSCBundle; OnListenOSCBundle.SafeInvoke(bundle); } else { OSCMessage message = packet as OSCMessage; OnListenOSCMessage.SafeInvoke(message); } } }
void UpdateOSC() { while (true) { OSCPacket msg = oscin.Receive(); if (msg != null) { if (msg.IsBundle()) { //Debug.Log ("msg is bundle"); OSCBundle b = (OSCBundle)msg; foreach (OSCPacket subm in b.Values) { parseMessage(subm); } } else { // Debug.Log ("msg is singular"); parseMessage(msg); } } //Debug.Log("while loop works"); // Thread.Sleep( 5 ); } }
/// <summary> /// Sends a /tuio/2Dobj message /// The remote Host is specified in the appConfig /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification) /// </summary> /// <param name="contacts">Current acitve Contacts</param> /// <param name="previousContacts">Contacts from the previous frame</param> public void sendTUIO_2DObj(List <TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts) { //if (contacts.Count == 0) return; //#warning Properties about the device are now on the InteractiveSurfaceDevice class. //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurfaceDevice.PrimarySurfaceDevice; //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left; //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top; InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice; double width = surface.Right - surface.Left; double height = surface.Bottom - surface.Top; OSCBundle objectBundle = new OSCBundle(); OSCMessage sourceMessage = TUIO_2DObj.sourceMessage(); objectBundle.Append(sourceMessage); OSCMessage aliveMessage = TUIO_2DObj.aliveMessage(contacts); objectBundle.Append(aliveMessage); for (int i = 0; i < contacts.Count; i++) { TouchPoint c = contacts[i]; double x = (c.CenterX - surface.Left) / width; double y = (c.CenterY - surface.Top) / height; float angularVelocity = 0.0f; float angularAcceleration = 0.0f; if (previousContacts.Contains(c.Id)) { computeAngularVelocity(c, previousContacts.GetTouchPointFromId(c.Id), out angularVelocity, out angularAcceleration); } float X = 0.0f; float Y = 0.0f; getVelocity(c.Id, out X, out Y); //, InteractiveSurface.PrimarySurfaceDevice.); float motionAcceleration = 0.0f; getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp); //if (c.Tag.Value) { OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Value, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration); objectBundle.Append(setMessage); } /*else if (c.Tag.Series) * { * OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Series, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration); * objectBundle.Append(setMessage); * }*/ } OSCMessage frameMessage = TUIO_2DObj.frameMessage(_Frame); objectBundle.Append(frameMessage); _Frame++; _OSCSender.Send(objectBundle); }
OSCBundle createBundle() { OSCBundle bundle = new OSCBundle(); bundle.Append(createMessage()); bundle.Append(createMessage()); bundle.Append(createMessage()); return(bundle); }
private static void Send(string message) { OSCMessage messageOne = new OSCMessage(message); //one float argument //OSCMessage messageTwo = new OSCMessage("/address2", 5.0f, 3.2f, "attributes"); //two floats and a string OSCBundle bundle = new OSCBundle(messageOne); SendStringUdpAsync(ServerIP, ServerPort, bundle); }
public void processEventFrame() { // Create an new TUIO Bundle OSCBundle pBundle = new OSCBundle(); // Create a fseq message and save it. This is to associate a unique frame id with a bundle of SET and ALIVE. OSCMessage pMessageFseq = new OSCMessage("/tuio/2Dcur"); pMessageFseq.Append("fseq"); pMessageFseq.Append(++iFrame); //(int)e.Timestamp); pBundle.Append(pMessageFseq); // Create a alive message. OSCMessage pMessageAlive = new OSCMessage("/tuio/2Dcur"); pMessageAlive.Append("alive"); // Now we want to take the raw frame data and draw points based on its data. WiiContact contact; while (contactQueue.Count > 0) { contact = contactQueue.Dequeue(); if ((contact.Type == ContactType.Hover || contact.Type == ContactType.EndFromHover)) { //No hover yet } else { // Compile the set message. OSCMessage pMessage = new OSCMessage("/tuio/2Dcur"); pMessage.Append("set"); // set pMessage.Append((int)contact.ID); // session pMessage.Append((float)contact.NormalPosition.X); // x pMessage.Append((float)contact.NormalPosition.Y); // y pMessage.Append(0f); // dx pMessage.Append(0f); // dy pMessage.Append(0f); // motion pMessage.Append((float)contact.Size.X); // height pMessage.Append((float)contact.Size.Y); // width // Append it to the bundle. pBundle.Append(pMessage); // Append the alive message for this contact to tbe bundle. pMessageAlive.Append((int)contact.ID); } } // Save the alive message. pBundle.Append(pMessageAlive); // Send the message off. this.pUDPWriter.Send(pBundle); }
public static OSCBundle CreateOSCBundle(params object[] msgs) { var bundle = new OSCBundle(); foreach (var msg in msgs) { bundle.Append(msg); } return(bundle); }
void Update() { while (0 < queue.Count) { OSCPacket packet = queue.Dequeue() as OSCPacket; if (packet.IsBundle()) { // OSCBundleの場合 OSCBundle bundle = packet as OSCBundle; foreach (OSCMessage msg in bundle.Data) { // メッセージの中身にあわせた処理 } } else { // OSCMessageの場合はそのまま変換 OSCMessage msg = packet as OSCMessage; // メッセージの中身にあわせた処理 //InfoWindow.Log("osc: " + msg.Address); if (msg.Address == "/data") { if (msg.Data.Count >= 1) { dataDistributer.SetData(msg.Data[0].ToString()); logWriter.WriteLine(msg.Data[0].ToString()); } } else if (msg.Address == "/reset") { dataDistributer.Reset(); } else if (msg.Address == "/sim") { if (msg.Data.Count >= 1) { dataDistributer.SetSimulationData(msg.Data[0].ToString()); } } else if (msg.Address == "/simclear") { dataDistributer.ClearSimulationData(); } // 展示用 else if (msg.Address == "/start") { Debug.Log("receive /start"); dummySender.RestartDemoMode(); } } } }
/// <summary> /// Forward the given touch message. /// </summary> /// <param name="?"></param> public void Forward(TouchMessage Message) { // Skip bad messages if (Message == null) { return; } // If we have a bad startup condition. if (pUDPWriter == null) { return; } // Create an new TUIO Bundle OSCBundle pBundle = new OSCBundle(); // Create a fseq message and save it. This is to associate a unique frame id with a bundle of SET and ALIVE. OSCMessage pMessageFseq = new OSCMessage("/tuio/2Dcur"); pMessageFseq.Append("fseq"); pMessageFseq.Append(++iFrame); pBundle.Append(pMessageFseq); // Create a alive message. OSCMessage pMessageAlive = new OSCMessage("/tuio/2Dcur"); pMessageAlive.Append("alive"); // Compile the set message. OSCMessage pMessage = new OSCMessage("/tuio/2Dcur"); pMessage.Append("set"); // set pMessage.Append((int)Message.ID); // session pMessage.Append((float)Message.X); // x pMessage.Append((float)Message.Y); // y pMessage.Append(0f); // dx pMessage.Append(0f); // dy pMessage.Append(0f); // motion pMessage.Append(1f); // height pMessage.Append(1f); // width // Append it to the bundle. pBundle.Append(pMessage); // Append the alive message for this contact to tbe bundle. pMessageAlive.Append((int)Message.ID); // Save the alive message. pBundle.Append(pMessageAlive); // Send the message off. this.pUDPWriter.Send(pBundle); }
public static bool ContainsCursors(OSCBundle bundle) { foreach (object o in bundle.Values) { OSCMessage msg = (OSCMessage)o; if (msg.Address == "/tuio/2Dcur") { return(true); } } return(false); }
/// <summary> /// Sends a /tuio/2Dblb message /// The remote Host is specified in the appConfig /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification) /// </summary> /// <param name="contacts">Current active contacts</param> /// <param name="previousContacts">Contacts from the previous frame</param> public void sendTUIO_2DBlb(List <TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts) { //if (contacts.Count == 0) return; //#warning Properties about the device are now on the InteractiveSurfaceDevice class. //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice; //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left; //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top; InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice; double width = surface.Right - surface.Left; double height = surface.Bottom - surface.Top; OSCBundle blobBundle = new OSCBundle(); OSCMessage sourceMessage = TUIO_2DBlb.sourceMessage(); blobBundle.Append(sourceMessage); OSCMessage aliveMessage = TUIO_2DBlb.aliveMessage(contacts); blobBundle.Append(aliveMessage); for (int i = 0; i < contacts.Count; i++) { TouchPoint c = contacts[i]; double x = (c.CenterX - surface.Left) / width; double y = (c.CenterY - surface.Top) / height; double w = c.MajorAxis / surface.Width; double h = c.MinorAxis / surface.Height; double f = c.PhysicalArea / (surface.Width * surface.Height); float angularVelocity = 0.0f; float angularAcceleration = 0.0f; if (previousContacts.Contains(c.Id)) { computeAngularVelocity(c, previousContacts.GetTouchPointFromId(c.Id), out angularVelocity, out angularAcceleration); } float X = 0.0f; float Y = 0.0f; getVelocity(c.Id, out X, out Y); //, surface); float motionAcceleration = 0.0f; getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp); OSCMessage setMessage = TUIO_2DBlb.setMessage(c.Id, (float)x, (float)y, (float)c.Orientation, (float)w, (float)h, (float)(w * h), X, Y, angularVelocity, motionAcceleration, angularAcceleration); blobBundle.Append(setMessage); } OSCMessage frameMessage = TUIO_2DBlb.frameMessage(_Frame); blobBundle.Append(frameMessage); _Frame++; _OSCSender.Send(blobBundle); }
public static int GetSequenceNumber(OSCBundle pack) { int result = -1; List<OSCMessage> msgs = FindByCommand(pack, "/tuio/2Dcur","fseq"); if (msgs.Count > 0) { result = Convert.ToInt32((int)msgs[0].Values[1]); } return result; }
public void TestParse() { OSCMessage first = new OSCMessage("/address1", 1, 2, 3, "string"); OSCMessage second = new OSCMessage("/address2", 3, 4, 5, "otherstring"); OSCBundle bundle = new OSCBundle(first, second); OSCBundle parsed = OSCBundle.Parse(new BinaryReader(new MemoryStream(bundle.Bytes))); Assert.Equal(first.Bytes, parsed.Contents[0].Bytes); Assert.Equal(second.Bytes, parsed.Contents[1].Bytes); }
public static Dictionary<int, Tuio2DCursor> GetCursors(OSCBundle pack) { Dictionary<int, Tuio2DCursor> result = new Dictionary<int, Tuio2DCursor>(); List<OSCMessage> cursors = FindByCommand(pack, "/tuio/2Dcur", "set"); foreach (OSCMessage msg in cursors) { Tuio2DCursor cur = new Tuio2DCursor(msg); result.Add(cur.SessionID, cur); } return result; }
private void CreatePacket(object userData, string[] options, int selected) { if (selected == 0) { CurrentPacket = new OSCMessage("/address"); } else { CurrentPacket = new OSCBundle(); } FilePath = string.Empty; }
private void SendStatusUpdate() { OSCBundle bundle = new OSCBundle(); OSCMessage message = new OSCMessage("/tuio/2Dcur"); message.Append("source"); message.Append("MultiPoint TUIO"); bundle.Append(message); //_oscTransmitter.Send(message); message = new OSCMessage("/tuio/2Dcur"); message.Append("alive"); foreach (Cursor c in _cursors.Values) { message.Append(c.SessionID); } bundle.Append(message); //_oscTransmitter.Send(message); foreach (Cursor c in _cursors.Values) { float xPos = (float)((1 / (double)_windowWidth) * (c.Position.X - _windowLeft)); float yPos = (float)((1 / (double)_windowHeight) * (c.Position.Y - _windowTop)); message = new OSCMessage("/tuio/2Dcur"); message.Append("set"); message.Append(c.SessionID); message.Append(xPos); message.Append(yPos); message.Append(0.0f); message.Append(0.0f); message.Append(0.0f); bundle.Append(message as OSCPacket); } message = new OSCMessage("/tuio/2Dcur"); message.Append("fseq"); message.Append(_messageCounter); _messageCounter++; bundle.Append(message as OSCPacket); _oscTransmitter.Send(bundle); }
private void ProcessPacket(OSCPacket packet) { if (packet.IsBundle()) { OSCBundle bundle = packet as OSCBundle; foreach (object o in bundle.Values) { this.ProcessPacket(o as OSCPacket); } } else { this.ProcessMessage(packet as OSCMessage); } }
private void ParseBundle(OSCBundle bundle) { //Check for Bundle foreach (object oscData in bundle.Data) { if (oscData.GetType() == typeof(OSCMessage)) { ParseMessage((OSCMessage)oscData); } if (oscData.GetType() == typeof(OSCBundle)) { ParseBundle((OSCBundle)oscData); } } }
public static List <int> GetAliveCursors(OSCBundle pack) { List <int> result = new List <int>(); List <OSCMessage> alivecmd = FindByCommand(pack, "/tuio/2Dcur", "alive"); if (alivecmd.Count > 0) { for (int i = 1; i < alivecmd[0].Values.Count; i++) { int id = (int)alivecmd[0].Values[i]; result.Add(id); } } return(result); }