Beispiel #1
0
        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);
        }
Beispiel #2
0
        public static Stream ToOSC(this Message message, bool extendedMode = false)
        {
            OSCBundle bundle = new OSCBundle(message.TimeStamp, extendedMode);
            foreach (string name in message.Attributes)
            {
                string oscAddress = "";

                foreach (string part in message.Address.Split('.'))
                {
                    if (part.Trim() != "") oscAddress += "/" + part;
                }

                foreach (string part in name.Split('.'))
                {
                    if (part.Trim() != "") oscAddress += "/" + part;
                }

                OSCMessage m = new OSCMessage(oscAddress, extendedMode);
                Bin bl = message[name];
                for (int i = 0; i < bl.Count; i++) m.Append(bl[i]);
                bundle.Append(m);
            }
            return new MemoryStream(bundle.BinaryData); // packs implicitly
        }
Beispiel #3
0
		public void SendToLiveTrack(string addr, string prop, object arg)
		{
			if( (FOSCTransmitter != null) && (addr != "") )
			{
				var bundle = new OSCBundle();
				var message = new OSCMessage(addr);
				
				message.Append(prop);
				
				if(arg is float) message.Append((float)arg);
				else 
					if(arg is double) message.Append((float)arg);
				else 
					if(arg is int) message.Append((int)arg);
				else 
					if(arg is bool) message.Append((bool)arg ? 1 : 0);
				else
					message.Append(arg.ToString());
				
				bundle.Append(message);
				
				try
				{
					FOSCTransmitter.Send(bundle);
					if(Debug) LogDebug(message.ToString());
				}
				catch (Exception ex)
				{
					LastError = ex.Message.ToString();
				}
			} else LastError = "ERROR: FOSCTransmitter is null!";
		}
Beispiel #4
0
		public void SendToLive(string addr, object[] args)
		{
			if( (FOSCTransmitter != null) && (addr != "") )
			{
				var bundle = new OSCBundle();
				var message = new OSCMessage(addr);
				
				for (int i = 0; i < args.Length; i++)
					message.Append(args[i]);
				
				bundle.Append(message);

				try
				{
					FOSCTransmitter.Send(bundle);
					if(Debug) LogDebug(message.ToString());
				}
				catch (Exception ex)
				{
					LastError = ex.Message.ToString();
				}
			}
		}
Beispiel #5
0
        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
        }
Beispiel #6
0
        public static OSCMessage Unpack(byte[] bytes, ref int start, bool extendedMode = false)
        {
            string address = unpackString(bytes, ref start);
            //Console.WriteLine("address: " + address);
            OSCMessage msg = new OSCMessage(address, extendedMode);

            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 if (tag == CHAR)
                {
                    msg.Append(unpackChar(bytes, ref start));
                }
                else if (tag == BLOB)
                {
                    msg.Append(unpackBlob(bytes, ref start));
                }
                //else if (tag == COLOR) msg.Append(unpackColor(bytes, ref start));
                else if (tag == TIMETAG)
                {
                    msg.Append(unpackTimeTag(bytes, ref start));
                }

//              here come the custom vvvv datatypes
                //else if (extendedMode)
                //{
                //    if (tag == VECTOR2D) msg.Append(unpackVector2D(bytes, ref start));
                //    else if (tag == VECTOR3D) msg.Append(unpackVector3D(bytes, ref start));
                //    else if (tag == QUATERNION) msg.Append(unpackVector4D(bytes, ref start));
                //    else if (tag == MATRIX4) msg.Append(unpackMatrix(bytes, ref start));
                //}
                else
                {
                    Console.WriteLine("unknown tag: " + tag);
                }
            }
            return(msg);
        }
Beispiel #7
0
        public static Stream ToOSC(this Message message, IEnumerable<FormularFieldDescriptor> fields, bool extendedMode = false)
        {
            string oscAddress = "";
            foreach (string part in message.Topic.Split('.'))
            {
                if (part.Trim() != "") oscAddress += "/" + part;
            }

            var msg = new OSCMessage(oscAddress, extendedMode);
            foreach (var field in fields)
            {
                var name = field.Name;

                Bin bin = message[field.Name];
                var size = bin == null ? 0 : bin.Count;
                var count = field.DefaultSize < 1 ? size : field.DefaultSize;

                for (int i = 0; i < count; i++)
                {
                    if (bin == null || i >= bin.Count)
                        msg.Append(TypeIdentity.Instance[field.Type].Default()); // send out defaults to keep the integrity of the osc message
                    else msg.Append(bin[i]);
                }

            }
            return new MemoryComStream(msg.BinaryData); // packs implicitly
        }
Beispiel #8
0
        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
        }
Beispiel #9
0
        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
        }
Beispiel #10
0
		public static OSCMessage Unpack(byte[] bytes, ref int start, bool extendedMode = false)
		{
			string address = unpackString(bytes, ref start);
			//Console.WriteLine("address: " + address);
			OSCMessage msg = new OSCMessage(address, extendedMode);

			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 if (tag == CHAR) msg.Append(unpackChar(bytes, ref start));
				else if (tag == BLOB) msg.Append(unpackBlob(bytes, ref start));
				else if (tag == COLOR) msg.Append(unpackColor(bytes, ref start));
				else if (tag == TIMETAG) msg.Append(unpackTimeTag(bytes, ref start));

				//              here come the custom vvvv datatypes
				else if (extendedMode)
				{
					if (tag == VECTOR2D) msg.Append(unpackVector2D(bytes, ref start));
					else if (tag == VECTOR3D) msg.Append(unpackVector3D(bytes, ref start));
					else if (tag == QUATERNION) msg.Append(unpackVector4D(bytes, ref start));
					else if (tag == MATRIX4) msg.Append(unpackMatrix(bytes, ref start));
				}
				else Console.WriteLine("unknown tag: " + tag);
			}
			return msg;
		}
Beispiel #11
0
        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);
        }
Beispiel #12
0
		/// <summary>
		/// Example 2
		/// Set value of surface
		/// </summary>
		static void SetValueOfSurface ()
		{
			var msg = new OSCMessage ("/surfaces/Quad 1/visible");
			msg.Append (0);
			communicator.Send (msg);
		}