public override void Update(OSCMessage msg) { int pocket; int ball; if(msg.Values.Count >= 6) { // new api ball = 0; // not tracked pocket = 0; for(int i=0; i<6; i++) { if((int)msg.Values[i] >= 1) { pocket = i; break; } } } else { // legacy api pocket = (int) msg.Values[0]; ball = (int) msg.Values[1]; } if(OnPocket != null) { OnPocket(pocket, ball); } }
public static OSCMessage Create(string address, params object[] messages) { OSCMessage msg = new OSCMessage(address); for(int i=0; i<messages.Length; ++i) { msg.Append(messages[i]); } return msg; }
public Tuio2DCursor(OSCMessage message) { this.SessionID = Convert.ToInt32(message.Values[1]); this.PositionX = Convert.ToSingle(message.Values[2]); this.PositionY = Convert.ToSingle(message.Values[3]); this.VelocityX = Convert.ToSingle(message.Values[4]); this.VelocityY = Convert.ToSingle(message.Values[5]); this.Acceleration = Convert.ToSingle(message.Values[6]); }
public static List<int> GetAliveCursors(OSCMessage aliveMessage) { ArrayList values = aliveMessage.Values; List<int> result = new List<int>(); for (int i = 1; i < values.Count; i++) { int id = (int)values[i]; result.Add(id); } return result; }
public OSCMessage GetMessage() { OSCMessage msg = new OSCMessage("/tuio/2Dcur"); msg.Append("set"); msg.Append(this.SessionID); msg.Append(this.PositionX); msg.Append(this.PositionY); msg.Append(this.VelocityX); msg.Append(this.VelocityY); msg.Append(this.Acceleration); return msg; }
public void Send(OSCMessage message) { byte[] packet;// = message.BinaryData; // not reliable! int length;// = packet.Length; // SendPacket(packet, length); // ... occasionally screws up! game/init "game" works, but game/show "game" fails (claiming "game" wasn't included!) // when it screwed up, packet was 4 bytes shy! (48 v 52) packet = new byte[1000]; length = OscMessageToPacket(message, packet, 0, 1000); // DebugExtras.Log("alt length: "+length.ToString()); SendPacket(packet, length); if ( GhopperDaemon.detailedDebug ) DebugExtras.Log( message.ToString() ); }
void OnMessage(OSCMessage message) { // ignore other messages if (message.Address != address) return; ArrayList values = message.Values; float x = (float) values[0]; float y = (float) values[1]; Vector3 pos = transform.position; pos.x = p0.x + x * scale; pos.z = p0.z + y * scale; transform.position = pos; }
public Tuio2DBlob(OSCMessage message) { this.SessionID = Convert.ToInt32(message.Values[1]); this.PositionX = Convert.ToSingle(message.Values[2]); this.PositionY = Convert.ToSingle(message.Values[3]); this.Angle = Convert.ToSingle(message.Values[4]); this.Width = Convert.ToSingle(message.Values[5]); this.Height = Convert.ToSingle(message.Values[6]); this.Area = Convert.ToSingle(message.Values[7]); this.VelocityX = Convert.ToSingle(message.Values[8]); this.VelocityY = Convert.ToSingle(message.Values[9]); this.Rotation = Convert.ToSingle(message.Values[10]); this.MotionAcceleration = Convert.ToSingle(message.Values[11]); this.RotationAcceleration = Convert.ToSingle(message.Values[12]); }
void OnMessage(OSCMessage message) { Debug.Log(message.Address); ArrayList values = message.Values; for (int i = 0; i < values.Count; i++) { Debug.Log(values[i]); } float x = (float) values[0]; float y = (float) values[1]; Vector3 pos = transform.position; pos.x = p0.x + x; pos.z = p0.z + y; transform.position = pos; }
void OnTriggerEnter(Collider other) { Ball ball = other.GetComponent<Ball>(); if(ball != null) { // (int)pocket1 (int)pocket2 (int)pocket3 (int)pocket4 (int)pocket5 (int)pocket6 OSCMessage msg = new OSCMessage(Config.OSC_ADDRESS_POCKET); for(int i=0; i<6; ++i) { if((int)number == i) { msg.Append(1); } else { msg.Append(0); } } manager.SendOSCMessage(msg); // manager.SendOSCMessage(OSCMessage.Create(Config.OSC_ADDRESS_POCKET, (int) pocketNumber, (int) ball.ballNumber)); } }
public static OSCMessage Unpack(byte[] bytes, ref int start) { string address = unpackString(bytes, ref start); //Console.WriteLine("address: " + address); OSCMessage msg = new OSCMessage(address); char[] tags = unpackString(bytes, ref start).ToCharArray(); //Console.WriteLine("tags: " + new string(tags)); foreach(char tag in tags) { //Console.WriteLine("tag: " + tag + " @ "+start); if(tag == ',') continue; else if(tag == INTEGER) msg.Append(unpackInt(bytes, ref start)); else if(tag == LONG) msg.Append(unpackLong(bytes, ref start)); else if(tag == DOUBLE) msg.Append(unpackDouble(bytes, ref start)); else if(tag == FLOAT) msg.Append(unpackFloat(bytes, ref start)); else if(tag == STRING || tag == SYMBOL) msg.Append(unpackString(bytes, ref start)); else Console.WriteLine("unknown tag: "+tag); } return msg; }
public OSCMessage GetMessage() { OSCMessage msg = new OSCMessage("/tuio/2Dblb"); msg.Append("set"); msg.Append(this.SessionID); msg.Append(this.PositionX); msg.Append(this.PositionY); msg.Append(this.Angle); msg.Append(this.Width); msg.Append(this.Height); msg.Append(this.Area); msg.Append(this.VelocityX); msg.Append(this.VelocityY); msg.Append(this.Rotation); msg.Append(this.MotionAcceleration); msg.Append(this.RotationAcceleration); return msg; }
// Function: OnReceiveTuio // (Internal) Takes in TUIO OSC messages received from the daemon and sends them along to the TUIO tracker. // *May change with TUIO different implementation--currently sends a MakingThings' OscMessage to an OscMessageHandler* public void OnReceiveTuio(OSCMessage message) { // DebugExtras.Log("daemon received tuio"); // DebugLogOsc(message); // if (usingTouchReader) { // touchReader.tuioHandler( message ); // } // OSCMessage convertedMessage = new OSCMessage( message.Address ); // convertedMessage.SetValues( message.Values ); // tuioTracker.ReceiveTuio( convertedMessage ); }
// alternate pack method -- need to compare this with OSCMessage's & see where the issue is. private static int OscMessageToPacket(OSCMessage oscM, byte[] packet, int start, int length) { int index = start; index = InsertString(oscM.Address, packet, index, length); //if (oscM.Values.Count > 0) { StringBuilder tag = new StringBuilder(); tag.Append(","); int tagIndex = index; index += PadSize(2 + oscM.Values.Count); foreach (object o in oscM.Values) { if (o is int) { int i = (int)o; tag.Append("i"); packet[index++] = (byte)((i >> 24) & 0xFF); packet[index++] = (byte)((i >> 16) & 0xFF); packet[index++] = (byte)((i >> 8) & 0xFF); packet[index++] = (byte)((i) & 0xFF); } else { if (o is float) { float f = (float)o; tag.Append("f"); byte[] buffer = new byte[4]; MemoryStream ms = new MemoryStream(buffer); BinaryWriter bw = new BinaryWriter(ms); bw.Write(f); packet[index++] = buffer[3]; packet[index++] = buffer[2]; packet[index++] = buffer[1]; packet[index++] = buffer[0]; } else { if (o is string) { tag.Append("s"); index = InsertString(o.ToString(), packet, index, length); } else { tag.Append("?"); } } } } InsertString(tag.ToString(), packet, tagIndex, length); } return index; }
// Function: OnReceiveOtherOsc // (Internal) Takes in OscMessages received from the daemon that couldn't be matched to a known root address & logs them. public void OnReceiveOtherOsc( OSCMessage message ) { if ( detailedDebug ) DebugLogOsc( message ); }
public static int GetSequenceNumber(OSCMessage sequenceMessage) { int result = -1; result = Convert.ToInt32((int)sequenceMessage.Values[1]); return result; }
void routeMessage( OSCMessage msg ) { List<OSCMessageDelegate> handlers = null; // DebugExtras.Log(msg.ToString()); if ( addressListeners.ContainsKey( msg.Address ) ) { handlers = addressListeners[msg.Address]; foreach ( OSCMessageDelegate handler in handlers ) { handler( msg ); } } allMessageHandler( msg ); }
static void allMessageHandlerDefault( OSCMessage message ) { }
// Function: Send // (Internal) Sends an address and values to the Grasshopper daemon (outside of Unity). public void Send(string address, ArrayList values) { // DebugExtras.Log("ghDaemon: Send()"); OSCMessage msg = new OSCMessage(address); values.Insert( 0, "game"); // for message routing, the first value tells the daemon who the sender is (in all of our cases, it's the game!) msg.SetValues(values); if (oscSender.IsRunning()) { if (backlogOutgoing.Count > 0) { SendBacklog(); } oscSender.Send(msg); } else { DebugExtras.Log("socket ain't open yet."); consecutiveFails++; backlogOutgoing.Add(msg); Invoke("SendBacklog", retryWait); } }
// Function: OnReceiveOsc // Private. Takes in osc messages and routes them to internal sorting for /tuio/ (as OSC) or /ghpr/ (converted to <GhopperMessage>). void OnReceiveOsc(OSCMessage message) { // DebugExtras.Log("OnReceiveOsc!"); // if (message.Address.StartsWith(TOUCH_INPUT_ADDRESS)) { // OnReceiveTuio(message); // } else if (message.Address.StartsWith(GRASSHOPPER_API_ADDRESS)) { GhopperMessage ghMessage = new GhopperMessage(message.Address, message.Values); OnReceiveDaemonMessage(ghMessage); } else { OnReceiveOtherOsc(message); } }
public static Tuio2DCursor GetCursor(OSCMessage cursorMessage) { return new Tuio2DCursor(cursorMessage); }
void OnOscMessage(OSCMessage msg) { if(msg.Address == Config.OSC_ADDRESS_TICK) { foreach(var tracker in trackers.Values) { tracker.OnTick(); } } else { trackers[msg.Address].Update(msg); } }
// OLD // Mindstorm's original OSC->Cursors (the actual tracking step), split out of receiveData (above), // with the actual update moved into updateCursors // -- this assumes we're receiving bundles, which seems to be reasonable for TUIO, // but not necessarily for OSC // public void ReceiveTuio(OSCBundle bundle) // { // //Not currently checked, we probably should! // //int fseq = TuioParser.GetSequenceNumber(bundle); // // List<int> alivecursors = TuioParser.GetAliveCursors(bundle); // Dictionary<int, Tuio2DCursor> newcursors = TuioParser.GetCursors(bundle); // // updateCursors(newcursors, alivecursors); // } public void ReceiveTuio(OSCMessage message) { ArrayList values = message.Values; string command = ""; if (TuioParser.IsCursor(message.Address) && values.Count > 0) { command = (string)values[0]; switch ( command ) { case "alive": // first message in bundle (aside from "source", which is optional) -- indicates active touches // DebugExtras.Log("alive msg"); nextAliveCursors = TuioParser.GetAliveCursors(message); break; case "set": // occurs for every touch that changed/moved // DebugExtras.Log("set msg"); Tuio2DCursor newCursor = TuioParser.GetCursor(message); nextNewCursors.Add(newCursor.SessionID, newCursor); break; case "fseq": // last message in bundle -- indicates message's frame sequence (to check if message is in order) // DebugExtras.Log("fseq msg"); // since this is always at the end of the bundle in TUIO 1.1, this cues the update //Not currently checked, we probably should! (in case the bundle arrived out of sequence) //int fseq = TuioParser.GetSequenceNumber(message); updateCursors(nextNewCursors, nextAliveCursors); nextNewCursors.Clear(); break; } } }
// Function: DebugLogOsc // (Internal) Logs OSC message, if necessary. public void DebugLogOsc(OSCMessage oM) { DebugExtras.Log(oM.ToString()); }