Пример #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();
                    }
                }
            };
        }
Пример #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;
                }
            }
        }
Пример #3
0
        public override void Initiate(Launchpad launchpad)
        {
            this.launchpad = launchpad as LaunchpadMk2;
            try
            {
                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    using (var fileStream = File.OpenText(@"Animations\initiate0.piskel"))
                    {
                        var contents = fileStream.ReadToEnd();
                        piskelFile   = new PiskelFile(contents);
                    }

                    var pngData = piskelFile.Layers.First().Chunks.First().Data;
                    bitmap      = SKBitmap.Decode(pngData);

                    var totalFrames = piskelFile.Layers.First().FrameCount;
                    var frameWidth  = bitmap.Width / totalFrames;

                    for (var frameIndex = 0; frameIndex < totalFrames; frameIndex++)
                    {
                        var frame   = new Color[frameWidth, bitmap.Height];
                        var xOffset = frameIndex * frameWidth;
                        for (var y = 0; y < bitmap.Height; y++)
                        {
                            for (var x = 0; x < frameWidth; x++)
                            {
                                var pixel   = bitmap.Pixels[bitmap.Width * y + (x + xOffset)];
                                frame[x, y] = Color.FromArgb(pixel.Alpha, pixel.Red, pixel.Green, pixel.Blue);
                            }
                        }
                        frames.Add(frame);
                    }


                    isInitiated = true;
                });
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }