示例#1
0
        public void Update(GameTime gameTime)
        {
            if (Buttons.Count == 0)
            {
                return;
            }

            HoverIndex = -1;

            for (int i = 0; i < Buttons.Count; i++)
            {
                Buttons[i].Update(gameTime);
                Buttons[i].IsSelected = false;

                if (Buttons[i].IsHovering)
                {
                    HoverIndex = i;
                }

                if (Buttons[i].IsClicked && Buttons[i].IsEnabled)
                {
                    CurrentIndex = i;
                    OnButtonChange?.Invoke();
                }
            }

            if (CurrentIndex > -1)
            {
                Buttons[CurrentIndex].IsSelected = true;
            }

            PreviousIndex = CurrentIndex;
        }
示例#2
0
        private void OnInputEvent(object sender, MidiEventReceivedEventArgs e)
        {
            switch (e.Event)
            {
            case NoteAftertouchEvent aftertouchEvent:
                var buttonEvt = new ButtonEvent(aftertouchEvent);
                OnButtonChange?.Invoke(this, new FaderPortButtonEventArgs(buttonEvt.Button, buttonEvt.State));
                return;

            case ControlChangeEvent controlChangeEvent:
            {
                if (_pendingSlider == null)
                {
                    _pendingSlider = controlChangeEvent;
                }
                else if (_pendingSlider.ControlNumber == 0x20)
                {
                    SliderPosition = _pendingSlider.ControlValue + (controlChangeEvent.ControlValue << 7);
                    _pendingSlider = null;
                }
                else
                {
                    _pendingSlider = controlChangeEvent;
                }
            }
            break;

            case PitchBendEvent pitchBendEvent:
                var up = pitchBendEvent.PitchValue == 0x80;
                break;
            }
        }
        // Get a new button from ControllerButtons Enum
        private ControllerButtons GetNewButton()
        {
            Array values = Enum.GetValues(typeof(ControllerButtons));

            m_PreviousButton = (ControllerButtons)values.GetValue((int)Random.Range(0, values.Length));
            OnButtonChange.Invoke(m_PreviousButton);
            return(m_PreviousButton);
        }
示例#4
0
 void Read(SerialPort port)
 {
     while (readPorts)
     {
         try
         {
             var msg = port.ReadLine();
             if (msg.StartsWith("btn1.down"))
             {
                 var args = new ButtonEventArgs("btn1", ButtonState.Down);
                 OnButtonDown?.Invoke(this, args);
                 OnButtonChange?.Invoke(this, args);
             }
             else if (msg.StartsWith("btn1.up"))
             {
                 var args = new ButtonEventArgs("btn1", ButtonState.Up);
                 OnButtonUp?.Invoke(this, args);
                 OnButtonChange?.Invoke(this, args);
             }
         }
         catch (TimeoutException e) { }
     }
 }
示例#5
0
        private void _device_ButtonPressed(object sender, ButtonPressEventArgs e)
        {
            var evt = new LaunchPadButtonEvent
            {
                Event = e
            };
            var btnName = "Unknown";

            if (e.Type == ButtonType.Grid)
            {
                evt.Button = _device[e.X, e.Y]; btnName = $"Grid({e.X},{e.Y})";
            }
            if (e.Type == ButtonType.Toolbar)
            {
                evt.Button = _device.GetButton(e.ToolbarButton); btnName = $"Toolbar({e.ToolbarButton})";
            }
            if (e.Type == ButtonType.Side)
            {
                evt.Button = _device.GetButton(e.SidebarButton); btnName = $"Side({e.SidebarButton})";
            }
            evt.Color    = GetColor(evt.Button.RedBrightness, evt.Button.GreenBrightness);
            evt.ButtonId = btnName;

            Log($"Button Event ({evt.ButtonId}) > {evt.Button.State}");

            string activeButtonStateText = null;

            lock (_activeButtons)
            {
                var btn = _activeButtons.Find((x) => x.Button == evt.Button);
                if (evt.Button.State == ButtonPressState.Up && btn != null)
                {
                    _activeButtons.Remove(btn);
                    activeButtonStateText = $"Deactivated, held for {(DateTime.Now - btn.TimePressed).TotalMilliseconds} ms.";
                }
                if (evt.Button.State == ButtonPressState.Down && btn == null)
                {
                    var bs = new ButtonState
                    {
                        Button      = evt.Button,
                        LastEvent   = evt,
                        TimePressed = DateTime.Now
                    };
                    _activeButtons.Add(bs);

                    activeButtonStateText = "Activated.";
                }
                else if (evt.Button.State == ButtonPressState.Down && btn != null)
                {
                    btn.TimePressed       = DateTime.Now;
                    btn.LastEvent         = evt;
                    activeButtonStateText = "Activated Again?";
                }
            }
            if (activeButtonStateText != null)
            {
                Log($"Button Activity ({evt.ButtonId}) > {activeButtonStateText}");
            }

            OnButtonChange?.Invoke(this, evt);
            if (e.Type == ButtonType.Grid)
            {
                OnGridButtonChange?.Invoke(this, evt);
            }
            if (e.Type == ButtonType.Toolbar)
            {
                OnToolbarButtonChange?.Invoke(this, evt);
            }
            if (e.Type == ButtonType.Side)
            {
                OnSideButtonChange?.Invoke(this, evt);
            }
        }