Exemple #1
0
    /// <summary>
    /// Creates an OSC Client (sends OSC messages) given an outgoing port and address.
    /// </summary>
    /// <param name="clientId">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="destination">
    /// A <see cref="IPAddress"/>
    /// </param>
    /// <param name="port">
    /// A <see cref="System.Int32"/>
    /// </param>
    public void CreateSender(string clientId, IPAddress destination, int port)
    {
        if (!_senders.ContainsKey(clientId))
        {
            SenderLog clientitem = new SenderLog();
            clientitem.sender   = new OSCSender(destination, port);
            clientitem.log      = new List <LogInfo>();
            clientitem.messages = new List <OSCMessage>();

            _senders.Add(clientId, clientitem);

            // Send test message
            string     testaddress = "/test/alive/";
            OSCMessage message     = new OSCMessage(testaddress, destination.ToString());
            message.Append(port); message.Append("OK");

            _senders[clientId].log.Add(new LogInfo {
                Timestamp = DateTime.UtcNow, Log = DataToString(message.Data)
            });

            _senders[clientId].messages.Add(message);

            _senders[clientId].sender.Send(message);
        }
    }
        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));
            }
        }
    /// <summary>
    /// Creates an OSC Client (sends OSC messages) given an outgoing port and address.
    /// </summary>
    /// <param name="clientId">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="destination">
    /// A <see cref="IPAddress"/>
    /// </param>
    /// <param name="port">
    /// A <see cref="System.Int32"/>
    /// </param>
    public void CreateClient(string clientId, IPAddress destination, int port)
    {
        if (m_DebugCreateNoServers)
        {
            return;
        }

        OSCClient newOSCClient = new OSCClient(destination, port);

        m_Clients.Add(newOSCClient);

        // Send test message
        string     testaddress = "/test/alive/";
        OSCMessage message     = new OSCMessage(testaddress, destination.ToString());

        message.Append(port); message.Append("OK");

        //_clients[clientId].log.Add(String.Concat(DateTime.UtcNow.ToString(),".",
        //                                         FormatMilliseconds(DateTime.Now.Millisecond), " : ",
        //                                         testaddress," ", DataToString(message.Data)));
        //_clients[clientId].messages.Add(message);
        newOSCClient.Send(message);

        Debug.Log("Client created. " + clientId + ", " + destination.ToString() + ", " + port.ToString() + " Client count: " + m_Clients.Count);
    }
Exemple #4
0
    public void sendOSC(string host, int port)
    {
        if (!hasChangedSinceLastUpdate)
        {
            return;
        }

        OSCMessage m = new OSCMessage("/joint/" + jointName);

        m.Append(relPos.x);
        m.Append(relPos.y);
        m.Append(relPos.z);

        float deltaUpdateTime = Time.time - lastSendTime;
        float speed           = Vector3.Distance(relPos, lastSendPos) / deltaUpdateTime;

        m.Append(speed);

        lastSendTime = Time.time;
        lastSendPos  = new Vector3(relPos.x, relPos.y, relPos.z);


        if (includeTimeStamp)
        {
            m.Append(Time.time);
        }

        OSCMaster.sendMessage(m, host, port);

        hasChangedSinceLastUpdate = false;
    }
    /// <summary>
    /// Creates an OSC Client (sends OSC messages) given an outgoing port and address.
    /// </summary>
    /// <param name="clientId">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="destination">
    /// A <see cref="IPAddress"/>
    /// </param>
    /// <param name="port">
    /// A <see cref="System.Int32"/>
    /// </param>
    public void CreateClient(string clientId, IPAddress destination, int port)
    {
        if (_clients.ContainsKey(clientId))
        {
            return;
        }
        ClientLog clientitem = new ClientLog();

        clientitem.client   = new OSCClient(destination, port);
        clientitem.log      = new List <string>();
        clientitem.messages = new List <OSCMessage>();

        _clients.Add(clientId, clientitem);

        // Send test message
        string     testaddress = "/test/alive/";
        OSCMessage message     = new OSCMessage(testaddress, destination.ToString());

        message.Append(port); message.Append("OK");

        _clients[clientId].log.Add(String.Concat(DateTime.UtcNow.ToString(), ".",
                                                 FormatMilliseconds(DateTime.Now.Millisecond), " : ",
                                                 testaddress, " ", DataToString(message.Data)));
        _clients[clientId].messages.Add(message);

        _clients[clientId].client.Send(message);
    }
Exemple #6
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            try
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FInDo[i])
                    {
                        var msg = new OSCMessage("/live/send");
                        msg.Append((int)FInTrack[i]);

                        msg.Append((int)FInSend[i]);

                        msg.Append((float)FInLevel[i]);
                        client.Send(msg);
                    }
                }
                FOutStatus[0] = "OK";
            }
            catch (Exception e)
            {
                FOutStatus[0] = e.Message;
            }
            //FLogger.Log(LogType.Debug, "hi tty!");
        }
Exemple #7
0
    public static void Send(this ISendOSC sender, string address, string targetIP, int targetPort)
    {
        OSCMessage message = new OSCMessage(address);

        message.Append(targetIP);
        message.Append(targetPort);
        sender.Send(message);
    }
    public static byte[] WrapAsOscPayload(this string address, long objectID, string payload)
    {
        OSCMessage message = new OSCMessage(address);

        message.Append(objectID);
        message.Append(payload);
        return(message.BinaryData);
    }
Exemple #9
0
    void sendTrackFeedback()
    {
        OSCMessage m = new OSCMessage("/bodyIsTracked");

        m.Append <int>(bodyIsTracked ? 1 : 0);
        m.Append(Time.time);
        OSCMaster.sendMessage(m, remoteHost, remotePort);
    }
Exemple #10
0
    void sendTouchFeedback()
    {
        OSCMessage m = new OSCMessage("/touch");

        m.Append <int>(simulateTouch?1:0);
        m.Append(Time.time);
        OSCMaster.sendMessage(m, remoteHost, remotePort);
    }
Exemple #11
0
        public static OSCMessage frameMessage(int frame)
        {
            OSCMessage message = new OSCMessage("/tuio/2Dobj");

            message.Append("fseq");
            message.Append(frame);
            return(message);
        }
        public static OSCMessage TUIOFseq(int fseq)
        {
            OSCMessage oscm = new OSCMessage("/tuio/2Dcur");

            oscm.Append("fseq");
            oscm.Append(fseq);
            return(oscm);
        }
    public static byte[] WrapAsOscPayload(this string address, int x, int y)
    {
        OSCMessage message = new OSCMessage(address);

        message.Append(x);
        message.Append(y);
        return(message.BinaryData);
    }
Exemple #14
0
    public void SendValue(string key, float value)
    {
        OSCMessage msg = new OSCMessage("/ckarvalue");

        msg.Append(key);
        msg.Append(value);

        osc.Send(msg);
    }
Exemple #15
0
        public static OSCMessage sourceMessage()
        {
            string     localIP = Helper.getLocalIP();
            OSCMessage message = new OSCMessage("/tuio/2Dobj");

            message.Append("source");
            message.Append("surface@" + localIP);
            return(message);
        }
        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>
    /// Create an Augmenta scene message with protocol V2.
    /// </summary>
    /// <param name="address"></param>
    /// <returns></returns>
    private OSCMessage CreateSceneMessageV2(string address)
    {
        var msg = new OSCMessage(address);

        msg.Append(_frameCounter);  // Frame number
        msg.Append(_pointsCount);   // Objects count
        msg.Append(width);          // Scene width
        msg.Append(height);         //Scene height

        return(msg);
    }
Exemple #18
0
        /// <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);
        }
Exemple #19
0
 void OnVideoLoaded(UnityEngine.Video.VideoPlayer vp)
 {
     if (oscClient != null)
     {
         OSCMessage message = new OSCMessage("/video-loaded");
         message.Append(myIP);
         message.Append(Path.GetFileName(vp.url));
         oscClient.Send(message);
     }
     DoNextCmd();
 }
Exemple #20
0
        public static OSCMessage aliveMessage(ReadOnlyTouchPointCollection contacts)
        {
            OSCMessage message = new OSCMessage("/tuio/2Dblb");

            message.Append("alive");
            for (int i = 0; i < contacts.Count; i++)
            {
                message.Append(contacts[i].Id);
            }
            return(message);
        }
Exemple #21
0
        public static OSCMessage aliveMessage(List <TouchPoint> contacts)
        {
            OSCMessage message = new OSCMessage("/tuio/2Dobj");

            message.Append("alive");
            for (int i = 0; i < contacts.Count; i++)
            {
                message.Append(contacts[i].Id);
            }
            return(message);
        }
        public static OSCMessage TUIOAlive(params object[] args)
        {
            OSCMessage oscm = new OSCMessage("/tuio/2Dcur");

            oscm.Append("alive");

            for (int I = 0; I < args.Length; I++)
            {
                oscm.Append(args[I]);
            }
            return(oscm);
        }
    private OSCMessage CreateSceneMessageV1(string address)
    {
        var msg = new OSCMessage(address);

        msg.Append(_frameCounter);
        //Compute point size
        msg.Append(instantiatedPoints.Count * 0.25f * (maxPointSize.x + minPointSize.x) * (maxPointSize.y + minPointSize.y));
        msg.Append(_pointsCount);
        //Compute average motion
        var velocitySum = Vector3.zero;

        foreach (var element in instantiatedPoints)
        {
            velocitySum += -element.Value.GetComponent <PointBehaviour>().normalizedVelocity;
        }

        if (instantiatedPoints.Count > 0)
        {
            velocitySum /= instantiatedPoints.Count;
        }

        msg.Append(velocitySum.x);
        msg.Append(velocitySum.z);
        msg.Append(Mathf.RoundToInt(width / pixelSize));
        msg.Append(Mathf.RoundToInt(height / pixelSize));
        msg.Append(100);

        return(msg);
    }
Exemple #24
0
    // Update is called once per frame
    void Update()
    {
        var playerOnBase = Vector3.Project(Player.transform.position, _speakerBase);

        _playerOnBaseGameObject.transform.position = playerOnBase;
        _playerOnBaseGameObject.transform.Rotate(new Vector3(0f, 45f, 0f));
        var i = 0;

        foreach (var source in _engine.Drops)
        {
            if (source == null)
            {
                return;
            }
            ComputeSpeakerValues(source);

            //   Debug.Log("Senfind OSC ...");

            //Start clip
            var packet = new OSCMessage("/live/play/clip");
            packet.Append(_engine.ActualFamily);
            packet.Append(source.GetComponent <DropBehaviour>().Id);
            myClient.Send(packet);

            //   /live/volume (int track, float volume(0.0 to 1.0))
            packet = new OSCMessage("/live/volume");
            packet.Append(source.GetComponent <DropBehaviour>().Id);
            packet.Append(Volume);
            myClient.Send(packet);

            // /live/master/pan        (int track, float pan(-1.0 to 1.0))             Sets master track's pan to pan
            packet = new OSCMessage("/live/master/pan");
            packet.Append(source.GetComponent <DropBehaviour>().Id);
            packet.Append(Pourcentage);
            myClient.Send(packet);
            i++;
            //var mouseDir = mousePos - charPos;
            //if (Vector3.Dot(right, mouseDir) < 0)
            //{
            //    //do right hand stuff
            //}
            //else
            //{
            //    //do left hand stuff
            //}
            //Player.transform.forward;
        }

        //  Debug.Log(" Closest point : " + Vector3.Project(Player.transform.position, Speaker1.transform.position - Speaker2.transform.position));
    }
        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);
        }
Exemple #26
0
    // Update is called once per frame
    void Update()
    {
        transform.localPosition = Vector3.Lerp(transform.localPosition, FTWPClient.planePosition, speed);

        int tPort = int.Parse(targetPort);

        // Convert local position in the kinect space to a world space position.
        OSCMessage m;

        m = new OSCMessage("/ftwp/position");
        m.Append <float>(transform.position.x);
        m.Append <float>(transform.position.y);
        m.Append <float>(transform.position.z);
        client.SendTo(m, targetHost, tPort);
    }
Exemple #27
0
        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);
                }
            }
        }
Exemple #28
0
    public void setOver(bool value)
    {
        if (over == value)
        {
            return;
        }

        over = value;
        foreach (MMSelectableObject mmo in mmos)
        {
            if (mmo != null)
            {
                mmo.overChanged(value);
            }
        }
        if (!selected && value)
        {
            overStartTime = Time.time;
        }

        OSCMessage m = new OSCMessage("/zone/" + id + "/over");

        m.Append(value?1:0);
        OSCMaster.sendMessage(m);
    }
Exemple #29
0
    public void setSelectedZone(MotionMapZone zone)
    {
        if (zone == selectedZone)
        {
            return;
        }
        if (selectedZone != null)
        {
            if (autoDeselectOnNewSelection)
            {
                selectedZone.setSelected(false);
            }
        }

        selectedZone = zone;

        if (selectedZone != null)
        {
            selectedZone.setSelected(true);
        }


        OSCMessage m = new OSCMessage("/lastSelectedZone");

        m.Append(selectedZone.id);
        OSCMaster.sendMessage(m);
    }
Exemple #30
0
    public void setSelectionProgression(float value)
    {
        if (!selected)
        {
            value = Mathf.Clamp01(value);
            if (value == selectionProgression)
            {
                // Debug.Log("Same value !");
                return;
            }

            foreach (MMSelectableObject mmo in mmos)
            {
                if (mmo != null)
                {
                    mmo.selectionProgress(value);
                }
            }

            selectionProgression = value;
            OSCMessage m = new OSCMessage("/zone/" + id + "/selectionProgress");
            m.Append(selectionProgression);
            OSCMaster.sendMessage(m);
        }
    }
Exemple #31
0
 public static void sendFloat(string address, float value)
 {
     OSCMessage msg = new OSCMessage(address);
     msg.Append<float>(value);
     client.Send(msg);
 }
Exemple #32
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {

            updateClient();
            this.viewModel.StatusMessage = "Running ...";

            try
            {
                // Get the list of Microsoft Bands paired to the phone.
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
                if (pairedBands.Length < 1)
                {
                    this.viewModel.StatusMessage = "This sample app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                    return;
                }

               
                // Connect to Microsoft Band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {

                    bool heartRateConsentGranted;

                    // Check whether the user has granted access to the HeartRate sensor.
                    if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() == UserConsent.Granted)
                    {
                        heartRateConsentGranted = true;
                    }
                    else
                    {
                        heartRateConsentGranted = await bandClient.SensorManager.HeartRate.RequestUserConsentAsync();
                    }

                    if (!heartRateConsentGranted)
                    {
                        this.viewModel.StatusMessage = "Access to the heart rate sensor is denied.";
                    }
                    else
                    {
                        int samplesReceived = 0; // the number of Accelerometer samples received

                        // Subscribe to Accelerometer data.
                        bandClient.SensorManager.HeartRate.ReadingChanged += (s, args) =>
                        {
                            
                            heartRate = args.SensorReading.HeartRate;
                            samplesReceived++;

                        };


                        bool gsrOK = false;
                        if (bandClient.SensorManager.Gsr.IsSupported)
                        {

                            bandClient.SensorManager.Gsr.ReadingChanged += (s, args) =>
                            {
                                gsr = args.SensorReading.Resistance;

                            };
                            gsrOK = true;
                        }
                        else
                        {
                            this.viewModel.StatusMessage = "Gsr sensor is not supported with your Band version. Microsoft Band 2 is required.";
                        }
                       

                        while (true)
                        {
                            await bandClient.SensorManager.HeartRate.StartReadingsAsync();
                            if(gsrOK) await bandClient.SensorManager.Gsr.StartReadingsAsync();

                            await Task.Delay(TimeSpan.FromSeconds(1));

                            await bandClient.SensorManager.HeartRate.StopReadingsAsync();
                            if(gsrOK) await bandClient.SensorManager.Gsr.StopReadingsAsync();

                            this.viewModel.StatusMessage = string.Format("Sending to {0}:{1}\nHeart Rate = {2}\nGSR = {3}",client.ClientIPAddress,client.Port, heartRate,gsr);

                            OSCMessage msg = new OSCMessage("/emotion/heart");
                            msg.Append<int>(heartRate);
                            client.Send(msg);

                            if (gsrOK)
                            {
                                OSCMessage msg2 = new OSCMessage("/emotion/gsr");
                                msg2.Append<int>(gsr);
                                client.Send(msg2);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.viewModel.StatusMessage = ex.StackTrace.ToString();
            }
        }