/// <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); }
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); }
/// <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); }
/// <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); }
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); }
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 }
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 }
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 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 }
public void processEventFrame(FrameEventArgs e) { // 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. foreach (WiiContact pContact in e.Contacts) { // Compile the set message. OSCMessage pMessage = new OSCMessage("/tuio/2Dcur"); pMessage.Append("set"); // set pMessage.Append((int)pContact.ID); // session pMessage.Append((float)pContact.NormalPosition.X); // x pMessage.Append((float)pContact.NormalPosition.Y); // y pMessage.Append(0f); // dx pMessage.Append(0f); // dy pMessage.Append(0f); // motion pMessage.Append((float)pContact.Size.X); // height pMessage.Append((float)pContact.Size.Y); // width // Append it to the bundle. pBundle.Append(pMessage); // Append the alive message for this contact to tbe bundle. pMessageAlive.Append((int)pContact.ID); } // Save the alive message. pBundle.Append(pMessageAlive); // Send the message off. this.pUDPWriter.Send(pBundle); }
/// <summary> /// Sends a /tuio/2Dcur 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_2DCur(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 cursorBundle = new OSCBundle(); OSCMessage sourceMessage = TUIO_2DCur.sourceMessage(); cursorBundle.Append(sourceMessage); OSCMessage aliveMessage = TUIO_2DCur.aliveMessage(contacts); cursorBundle.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 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_2DCur.setMessage(c.Id, (float)x, (float)y, X, Y, motionAcceleration); cursorBundle.Append(setMessage); } OSCMessage frameMessage = TUIO_2DCur.frameMessage(_Frame); cursorBundle.Append(frameMessage); _Frame++; _OSCSender.Send(cursorBundle); }
public static OSCBundle CreateOSCBundle(params object[] msgs) { var bundle = new OSCBundle(); foreach (var msg in msgs) { bundle.Append(msg); } return(bundle); }
void timer1_Tick(object sender, EventArgs e) { var hosttime = Clock.ElapsedMilliseconds / 1000f; var bundle = new OSCBundle(); var prefix = "/" + PrefixTextBox.Text.Trim('/') + "/"; if (prefix == "//") { prefix = "/"; } lock (FPoshTimeliners) foreach (var timeliner in FPoshTimeliners) { timeliner.Evaluate(hosttime); var msg = new OSCMessage(prefix + "time"); msg.Append(timeliner.Timeliner.Timer.Time); bundle.Append(msg); foreach (var tl in timeliner.Timeliner.TimelineModel.Tracks) { var label = tl.Label.Value; //TODO: ask track to generate osc message var val = tl.GetCurrentValueAsObject(); msg = new OSCMessage(prefix + label); msg.Append(val); bundle.Append(msg); } //set interval for next round timer1.Interval = 1000 / timeliner.Timeliner.Timer.FPS; } if (FOSCTransmitter != null) { FOSCTransmitter.Send(bundle); } }
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; } } Bin bin = message[name]; var typeRecord = TypeIdentity.Instance[bin.GetInnerType()]; if (typeRecord == null || typeRecord.CloneMethod == CloneBehaviour.Null) { continue; } OSCMessage msg = new OSCMessage(oscAddress, extendedMode); for (int i = 0; i < bin.Count; i++) { msg.Append(bin[i]); } bundle.Append(msg); } return(new MemoryStream(bundle.BinaryData)); // packs implicitly }
public void Evaluate(int SpreadMax) { if (FUDPPort.IsChanged) { StopListeningOSC(); StartListeningOSC(); } FTouchID.SliceCount = 0; FTouchXY.SliceCount = 0; FTouchPressure.SliceCount = 0; //special treatment for bangs //which cause 2 patch messages in consecutive frames to be sent foreach (var pin in FBangs) { //set all the bangs values to 0 pin.Spread = "0"; } FBangs.Clear(); //process messagequeue //in order to handle all messages from main thread //since all COM-access is single threaded lock (FMessageQueue) { foreach (var message in FMessageQueue) { ProcessOSCMessage(message); } FMessageQueue.Clear(); } //send targets to kontrolleur var bundle = new OSCBundle(); foreach (var target in FTargets.Values) { if (target.State == RemoteValueState.Idle) { continue; } OSCMessage osc; if (target.State == RemoteValueState.Remove) { osc = new OSCMessage("/k/remove"); osc.Append(target.RuntimeNodePath); bundle.Append(osc); continue; } else if (target.State == RemoteValueState.Add) { osc = new OSCMessage("/k/add"); osc.Append(target.RuntimeNodePath); osc.Append(target.Name); osc.Append(target.Type); osc.Append(target.Default); osc.Append(target.Minimum); osc.Append(target.Maximum); osc.Append(target.Stepsize); osc.Append(target.Value); bundle.Append(osc); } else if (FAllowUpdates && target.State == RemoteValueState.Update) { osc = new OSCMessage("/k/update"); osc.Append(target.RuntimeNodePath); osc.Append(target.Name); osc.Append(target.Type); osc.Append(target.Default); osc.Append(target.Minimum); osc.Append(target.Maximum); osc.Append(target.Stepsize); osc.Append(target.Value); bundle.Append(osc); } } if (FOSCTransmitter != null) { try { FOSCTransmitter.Send(bundle); } catch (Exception ex) { FLogger.Log(LogType.Warning, "Kontrolleur: " + ex.Message); } } //remove unused targets foreach (var target in FTargets.ToArray()) { if (target.Value.State == RemoteValueState.Remove) { target.Value.Kill(); FTargets.Remove(target.Key); } else { target.Value.InvalidateState(); } } }
public void Evaluate(int SpreadMax) { if (!FInput.IsChanged && !FSelect.IsChanged && !FDistribute.IsChanged) { return; } if ((FInput.SliceCount == 0) || (FInput[0] == null) || (FInput[0].Length <= 1)) { return; } SpreadMax = FInput.SliceCount; var isFound = new Dictionary <string, bool>(); var messages = new List <OSCMessage>(); for (int i = 0; i < SpreadMax; i++) { var ms = new MemoryStream(); int index = FSelect[0] == SelectEnum.Last ? SpreadMax - i - 1 : i; FInput[index].Position = 0; // rewind stream FInput[index].CopyTo(ms); byte[] bytes = ms.ToArray(); int start = 0; OSCPacket packet = OSCPacket.Unpack(bytes, ref start, (int)FInput[index].Length); if (packet.IsBundle()) { var packets = ((OSCBundle)packet).Values; for (int j = 0; j < packets.Count; j++) { int innerIndex = FSelect[0] == SelectEnum.Last ? packets.Count - j - 1 : j; var innerMessage = (OSCMessage)packets[innerIndex]; if (FSelect[0] == SelectEnum.All) { messages.Add(innerMessage); } else { if (isFound.ContainsKey(innerMessage.Address)) { // do nothing. } else { isFound.Add(innerMessage.Address, true); messages.Add(innerMessage); } } } } else { if (FSelect[0] == SelectEnum.All) { messages.Add((OSCMessage)packet); } else { if (isFound.ContainsKey(packet.Address)) { // do nothing. } else { isFound.Add(packet.Address, true); messages.Add((OSCMessage)packet); } } } } // all unnecessary messages are gone. now try to distribute them. FOutput.SliceCount = 0; var bundles = new Dictionary <string, OSCBundle>(); var singleBundle = new OSCBundle(); foreach (var message in messages) { if (!FDistribute[0]) { singleBundle.Append(message); } else { var a = MainAddress(message.Address); if (!bundles.ContainsKey(a)) { bundles.Add(a, new OSCBundle()); } bundles[a].Append(message); } } FOutput.SliceCount = 0; if (!FDistribute[0]) { FOutput.Add(new MemoryStream((singleBundle.BinaryData))); } else { foreach (OSCBundle bundle in bundles.Values) { FOutput.Add(new MemoryStream((bundle.BinaryData))); } } FOutput.Flush(); }
public MainWindow() { this.Loaded += MainWindow_Loaded; InitializeComponent(); TouchInjector.InitializeTouchInjection(); mainCanvas.Width = Screen.PrimaryScreen.Bounds.Width; mainCanvas.Height = Screen.PrimaryScreen.Bounds.Height; BitmapImage bi0 = new BitmapImage(); bi0.BeginInit(); bi0.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor0.png"); bi0.EndInit(); BitmapImage bi1 = new BitmapImage(); bi1.BeginInit(); bi1.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor1.png"); bi1.EndInit(); cursorImageIndex.Source = bi0; cursorImageIndex.Width = cursorImageIndex.Height = 100; cursorImageThumb.Source = bi0; cursorImageThumb.Width = cursorImageThumb.Height = 100; cursorImageIndex.Opacity = 0; cursorImageThumb.Opacity = 0; IPC ipc = new IPC("win_cursor_plus"); ipc.MapFunction("exit", delegate(string messageBody) { ipc.Clear(); Environment.Exit(0); return(1); }); ipc.SetUDPCallback(delegate(string message) { if (message != "hide_cursor_index" || message != "hide_cursor_thumb") { string[] xyStr = message.Split('!'); if (xyStr.Length == 5) { cursorIndexDown = false; cursorThumbDown = false; float x; float y; float z; int down; bool b0 = float.TryParse(xyStr[0], System.Globalization.NumberStyles.Float, null, out x); bool b1 = float.TryParse(xyStr[1], System.Globalization.NumberStyles.Float, null, out y); bool b2 = float.TryParse(xyStr[2], System.Globalization.NumberStyles.Float, null, out z); bool b3 = int.TryParse(xyStr[3], System.Globalization.NumberStyles.Float, null, out down); if (b0 && b1 && b2) { if (xyStr[4] == "index") { xCursorIndex = x * screenWidth / 1000; if (xCursorIndex < 0) { xCursorIndex = 0; } else if (xCursorIndex > screenWidth) { xCursorIndex = screenWidth; } yCursorIndex = y * screenHeight / 1000; if (yCursorIndex < 0) { yCursorIndex = 0; } else if (yCursorIndex > screenHeight) { yCursorIndex = screenHeight; } zCursorIndex = z; showCursorIndex = true; cursorIndexDown = down == 1; } else if (xyStr[4] == "thumb") { xCursorThumb = x * screenWidth / 1000; if (xCursorThumb < 0) { xCursorThumb = 0; } else if (xCursorThumb > screenWidth) { xCursorThumb = screenWidth; } yCursorThumb = y * screenHeight / 1000; if (yCursorThumb < 0) { yCursorThumb = 0; } else if (yCursorThumb > screenHeight) { yCursorThumb = screenHeight; } zCursorThumb = z; showCursorThumb = true; cursorIndexDown = true; cursorThumbDown = true; } } } else if (message == "hide_cursor_index") { showCursorIndex = false; } else if (message == "hide_cursor_thumb") { showCursorThumb = false; } else if (xyStr.Length == 2 && xyStr[0] == "update") { updateNumNew = int.Parse(xyStr[1]); } } return(1); }); Timer ipcTimer = new Timer(); ipcTimer.Interval = 100; ipcTimer.Tick += delegate(object o, EventArgs e) { ipc.Update(); }; ipcTimer.Start(); Timer timer = new Timer(); timer.Interval = 20; timer.Tick += delegate(object o, EventArgs e) { if (updateNumNew == updateNumOld && showCursorIndex) { return; } updateNumOld = updateNumNew; if (!useTUIO && showCursorIndex) { if (!useFallback) { List <PointerTouchInfo> contacts = new List <PointerTouchInfo>(); if (cursorIndexDown && !cursorIndexDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndex, (int)yCursorIndex, 2, 1); contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; contacts.Add(contact); } else if (cursorIndexDown && cursorIndexDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndex, (int)yCursorIndex, 2, 1); contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; contacts.Add(contact); } else if (!cursorIndexDown && cursorIndexDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndexOld, (int)yCursorIndexOld, 2, 1); contact.PointerInfo.PointerFlags = PointerFlags.UP; contacts.Add(contact); } if (cursorThumbDown && !cursorThumbDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumb, (int)yCursorThumb, 2, 2); contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; contacts.Add(contact); } else if (cursorThumbDown && cursorThumbDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumb, (int)yCursorThumb, 2, 2); contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; contacts.Add(contact); } else if (!cursorThumbDown && cursorThumbDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumbOld, (int)yCursorThumbOld, 2, 2); contact.PointerInfo.PointerFlags = PointerFlags.UP; contacts.Add(contact); } bool success = TouchInjector.InjectTouchInput(contacts.Count, contacts.ToArray()); } else { System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)xCursorIndex, (int)yCursorIndex); if (cursorIndexDown) { mouseDown(); } else { mouseUp(); } } } else if (showCursorIndex) { Object[] tCur0 = new Object[7]; Object[] tCur1 = new Object[7]; OSCBundle bundle = new OSCBundle(); bundle.Append(TUIO.TUIOFseq(tuioFSeq)); ArrayList TUIOSessions = new ArrayList(); if (cursorIndexDown) { bundle.Append(TUIO.TUIO2DcurExt(0, xCursorIndex / screenWidth, yCursorIndex / screenHeight, 0, 0, 0, 10, 10)); TUIOSessions.Add(0); } if (cursorThumbDown) { bundle.Append(TUIO.TUIO2DcurExt(1, xCursorThumb / screenWidth, yCursorThumb / screenHeight, 0, 0, 0, 10, 10)); TUIOSessions.Add(1); } bundle.Append(TUIO.TUIOAlive(TUIOSessions)); transmitter.Send(bundle); tuioFSeq++; } if (showCursorIndex) { if (cursorIndexDown) { cursorImageIndex.Source = bi1; } else { cursorImageIndex.Source = bi0; } if (cursorImageIndex.Opacity < 1) { cursorImageIndex.Opacity += 0.2; } int cursorSize = (int)(zCursorIndex * 5 * (float)windowWidth / (float)screenWidth); if (cursorSize > 150) { cursorSize = 150; } else if (cursorSize < 50) { cursorSize = 50; } cursorImageIndex.Width = cursorImageIndex.Height = cursorSize; int xPosRemapped = (int)map_val(xCursorIndex, 0, screenWidth, 0, windowWidth); int yPosRemapped = (int)map_val(yCursorIndex, 0, screenHeight, 0, windowHeight); if (xPosRemapped < 0) { xPosRemapped = 0; } else if (xPosRemapped > screenWidth) { xPosRemapped = screenWidth; } if (yPosRemapped < 0) { yPosRemapped = 0; } else if (yPosRemapped > screenHeight) { yPosRemapped = screenHeight; } Canvas.SetLeft(cursorImageIndex, xPosRemapped - (cursorSize / 2)); Canvas.SetTop(cursorImageIndex, yPosRemapped - (cursorSize / 2)); } else if (cursorImageIndex.Opacity > 0) { cursorImageIndex.Opacity -= 0.2; } if (showCursorThumb) { if (cursorThumbDown) { cursorImageThumb.Source = bi1; } else { cursorImageThumb.Source = bi0; } if (cursorImageThumb.Opacity < 1) { cursorImageThumb.Opacity += 0.2; } int cursorSize = (int)(zCursorThumb * 5 * (float)windowWidth / (float)screenWidth); if (cursorSize > 150) { cursorSize = 150; } else if (cursorSize < 50) { cursorSize = 50; } cursorImageThumb.Width = cursorImageThumb.Height = cursorSize; int xPosRemapped = (int)map_val(xCursorThumb, 0, screenWidth, 0, windowWidth); int yPosRemapped = (int)map_val(yCursorThumb, 0, screenHeight, 0, windowHeight); if (xPosRemapped < 0) { xPosRemapped = 0; } else if (xPosRemapped > screenWidth) { xPosRemapped = screenWidth; } if (yPosRemapped < 0) { yPosRemapped = 0; } else if (yPosRemapped > screenHeight) { yPosRemapped = screenHeight; } Canvas.SetLeft(cursorImageThumb, xPosRemapped - (cursorSize / 2)); Canvas.SetTop(cursorImageThumb, yPosRemapped - (cursorSize / 2)); } else if (cursorImageThumb.Opacity > 0) { cursorImageThumb.Opacity -= 0.2; } cursorIndexDownOld = cursorIndexDown; cursorThumbDownOld = cursorThumbDown; xCursorThumbOld = xCursorThumb; yCursorThumbOld = yCursorThumb; zCursorThumbOld = zCursorThumb; xCursorIndexOld = xCursorIndex; yCursorIndexOld = yCursorIndex; zCursorIndexOld = zCursorIndex; }; timer.Start(); }
void AfterEvaluateCB() { if (EnableOSCCheckBox.Checked) { //double time; //GetCurrentTime(out time); OSCBundle bundle = new OSCBundle(); //send outputs as OSC for (int i = 0; i < FPluginHost.Outputs.Count; i++) { string pinname = FPluginHost.Outputs[i].Name; // pinname = pinname.Replace(" ", "_"); OSCMessage message = new OSCMessage(FOSCAddress + "/" + pinname); if (FPluginHost.Outputs[i] is TValuePin) { double val; for (int j = 0; j < (FPluginHost.Outputs[i] as TValuePin).SliceCount; j++) { (FPluginHost.Outputs[i] as TValuePin).GetValue(j, out val); message.Append((float)val); } } else if (FPluginHost.Outputs[i] is TStringPin) { string str; for (int j = 0; j < (FPluginHost.Outputs[i] as TStringPin).SliceCount; j++) { (FPluginHost.Outputs[i] as TStringPin).GetString(j, out str); message.Append(str); } } else if (FPluginHost.Outputs[i] is TColorPin) { RGBAColor col; for (int j = 0; j < (FPluginHost.Outputs[i] as TColorPin).SliceCount; j++) { (FPluginHost.Outputs[i] as TColorPin).GetColor(j, out col); message.Append(col.ToString()); } } bundle.Append(message); } try { if (FOSCTransmitter != null) { FOSCTransmitter.Send(bundle); } } catch (Exception ex) { DebugLog.Items.Add("UDP: " + ex.Message); } } bool redraw = false; for (int i = 0; i < FPluginHost.Inputs.Count; i++) { redraw |= (FPluginHost.Inputs[i] as TBasePin).PinIsChanged; FPinsChanged |= (FPluginHost.Inputs[i] as TBasePin).SliceCountIsChanged; (FPluginHost.Inputs[i] as TBasePin).Invalidate(); } if (redraw) { InputsPanel.Invalidate(); } redraw = false; for (int i = 0; i < FPluginHost.Outputs.Count; i++) { redraw |= (FPluginHost.Outputs[i] as TBasePin).PinIsChanged; FPinsChanged |= (FPluginHost.Outputs[i] as TBasePin).SliceCountIsChanged; (FPluginHost.Outputs[i] as TBasePin).Invalidate(); } if (redraw) { OutputsPanel.Invalidate(); } }
public static Message FromOSC(Stream stream, bool extendedMode = false, string messagePrefix = "", int contractAddress = 1) { if (stream == null || stream.Length <= 0) { return(null); } stream.Position = 0; byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); if (bytes.Length == 0) { return(null); } Message message = new Message(); var pack = OSCPacket.Unpack(bytes, extendedMode); bool useNesting; OSCBundle bundle; if (pack.IsBundle()) { bundle = (OSCBundle)pack; message.TimeStamp = bundle.getTimeStamp(); // if not set, will be 1.1.1900 useNesting = true; } else { bundle = new OSCBundle(extendedMode); var m = (OSCMessage)pack; bundle.Append(m); message.TimeStamp = Time.CurrentTime(); useNesting = false; } foreach (OSCMessage m in bundle.Values) { string[] address = m.Address.Trim(new char[] { '/' }).Split('/'); string messageAddress = string.Join(".", address.Take(Math.Max(1, address.Length - contractAddress)).ToArray()); if (messagePrefix.Trim() == "") { message.Topic = messageAddress; } else { message.Topic = messagePrefix + "." + messageAddress; } // empty messages are usually used for requesting data if (m.Values.Count <= 0) { // leave message emtpy, cannot infer type. } else { var usedTypes = ( from v in m.Values.ToArray() select v.GetType() ).Distinct(); string attribName = string.Join(".", address.Skip(Math.Max(0, address.Length - contractAddress)).ToArray()); if (usedTypes.Count() > 1) { var inner = new Message(message.Topic + "." + attribName); var max = m.Values.Count; for (int i = 0; i < max; i++) { var item = m.Values[i]; var num = i.ToString(); inner[num] = BinFactory.New(item.GetType()); inner[num].Add(item); } if (useNesting) { message[attribName] = BinFactory.New(inner); } else { message = inner; } } else { var bin = BinFactory.New(usedTypes.First()); bin.AssignFrom(m.Values); message[attribName] = bin; } } } return(message); }
/// <summary> /// Process an event frame and convert the data into a TUIO message. /// </summary> /// <param name="e"></param> private void processEventFrame(FrameEventArgs e) { // Obtain mutual exclusion. this.pCommunicationMutex.WaitOne(); // If Windows 7 events are enabled. if (bWindowsTouch) { // For every contact in the list of contacts. foreach (WiiContact pContact in e.Contacts) { // Construct a new HID frame based on the contact type. switch (pContact.Type) { case ContactType.Start: this.pTouchDevice.enqueueContact(HidContactState.Adding, pContact); break; case ContactType.Move: this.pTouchDevice.enqueueContact(HidContactState.Updated, pContact); break; case ContactType.End: this.pTouchDevice.enqueueContact(HidContactState.Removing, pContact); break; } } // Flush the contacts? this.pTouchDevice.sendContacts(); } // If TUIO events are enabled. if (bTUIOTouch) { // 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. foreach (WiiContact pContact in e.Contacts) { // Compile the set message. OSCMessage pMessage = new OSCMessage("/tuio/2Dcur"); pMessage.Append("set"); // set pMessage.Append((int)pContact.ID); // session pMessage.Append((float)pContact.NormalPosition.X); // x pMessage.Append((float)pContact.NormalPosition.Y); // y pMessage.Append(0f); // dx pMessage.Append(0f); // dy pMessage.Append(0f); // motion pMessage.Append((float)pContact.Size.X); // height pMessage.Append((float)pContact.Size.Y); // width // Append it to the bundle. pBundle.Append(pMessage); // Append the alive message for this contact to tbe bundle. pMessageAlive.Append((int)pContact.ID); } // Save the alive message. pBundle.Append(pMessageAlive); // Send the message off. this.pUDPWriter.Send(pBundle); } // And release it! pCommunicationMutex.ReleaseMutex(); }