Exemplo n.º 1
0
        public LaunchpadManager()
        {
            _launchpad = LaunchpadMk2.GetInstance().Result;

            _launchpad.Clear();

            _launchpad.OnButtonStateChanged += button =>
            {
                if (_activeProfile == null)
                {
                    return;
                }

                if (button.State == LaunchpadButtonState.Pressed)
                {
                    if (button.X == 8)
                    {
                        // Profile changing buttons
                        var profileCandidate = _profiles.FirstOrDefault(x => x.LaunchpadCoord.Y == button.Y);

                        if (profileCandidate != null)
                        {
                            SetProfileActive(profileCandidate);
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Button @ {button.X},{button.Y} of profile {_activeProfile.Name} clicked!");
                        var clickableButton = _activeProfile.Buttons.FirstOrDefault(x => x.X == button.X && x.Y == button.Y);
                        var clickCallback   = clickableButton?.ClickCallback;
                        clickCallback?.Invoke();
                    }
                }
            };
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var launchpad = LaunchpadMk2.GetInstance().Result;

            var input = string.Empty;

            while (input != "q")
            {
                Console.Clear();
                Console.WriteLine("Welcome to the Novation Launchpad sample app.");
                Console.WriteLine("Please enter a command to see examples in action. Enter ? to get a list of all valid commands.");

                input = Console.ReadLine();
                switch (input.ToLower())
                {
                case "c":
                    launchpad.Clear();
                    break;

                case "piskel":
                    launchpad.RegisterEffect(new PiskelEffect("demo.piskel", true), 50);
                    break;

                case "piskelfreq":
                    Console.WriteLine("Enter the new frequency:");
                    if (!uint.TryParse(Console.ReadLine(), out uint piskelFrequency))
                    {
                        continue;
                    }
                    launchpad.Effects.First().Key.UpdateFrequency(piskelFrequency);
                    break;

                case "pulse":
                    Console.WriteLine("Pulse");
                    Console.WriteLine("Enter the button x value:");
                    if (!int.TryParse(Console.ReadLine(), out int pulseX))
                    {
                        continue;
                    }
                    Console.WriteLine("Enter the button y value:");
                    if (!int.TryParse(Console.ReadLine(), out int pulseY))
                    {
                        continue;
                    }
                    Console.WriteLine("Enter the color value as an int:");
                    if (!int.TryParse(Console.ReadLine(), out int pulseColor))
                    {
                        continue;
                    }
                    launchpad.PulseButton(pulseX, pulseY, LaunchpadMk2Color.DarkHotPink);
                    break;
                }
            }
        }