コード例 #1
0
ファイル: OSCExtensions.cs プロジェクト: sebllll/vvvv-Message
        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
        }
コード例 #2
0
ファイル: LiveTrackNode.cs プロジェクト: zeos/Somaphone
		private void ProcessOSCMessage(OSCMessage message)
		{
			
			if(message.Address.StartsWith("/live_set/tracks/") && (message.Values.Count > 0))
			{
				ProcessTrackOSCMessage(message);
			}
			else switch (message.Address)
			{
				case "/live/song_length":
				{
					LiveSet.Length = (float) message.Values[0];
					FLength[0] = LiveSet.Length;
				}
				break;
				
				case "/live/master/level":
				{
					LiveSet.MasterLevel_L = (float)message.Values[0];
					LiveSet.MasterLevel_R = (float)message.Values[1];
				}
				break;
				
				case "/live/timecode":
				{
					LiveSet.timecode_beats = (float) message.Values[0];
					string bbu = (string)(message.Values[1]);
					string[] BBU = bbu.Split(' ');
					if(BBU.Length > 2)
					{
						Int32.TryParse(BBU[0], out LiveSet.timecode_bar);
						Int32.TryParse(BBU[1], out LiveSet.timecode_beat);
						Int32.TryParse(BBU[2], out LiveSet.timecode_tick);
					}
					LiveSet.timecode_SMPTE = (string)message.Values[2];
					
					bool state = ((int)message.Values[3] == 1) ? true : false;
					LiveSet.isPlaying = state;
					FPlaying[0] = state;
				}
				break;
				
				case "/live/record":
				{
					bool state = ((int)message.Values[0] == 1) ? true : false;
					LiveSet.isRecording = state;
					FRecording[0] = state;
				}
				break;
				
				case "/live/loop/active":
				{
					bool state = ((int)message.Values[0] == 1) ? true : false;
					LiveSet.isLooped = state;
					FLooped[0] = state;
				}
				break;
				
				case "/live/loop/start":
				{
					float pos = (float)message.Values[0];
					LiveSet.Loop_Start = pos;
					FLoopStart[0] = pos;
					LiveSet.Loop_End = LiveSet.Loop_Start + LiveSet.Loop_Length;
				}
				break;
				
				case "/live/loop/length":
				{
					float len = (float)message.Values[0];
					LiveSet.Loop_Length = len;
					FLoopLength[0] = len;
					LiveSet.Loop_End = LiveSet.Loop_Start + LiveSet.Loop_Length;
				}
				break;
				
				case "/live/signature/denominator":
				{
					int val = (int)message.Values[0];
					LiveSet.Sig_Denom = val;
					FSigDenom[0] = val;
				}
				break;
				
				case "/live/signature/numerator":
				{
					int val = (int)message.Values[0];
					LiveSet.Sig_Nom = val;
					FSigNom[0] = val;
				}
				break;
				
				case "/live/bpm":
				{
					float bpm = (float)message.Values[0];
					LiveSet.BPM = bpm;
					FBPM[0] = bpm;
				}
				break;
				
				//cues
				case "/live/cue":
				{
					//LiveSet.ClearCues();
					
					int cueID = (int)message.Values[0];
					string cueName = (string)message.Values[1];
					float cueTime  = (float)message.Values[2];
					
					LiveSet.addCue(cueID, cueName, cueTime);
					EnumManager.UpdateEnum("LiveSetCues", "None", LiveSet.getCuesNames());
				}
				break;
				
				default:
				break;
				
			}

		}
コード例 #3
0
ファイル: LiveTrackNode.cs プロジェクト: zeos/Somaphone
		private void ProcessTrackOSCMessage(OSCMessage message) 
		{
			char[] Sep = {'/'}; 
			
			// FLogger.Log(LogType.Debug, "OSC In: " + message.Address);
			
			string Prop = ""; 
			int TrackIndex = -1;
			AbletonLiveTrack track = null;
			
			var a = message.Address.Split(Sep);
			if(a.Length < 4) return;
			
			try
			{
				TrackIndex = Convert.ToInt32(a[3]); //get track ID
				Prop = a[4]; //get track Property
				track = LiveSet.GetTrackByIndex(TrackIndex); //get V4 track object
			
			}
			catch(Exception e)
			{
				FLogger.Log(LogType.Debug,e.Message);
				return;
			}
			/*
			FLogger.Log(LogType.Debug, "LIVE-TRACK: " 
						+ message.Address 
						+ " Index:" + TrackIndex.ToString() 
						+ " Property: " + Prop 
						//+ " Data: " + message.Values[0].ToString()
				);
			
			*/
			//process
			if((track != null) && (message.Values.Count>0) ) switch (Prop)
			{
				case "name":
				{
					if (message.Values[0] is string)
					{
						track.Name = (string)message.Values[0];
							
						//update tracks ENUM
						int cnt = EnumManager.GetEnumEntryCount("LiveSetTracks");
						bool found = false;
						for(int i = 0; i < cnt; i++)
						{
							var name = EnumManager.GetEnumEntry("LiveSetTracks", i);
							if(name == track.Name) { found = true; break; }
						}
						if(!found) EnumManager.AddEntry("LiveSetTracks", track.Name);
						//	EnumManager.UpdateEnum("LiveSetTracks", "None", LiveSet.GetTracksNames());
					}
					
				}
				break;
				
				case "level":
				{
					if(message.Values.Count == 2)
					{
						track.Level_L = (float)message.Values[0];
						track.Level_R = (float)message.Values[1];
						track.Level = (track.Level_L + track.Level_R) / 2;
					}
					//peak detection
					//peak on beat detection
					//max peak
					//accumulator
					//fft?
				}
				break;
				
				case "output":
				{
					track.Peak = (float)message.Values[0];
				}
				break;
				
				case "mute":
				{
					track.isMuted = ((int)message.Values[0] == 1) ? true : false;
				}
				break;
				
				case "solo":
				{
					track.isSolo = ((int)message.Values[0] == 1) ? true : false;
				}
				break;
				
				case "arm":
				{
					track.isArmed = ((int)message.Values[0] == 1) ? true : false;
				}
				break;
				
				case "volume":
				{
					if(message.Values[0] is float) track.Volume = (float)message.Values[0];
				}
				break;
				
				case "pan":
				{
					if(message.Values[0] is float) track.pan = (float)message.Values[0];
				}
				break;
				
				
				case "clip":
				{
					if(message.Values.Count == 2)
					{
						track.ActiveClipID = (int)message.Values[0];
						track.ActiveClipName = (string)message.Values[1];
						
					}
				}
				break; 
				
				case "clip_slot":
				{
					/*
					FLogger.Log(LogType.Debug, "clip_slot(" + TrackIndex.ToString() + ")  " +
						message.Values[0].ToString() + ": " + 
						message.Values[1].ToString()
					);
					*/
					if(message.Values.Count == 3)
					{
						var clip = track.AddClip((int)message.Values[0], message.Values[1].ToString(), -1);
						clip.Length_in_beats = (int)message.Values[2];
						LiveSet.RaiseNotifyRefresh();
					}
				}
				break; 
				
				
				default:
				break;
			}
		}
コード例 #4
0
ファイル: LiveTrackNode.cs プロジェクト: zeos/Somaphone
		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!";
		}
コード例 #5
0
ファイル: LiveTrackNode.cs プロジェクト: zeos/Somaphone
		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();
				}
			}
		}
コード例 #6
0
ファイル: Message.cs プロジェクト: michael-burk/Stimmen
        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
        }
コード例 #7
0
ファイル: OSCMessage.cs プロジェクト: seanD111/TabletNotifier
        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);
        }
コード例 #8
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
        }
コード例 #9
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
        }
コード例 #10
0
ファイル: Message.cs プロジェクト: smakhtin/vvvv-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
        }
コード例 #11
0
ファイル: OSCMessage.cs プロジェクト: cansik/madmapperapi
		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;
		}
コード例 #12
0
ファイル: Form1.cs プロジェクト: stahlnow/Timeliner
        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);
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: stahlnow/Timeliner
        void ProcessOSCMessage(OSCMessage message)
        {
            var address = message.Address;
            var args = message.Values;

            char[] s = {'/'};
            string[] path = address.Split(s);

            if (path[1] == PrefixTextBox.Text.Trim('/'))
                switch(path[2])
            {
                case "play":
                    {
                        var arg = (int) args[0];
                        FPoshTimeliners[0].Timeliner.Timer.Play(arg == 1);
                        break;
                    }
                case "stop":
                    {
                        FPoshTimeliners[0].Timeliner.Timer.Stop();
                        break;
                    }
                case "seek":
                    {
                        FPoshTimeliners[0].Timeliner.Timer.Time = (float) args[0];
                        break;
                    }
                case  "loop":
                    {
                        FPoshTimeliners[0].Timeliner.TimelineModel.Ruler.LoopStart.Value = (float) args[0];
                        FPoshTimeliners[0].Timeliner.TimelineModel.Ruler.LoopEnd.Value = (float) args[1];
                        FPoshTimeliners[0].Timeliner.TimelineView.UpdateScene();
                        break;
                    }
            }
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: cansik/madmapperapi
		/// <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);
		}