Exemple #1
0
 public void CheckAuthMessage(OscMessage message)
 {
     //Show GUI
     if (message.TryGet(0, out robotID) && message.TryGet(1, out robotHostName))
     {
         if (generalMagnager.mainHostName != null)
         {
             OnAuthorized();
         }
     }
 }
        void OnTest3( OscMessage message )
        {
            // Get string arguments at index 0 and 1 safely.
            string text0, text1;
            if( message.TryGet( 0, out text0 ) && message.TryGet( 1, out text1 ) ){
                Debug.Log( "Received: " + text0 + " " + text1 );
            }

            // If you wish to mess with the arguments yourself, you can.
            foreach( object a in message.args ) if( a is string ) Debug.Log( "Received: " + a );

            // NEVER DO THIS AT HOME
            // Never cast directly, without ensuring that index is inside bounds and encapsulating
            // the cast in try-catch statement.
            //float value = (float) message.args[0]; // No no!
        }
Exemple #3
0
        void OnTest2(OscMessage message)
        {
            // Get arguments from index 0, 1 and 2 safely.
            int   frameCount;
            float time;
            float random;

            if (
                message.TryGet(0, out frameCount) &&
                message.TryGet(1, out time) &&
                message.TryGet(2, out random)
                )
            {
                Debug.Log("Received test2\n" + frameCount + " " + time + " " + random + "\n");
            }

            // If you don't know what type of arguments to expect, then you
            // can check the type of each argument and get the ones you need.
            for (int i = 0; i < message.Count(); i++)
            {
                OscArgType argType;
                if (!message.TryGetArgType(i, out argType))
                {
                    continue;
                }

                switch (argType)
                {
                case OscArgType.Float:
                    float floatValue;
                    message.TryGet(i, out floatValue);
                    // Do something with floatValue here...
                    break;

                case OscArgType.Int:
                    int intValue;
                    message.TryGet(i, out intValue);
                    // Do something with intValue here...
                    break;
                }
            }

            // Always recycle incoming messages when used.
            OscPool.Recycle(message);
        }
        void OnMessageReceived( OscMessage message )
        {
            // Get the value
            float value;
            if( !message.TryGet( 0, out value ) ) return;

            // Update label
            receiveLabel.text = value.ToString();
        }
        void OnMessageReceived( OscMessage message )
        {
            // Get the time tag.
            OscTimeTag timeTag;
            if( !message.TryGet( 0, out timeTag ) ) return;

            // Update label.
            receiveLabel.text = timeTag.time + ":" + timeTag.time.Millisecond;
        }
Exemple #6
0
        void ParseRecievedNotice(OscMessage message)
        {
            string type = "";

            if (message.TryGet(0, ref type))
            {
                byte[] data = new byte[0];
                switch (type)
                {
                case "text":
                    if (message.TryGet(1, ref data))
                    {
                        int duration = 10;
                        message.TryGet(2, out duration);
                        ToryUX.ToryNotification.Instance.Show(System.Text.Encoding.UTF8.GetString(data), duration);
                    }
                    break;

                case "backgroundColor":
                    if (message.TryGet(1, ref data))
                    {
                        if (data.Length >= 4)
                        {
                            ToryUX.ToryNotification.Instance.SetBackgroundColor(new Color32(data[0], data[1], data[2], data[3]));
                        }
                    }
                    break;

                case "textColor":
                    if (message.TryGet(1, ref data))
                    {
                        if (data.Length >= 4)
                        {
                            ToryUX.ToryNotification.Instance.SetTextColor(new Color32(data[0], data[1], data[2], data[3]));
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            OscPool.Recycle(message);
        }
Exemple #7
0
        void ParseOscMessage(OscMessage oscMessage)
        {
            if (oscMessage.args.Count % 2 != 0)
            {
                Debug.LogWarning("Invalid Argument Count");
                return;
            }
            int kvCount = oscMessage.args.Count / 2;

            Debug.Log(kvCount);
            for (int i = 0; i < kvCount; i++)
            {
                int    objectID = 0;
                string stringID;
                string syncValue;
                bool   isIDreadable    = oscMessage.TryGet(i * 2, out stringID);
                bool   isValueReadable = oscMessage.TryGet(i * 2 + 1, out syncValue);
                if (!isIDreadable)
                {
                    Debug.LogWarning("Error Getting Data from OscMessage");
                }
                else
                {
                    objectID = int.Parse(stringID);
                }
                if (!isValueReadable)
                {
                    Debug.LogWarning("Error Getting Data from OscMessage");
                }
                if (isIDreadable && isValueReadable)
                {
                    if (!SceneVariables.ContainsKey(objectID))
                    {
                        SceneVariables.Add(objectID, syncValue);
                    }
                    else
                    {
                        SceneVariables[objectID] = syncValue;
                    }
                }
            }
        }
Exemple #8
0
        void OnMessageReceived(OscMessage message)
        {
            // Get the value
            float value;

            if (!message.TryGet(0, out value))
            {
                return;
            }

            // Update label
            receiveLabel.text = value.ToString();
        }
        void OnMessageReceived(OscMessage message)
        {
            // Get the time tag.
            OscTimeTag timeTag;

            if (!message.TryGet(0, out timeTag))
            {
                return;
            }

            // Update label.
            receiveLabel.text = timeTag.time + ":" + timeTag.time.Millisecond;
        }
    /// <summary>
    /// splits incoming OscMessage into StringArray
    /// returns in order: value, adress, sourcenumber, command
    /// </summary>
    public static string[] splitMessage(OscMessage input)
    {
        string[] results = new string[5];
        float    value;

        input.TryGet(0, out value);
        results[0] = value.ToString();                         // value
        results[1] = input.address;                            // adress
        results[2] = Regex.Match(input.address, @"\d+").Value; // sourceNumber
        var output = Regex.Replace(input.address, @"[\d-]", string.Empty);

        results[3] = Regex.Match(output, @"([^/]+$)").Value; //command
        return(results);
    }
Exemple #11
0
        void OnTest3(OscMessage message)
        {
            // Get string arguments at index 0 and 1 safely.
            string text0, text1;

            if (message.TryGet(0, out text0) && message.TryGet(1, out text1))
            {
                Debug.Log("Received: " + text0 + " " + text1);
            }

            // If you wish to mess with the arguments yourself, you can.
            foreach (object a in message.args)
            {
                if (a is string)
                {
                    Debug.Log("Received: " + a);
                }
            }

            // NEVER DO THIS AT HOME
            // Never cast directly, without ensuring that index is inside bounds and encapsulating
            // the cast in try-catch statement.
            //float value = (float) message.args[0]; // No no!
        }
Exemple #12
0
        void OnMessageReceived(OscMessage incomingMessage)
        {
            // Try to get the string from the message at arg index 0.
            if (incomingMessage.TryGet(0, ref _incomingText))
            {
                // We have now received a string that will only be
                // recreated (generate garbage) if it changes.

                // However, this Debug.Log call will generate garbage. Lots of it ;)
                Debug.Log(_incomingText);
            }

            // OPTIMISATION #4
            // Always recycle messages when you handle them yourself.
            OscPool.Recycle(incomingMessage);
        }
Exemple #13
0
    void Update()
    {
        if (_mappings == null)
        {
            return;
        }

        if (!isOpen)
        {
            return;
        }

        if (_mappingLookup == null || _dirtyMappings)
        {
            UpdateMappings();
        }

        if (invokeUnmappedQueue == null)
        {
            invokeUnmappedQueue = new Queue <OscMessage>();
        }
        if (invokeMappedQueue == null)
        {
            invokeMappedQueue = new Queue <KeyValuePair <OscMapping, OscMessage> >();
        }
        deadAddresses.Clear();

        // Lock while we mess with '_messages'
        lock ( _lock )
        {
            foreach (KeyValuePair <string, List <OscMessage> > pair in _messages)
            {
                List <OscMessage> groupedMessages = pair.Value;
                int gmCount = groupedMessages.Count;

                // Collect the dead
                if (gmCount == 0)
                {
                    deadAddresses.Add(pair.Key);
                    continue;
                }

                // Get messages and invoke mapped handlers
                int gmBegin = _filterDuplicates ? gmCount - 1 : 0;
                for (int gm = gmBegin; gm < gmCount; gm++)
                {
                    OscMessage message = groupedMessages[gm];
                    OscMapping mapping;
                    if (_mappingLookup.TryGetValue(message.address, out mapping))
                    {
                        // Enqueue mapped call
                        invokeMappedQueue.Enqueue(new KeyValuePair <OscMapping, OscMessage>(mapping, message));
                    }
                    else
                    {
                        // Enqueue unmapped (catch all) call
                        invokeUnmappedQueue.Enqueue(message);
                    }
                }

                // Clear address group
                groupedMessages.Clear();
            }

            // Remove the dead
            foreach (string address in deadAddresses)
            {
                _messages.Remove(address);
            }
        }

        // Count
        _messageCount = invokeUnmappedQueue.Count + invokeMappedQueue.Count;

        // Invoke handlers outside lock
        while (invokeUnmappedQueue.Count > 0)
        {
            _onAnyMessage.Invoke(invokeUnmappedQueue.Dequeue());
        }
        while (invokeMappedQueue.Count > 0)
        {
            KeyValuePair <OscMapping, OscMessage> pair = invokeMappedQueue.Dequeue();
            OscMapping mapping = pair.Key;
            OscMessage message = pair.Value;

            _onAnyMessage.Invoke(message);

            switch (mapping.type)
            {
            case OscMessageType.OscMessage:
                mapping.OscMessageHandler.Invoke(message);
                break;

            case OscMessageType.Float:
                float floatValue;
                if (message.TryGet(0, out floatValue))
                {
                    mapping.FloatHandler.Invoke(floatValue);
                }
                break;

            case OscMessageType.Double:
                double doubleValue;
                if (message.TryGet(0, out doubleValue))
                {
                    mapping.DoubleHandler.Invoke(doubleValue);
                }
                break;

            case OscMessageType.Int:
                int intValue;
                if (message.TryGet(0, out intValue))
                {
                    mapping.IntHandler.Invoke(intValue);
                }
                break;

            case OscMessageType.Long:
                long longValue;
                if (message.TryGet(0, out longValue))
                {
                    mapping.LongHandler.Invoke(longValue);
                }
                break;

            case OscMessageType.String:
                string stringValue;
                if (message.TryGet(0, out stringValue))
                {
                    mapping.StringHandler.Invoke(stringValue);
                }
                break;

            case OscMessageType.Char:
                char charValue;
                if (message.TryGet(0, out charValue))
                {
                    mapping.CharHandler.Invoke(charValue);
                }
                break;

            case OscMessageType.Bool:
                bool boolValue;
                if (message.TryGet(0, out boolValue))
                {
                    mapping.BoolHandler.Invoke(boolValue);
                }
                break;

            case OscMessageType.Color:
                Color32 colorValue;
                if (message.TryGet(0, out colorValue))
                {
                    mapping.ColorHandler.Invoke(colorValue);
                }
                break;

            case OscMessageType.Blob:
                byte[] blobValue;
                if (message.TryGet(0, out blobValue))
                {
                    mapping.BlobHandler.Invoke(blobValue);
                }
                break;

            case OscMessageType.TimeTag:
                OscTimeTag timeTagValue;
                if (message.TryGet(0, out timeTagValue))
                {
                    mapping.TimeTagHandler.Invoke(timeTagValue);
                }
                break;

            case OscMessageType.ImpulseNullEmpty:
                mapping.ImpulseNullEmptyHandler.Invoke();
                break;
            }
        }
    }
Exemple #14
0
    void InvokeMapping(OscMapping mapping, OscMessage message)
    {
        switch (mapping.type)
        {
        case OscMessageType.OscMessage:
            mapping.Invoke(message);
            break;

        case OscMessageType.Float:
            float floatValue;
            if (message.TryGet(0, out floatValue))
            {
                mapping.Invoke(floatValue);
                //Debug.Log( floatValue );
            }
            break;

        case OscMessageType.Double:
            double doubleValue;
            if (message.TryGet(0, out doubleValue))
            {
                mapping.Invoke(doubleValue);
            }
            break;

        case OscMessageType.Int:
            int intValue;
            if (message.TryGet(0, out intValue))
            {
                mapping.Invoke(intValue);
            }
            break;

        case OscMessageType.Long:
            long longValue;
            if (message.TryGet(0, out longValue))
            {
                mapping.Invoke(longValue);
            }
            break;

        case OscMessageType.String:
            string stringValue = string.Empty;
            if (message.TryGet(0, ref stringValue))
            {
                mapping.Invoke(stringValue);
            }
            break;

        case OscMessageType.Char:
            char charValue;
            if (message.TryGet(0, out charValue))
            {
                mapping.Invoke(charValue);
            }
            break;

        case OscMessageType.Bool:
            bool boolValue;
            if (message.TryGet(0, out boolValue))
            {
                mapping.Invoke(boolValue);
            }
            break;

        case OscMessageType.Color:
            Color32 colorValue;
            if (message.TryGet(0, out colorValue))
            {
                mapping.Invoke(colorValue);
            }
            break;

        case OscMessageType.Midi:
            OscMidiMessage midiValue;
            if (message.TryGet(0, out midiValue))
            {
                mapping.Invoke(midiValue);
            }
            break;

        case OscMessageType.Blob:
            byte[] blobValue = null;
            if (message.TryGet(0, ref blobValue))
            {
                mapping.Invoke(blobValue);
            }
            break;

        case OscMessageType.TimeTag:
            OscTimeTag timeTagValue;
            if (message.TryGet(0, out timeTagValue))
            {
                mapping.Invoke(timeTagValue);
            }
            break;

        case OscMessageType.ImpulseNullEmpty:
            mapping.Invoke();
            break;
        }
    }