Beispiel #1
0
 private void OscServiceMessageReceived(object sender, OscMessageReceivedArgs e)
 {
     CommandInfo cmdInfo;
     if (m_addressesToCommands.TryGetValue(e.Address, out cmdInfo))
     {
         ICommandClient cmdClient = m_commandService.GetClient(cmdInfo.CommandTag);
         if (cmdClient != null)
         {
             if (cmdClient.CanDoCommand(cmdInfo.CommandTag))
                 cmdClient.DoCommand(cmdInfo.CommandTag);
         }
         e.Handled = true;
     }
 }
        private void OscServiceMessageReceived(object sender, OscMessageReceivedArgs e)
        {
            CommandInfo cmdInfo;

            if (m_addressesToCommands.TryGetValue(e.Address, out cmdInfo))
            {
                ICommandClient cmdClient = m_commandService.GetClient(cmdInfo.CommandTag);
                if (cmdClient != null)
                {
                    if (cmdClient.CanDoCommand(cmdInfo.CommandTag))
                    {
                        cmdClient.DoCommand(cmdInfo.CommandTag);
                    }
                }
                e.Handled = true;
            }
        }
Beispiel #3
0
        // The main GUI thread will call this and clear out the current queue of OSC messages.
        private void ConsumeMessages()
        {
            List<OscMessage> messages;
            lock (m_incomingQueue)
            {
                messages = new List<OscMessage>(m_incomingQueue.Values);
                m_incomingQueue.Clear();
            }

            // Make a note of all OSC input devices that have contacted us. This allows for auto-configuration.
            // And give listeners to our MessageReceived event a chance to handle this message before we do
            //  further processing.
            int messagesHandled = 0;
            for(int i = 0; i < messages.Count; i++)
            {
                OscMessage message = messages[i];
                m_inputDevices.Add(message.SourceEndPoint);
                m_autoInputDevices.Add(message.SourceEndPoint);
                var args = new OscMessageReceivedArgs(message.Address, message.Data);
                OnMessageRecieved(args);
                if (args.Handled)
                {
                    messagesHandled++;
                    messages[i] = null;
                }
            }
            
            // Avoid expensive work if possible.
            if (messagesHandled == messages.Count)
                return;

            // Before accessing OscAddressInfo.Addressable, we must call this.
            CheckAddressableCache();

            // Set a flag so that when we set properties, we don't send OSC messages.
            // Also, this will make sure that we don't modify OscAddressInfo.Addressable while
            //  we're enumerating it.
            m_consumingMsg = true;

            try
            {
                // Only enter the transaction below if we receive useful OSC messages. Some client apps add
                //  a lot of overhead to each transaction, like re-drawing everything.
                var valuesToSet = new List<ValueSettingInfo>();
                foreach (OscMessage message in messages)
                {
                    // The message may have been handled already and removed from the list.
                    if (message == null)
                        continue;

                    // Make sure there's data before continuing.
                    if (message.Data.Count <= 0)
                        continue;

                    // Find matching OscAddressInfos
                    foreach (OscAddressInfo info in GetMatchingInfos(message.Address))
                    {
                        foreach (object addressable in info.Addressable)
                        {
                            object convertedData = ConvertOscData(message.Data, info.PropertyType);
                            if (convertedData != null)
                            {
                                valuesToSet.Add(new ValueSettingInfo(message.Address, addressable, convertedData, info));
                            }
                        }
                    }
                }

                if (valuesToSet.Count > 0)
                {
                    // If hundreds of objects are selected, DoTransaction() gives a critical performance boost.
                    // DoTransaction also enables undo/redo support.
                    m_transactionContext.DoTransaction(() =>
                    {
                        foreach (var valueToSet in valuesToSet)
                            SetValue(valueToSet.OscAddress, valueToSet.Addressable, valueToSet.ConvertedData, valueToSet.OscAddressInfo);
                    }, "OSC Input".Localize("The name of a command"));
                }
            }
            finally
            {
                m_consumingMsg = false;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Raises the MessageReceived event</summary>
 /// <param name="args">Event args containing the OSC address and data. Set the Handled
 /// property to true to avoid further processing.</param>
 protected virtual void OnMessageRecieved(OscMessageReceivedArgs args)
 {
     foreach (var del in m_messageReceivedDelegates)
     {
         if (args.Handled) //check first, in case derived class set Handled to true
             return;
         del.Invoke(this, args);
     }
 }
Beispiel #5
0
 /// <summary>
 /// Raises the MessageReceived event</summary>
 /// <param name="args">Event args containing the OSC address and data. Set the Handled
 /// property to true to avoid further processing.</param>
 protected override void OnMessageRecieved(OscMessageReceivedArgs args)
 {
     switch (args.Address)
     {
         case SolidAddress:
             SetRenderFlags(GlobalRenderFlags.Solid, args.Data);
             return;
         case WireAddress:
             SetRenderFlags(GlobalRenderFlags.WireFrame, args.Data);
             return;
         case SolidAndWireAddress:
             SetRenderFlags(GlobalRenderFlags.Solid | GlobalRenderFlags.WireFrame, args.Data);
             return;
         case TexturesAddress:
             SetRenderFlags(GlobalRenderFlags.Textured, args.Data);
             return;
         case LightingAddress:
             SetRenderFlags(GlobalRenderFlags.Lit, args.Data);
             return;
         case BackfacesAddress:
             SetRenderFlags(GlobalRenderFlags.RenderBackFace, args.Data);
             return;
         case ShadowsAddress:
             SetRenderFlags(GlobalRenderFlags.Shadows, args.Data);
             return;
         case NormalsAddress:
             SetRenderFlags(GlobalRenderFlags.RenderNormals, args.Data);
             return;
         case GlobalRecordA:
             if (IsOscDataTrue(args.Data))
                 RecordGlobalLighting(0);
             return;
         case GlobalRecallA:
             if (IsOscDataTrue(args.Data))
                 RecallGlobalLighting(0);
             return;
         case GlobalRecordB:
             if (IsOscDataTrue(args.Data))
                 RecordGlobalLighting(1);
             return;
         case GlobalRecallB:
             if (IsOscDataTrue(args.Data))
                 RecallGlobalLighting(1);
             return;
         case GlobalRecordC:
             if (IsOscDataTrue(args.Data))
                 RecordGlobalLighting(2);
             return;
         case GlobalRecallC:
             if (IsOscDataTrue(args.Data))
                 RecallGlobalLighting(2);
             return;
         case GlobalRecordD:
             if (IsOscDataTrue(args.Data))
                 RecordGlobalLighting(3);
             return;
         case GlobalRecallD:
             if (IsOscDataTrue(args.Data))
                 RecallGlobalLighting(3);
             return;
         case GlobalRecordE:
             if (IsOscDataTrue(args.Data))
                 RecordGlobalLighting(4);
             return;
         case GlobalRecallE:
             if (IsOscDataTrue(args.Data))
                 RecallGlobalLighting(4);
             return;
         case RecordA:
             if (IsOscDataTrue(args.Data))
                 RecordSelectedLight(0);
             return;
         case RecallA:
             if (IsOscDataTrue(args.Data))
                 RecallSelectedLight(0);
             return;
         case RecordB:
             if (IsOscDataTrue(args.Data))
                 RecordSelectedLight(1);
             return;
         case RecallB:
             if (IsOscDataTrue(args.Data))
                 RecallSelectedLight(1);
             return;
     }
     if (args.Address.Contains("GlobalAmbient"))
     {
         SetGlobalAmbientComponent(ActiveDirLight, args.Address, args.Data);
         return;
     }
     if (args.Address.Contains("GlobalSpecular"))
     {
         SetGlobalSpecularComponent(ActiveDirLight, args.Address, args.Data);
         return;
     }
     if (args.Address.Contains("GlobalDiffuse"))
     {
         SetGlobalDiffuseComponent(ActiveDirLight, args.Address, args.Data);
         return;
     }
     base.OnMessageRecieved(args);
 }