Example #1
0
        /// <summary>
        /// Sends the test message.
        /// Only for testing the OSC Out connection.
        /// </summary>
        public void SendTestMessage()
        {
            OSCsharp.Data.OscMessage msg  = new OSCsharp.Data.OscMessage("/test", 1f);
            UniOSCEventArgs          args = new UniOSCEventArgs(oscOutPort, msg);

            args.IPAddress = oscOutIPAddress;
            SendOSCMessage(this, args);
        }
Example #2
0
        /// <summary>
        /// Sends the session data.
        /// This is useful for updating the GUI of TouOSC for example with the last data values from incomming OSC messages.
        /// You have to add a OSC Session file to the OSCConnection to use this feature.
        /// </summary>
        public void SendSessionData()
        {
            if (!hasOSCSessionFileAttached)
            {
                return;
            }
            lock (_sessionEventLock){
                foreach (var osf in oscSessionFileObjList)
                {
                    if (osf == null)
                    {
                        continue;
                    }
                    foreach (var osi  in osf.oscSessionItemList)
                    {
                        string address = osi.address;
                        if (String.IsNullOrEmpty(address))
                        {
                            continue;
                        }
                        OSCsharp.Data.OscMessage msg = new OSCsharp.Data.OscMessage(address);
                        for (int i = 0; i < osi.data.Count; i++)
                        {
                            float number;
                            bool  result = Single.TryParse(osi.data[i], out number);
                            if (result)
                            {
                                msg.Append(number);
                                //typecheck? osi.dataTypeList[i]
                                //msg.Append(Int32.Parse(osi.data[i]));
                            }
                        }

                        UniOSCEventArgs args = new UniOSCEventArgs(oscOutPort, msg);
                        args.IPAddress = oscOutIPAddress;
                        //give a delay for proper update of TouchOSC
                        //to prevent some lack at runtime we use a queue that is dequeued on _Update()
                        //In Editor mode  we stop the running thread for a millisecond.
                        //Otherwise part of the osc messages could be lost if we send to much udp packets at the same time
                        if (Application.isPlaying)
                        {
                            _sessionEventQueue.Enqueue(args);
                        }
                        else
                        {
                            Thread.Sleep(1);
                            SendOSCMessage(this, args);
                        }
                    }    //oscSessionItemList
                }        //oscSessionFileObjList
            }            //lock
        }