예제 #1
0
 public void Update(LaunchpadDevice device, IEnumerable <LaunchpadEvent> evnts)
 {
     for (int i = 0; i < _elements.Count; i++)
     {
         _elements[i].Update(device, evnts);
     }
 }
예제 #2
0
        public bool Connect(LaunchpadDevice device)
        {
            foreach (InputDevice id in DeviceManager.InputDevices)
            {
                if (id.Name.ToLower() == device._midiName.ToLower())
                {
                    targetInput = id;
                    id.Open();

                    targetInput.ControlChange += new ControlChangeHandler(controlPress);
                    targetInput.NoteOn        += new NoteOnHandler(midiPress);
                    targetInput.StartReceiving(null);
                }
            }
            foreach (OutputDevice od in DeviceManager.OutputDevices)
            {
                if (od.Name.ToLower() == device._midiName.ToLower())
                {
                    targetOutput = od;
                    od.Open();
                }
            }

            return(true); // targetInput.IsOpen && targetOutput.IsOpen;
        }
예제 #3
0
        public Snake(LaunchpadDevice device)
        {
            mLaunchpadDevice = device;

            mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;

            Restart();
        }
예제 #4
0
 /// <summary>
 /// Disconnects a given LaunchpadDevice
 /// </summary>
 /// <param name="device">The Launchpad to disconnect.</param>
 /// <returns>Returns bool if disconnection was successful.</returns>
 public bool disconnect(LaunchpadDevice device)
 {
     if (targetInput.IsOpen && targetOutput.IsOpen)
     {
         targetInput.StopReceiving();
         targetInput.Close();
         targetOutput.Close();
     }
     return(!targetInput.IsOpen && !targetOutput.IsOpen);
 }
예제 #5
0
 protected void Draw(LaunchpadDevice device)
 {
     for (int i = 0; i < _elements.Count; i++)
     {
         if (_elements[i]._isInvalidated)
         {
             _elements[i].Draw(device);
             _elements[i]._isInvalidated = false;
         }
     }
 }
예제 #6
0
        public Reversi(LaunchpadDevice device)
        {
            mLaunchpadDevice = device;

            mLaunchpadDevice.DoubleBuffered = false;
            mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;

            mOutputDevice = OutputDevice.InstalledDevices[0];
            mOutputDevice.Open();

            Restart();
        }
예제 #7
0
        public RainSequencer(LaunchpadDevice device)
        {
            mLaunchpadDevice = device;
            mOutputDevice    = OutputDevice.InstalledDevices[0];
            mOutputDevice.Open();

            mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;

/*
 *                      Random rand = new Random();
 *                      for (int y = 0; y < NumRows; y++)
 *                              for (int x = 0; x < NumRows; x++)
 *                                      if (rand.Next(0, 12) == 0)
 *                                              mSequence[x, y] = true;
 * */
        }
        // Dictionary<int[], DeviceAction> keyActions = new Dictionary<int[], DeviceAction>(); //int[]: 0=x, 1=y, 3=yMax

        public MidiManager()
        {
            try
            {
                launchpad = new LaunchpadDevice();
                launchpad.DoubleBuffered = true;
                launchpad.ButtonPressed += packetRecievedEvent;

                Console.WriteLine("Launchpad found");
            }
            catch (Exception e)
            {
                Console.WriteLine("No launchpad found");
                Console.WriteLine(e);
            }
        }
예제 #9
0
        public ToggleGrid(LaunchpadDevice device)
        {
            mLaunchpadDevice = device;

            mLaunchpadDevice.DoubleBuffered = false;
            mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;

            mLaunchpadDevice.GetButton(ToolbarButton.Session).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);

            /*
             * for (int y = 0; y < 4; y++) {
             *      for (int x = 0; x < 4; x++) {
             *              mLaunchpadDevice[x, y].SetBrightness((ButtonBrightness)x, (ButtonBrightness)y);
             *      }
             * }
             */
        }
예제 #10
0
 /// <summary>
 /// Connects specific launchpad or auto connect or only refresh list
 /// </summary>
 /// <param name="id">Midi device Id. leave empty to only refresh device list</param>
 private void ConnectLaunchpad(string id = "")
 {
     if (id == "" || devices == null)
     {
         devices = Launchpad.Engines.Winmm.WinmmMidiDevices.GetLaunchpads();
     }
     if (devices.Count == 0)
     {
         MessageBox.Show("Launchpad not found. Please try again", "Error", MessageBoxButtons.OK);
         return;
     }
     // disconnect if necessary
     if (connectingDevice != null && connectingDevice.Id != id && id != "")
     {
         connectingDevice.Stop();
         connectingDevice = null;
     }
     // if device not yet connected for whatever reason
     if (connectingDevice == null)
     {
         if (id == "")
         {
             connectingDevice = new LaunchpadDevice(devices[devices.Count - 1]);
         }
         else
         {
             foreach (var device in devices)
             {
                 if (device.Id == id)
                 {
                     connectingDevice = new LaunchpadDevice(device);
                     break;
                 }
             }
         }
         if (connectingDevice != null)
         {
             connectingDevice.Start(140, 0);
         }
         else
         {
             MessageBox.Show("Selected device not found", "Error", MessageBoxButtons.OK);
         }
     }
 }
예제 #11
0
        private void StateMonitorThread()
        {
            _device = new LaunchpadDevice();
            _device.DoubleBuffered = true;
            _device.Reset();
            _device.ButtonPressed += _device_ButtonPressed;
            _activeButtons         = new List <ButtonState>();

            IsRunning = true;
            Log("Started.");


            while (IsRunning)
            {
                var active  = GetActiveButtons();
                var removed = new List <ButtonState>();
                foreach (var b in active)
                {
                    if (b.Button.State != ButtonPressState.Down)
                    {
                        removed.Add(b);
                    }
                }
                foreach (var b in removed)
                {
                    _device_ButtonPressed(this, b.LastEvent.Event);
                }


                Thread.Sleep(_debounceLimitMs);
            }

            if (_device != null)
            {
                _device.ButtonPressed -= _device_ButtonPressed;
                _device.Reset();
                _activeButtons = new List <ButtonState>();
            }

            _device   = null;
            IsRunning = false;
            Log("Stopped.");
            _stateMonitor = null;
        }
예제 #12
0
        /// <summary>
        /// Function to connect with a LaunchpadDevice
        /// </summary>
        /// <param name="device">The Launchpad to connect to.</param>
        /// <returns>Returns bool if connection was successful.</returns>
        public bool connect(LaunchpadDevice device)
        {
            string inName  = String.Empty;
            string outName = String.Empty;

            if (device._isLegacy)
            {
                inName      = device._midiName.ToLower();
                outName     = inName;
                sysexHeader = new byte[] { 240, 00, 32, 41, 2, 24 };
                IsLegacy    = true;
            }
            else
            {
                inName      = device._midiIn.ToLower();
                outName     = device._midiOut.ToLower();;
                sysexHeader = new byte[] { 240, 00, 32, 41, 2, 13 };
                IsLegacy    = false;
            }
            foreach (InputDevice id in DeviceManager.InputDevices)
            {
                if (id.Name.ToLower() == inName)
                {
                    targetInput = id;
                    id.Open();
                    targetInput.NoteOn        += new NoteOnHandler(midiPress);
                    targetInput.ControlChange += new ControlChangeHandler(controlChangePress);
                    targetInput.StartReceiving(null);
                }
            }
            foreach (OutputDevice od in DeviceManager.OutputDevices)
            {
                if (od.Name.ToLower() == outName)
                {
                    targetOutput = od;
                    od.Open();
                }
            }
            Connected = targetInput.IsOpen && targetOutput.IsOpen;
            return(Connected);
        }
예제 #13
0
 public override void Draw(LaunchpadDevice device)
 {
     for (int i = 0, y = 8, x = 0; i < Math.Min(_items.Count, 64); i++)
     {
         if (i < _items.Count)
         {
             device.Set(x, y, _items[i].Light);
         }
         else
         {
             device.SetOff(x, y);
         }
         if (++x >= 8)
         {
             if (--y < 0)
             {
                 break;
             }
         }
     }
 }
예제 #14
0
        /// <summary>
        /// Function to connect with a LaunchpadDevice
        /// </summary>
        /// <param name="device">The Launchpad to connect to.</param>
        /// <returns>Returns bool if connection was successful.</returns>
        public bool connect(LaunchpadDevice device)
        {
            foreach (InputDevice id in Midi.InputDevice.InstalledDevices)
            {
                if (id.Name.ToLower() == device._midiName.ToLower())
                {
                    targetInput = id;
                    Console.WriteLine($"Connecting to : {id.Name}");
                    targetInput.Open();
                    if (id.Name == "Launchpad MK2")
                    {
                        Console.WriteLine($"Detected as MK2, using updated button positions");
                        rowBasePitch  = rowBasePitch_launchpadmk2;
                        ccBaseControl = ccBaseControl_launchpadmk2;
                        launchpadType = LaunchpadType.MK2;
                    }
                    else
                    {
                        rowBasePitch  = rowBasePitch_launchpadMini; // works-ish with a lot of them
                        ccBaseControl = ccBaseControl_launchpadMini;
                        launchpadType = LaunchpadType.Mini;
                    }
                    Console.WriteLine($"isReceiving: {targetInput.IsReceiving}, open: {targetInput.IsOpen}");
                    targetInput.NoteOn        += new InputDevice.NoteOnHandler(midiPress);
                    targetInput.ControlChange += new InputDevice.ControlChangeHandler(midiCC);
                    targetInput.StartReceiving(null);
                }
            }
            foreach (OutputDevice od in Midi.OutputDevice.InstalledDevices)
            {
                if (od.Name.ToLower() == device._midiName.ToLower())
                {
                    targetOutput = od;
                    od.Open();
                }
            }

            return(true); // targetInput.IsOpen && targetOutput.IsOpen;
        }
예제 #15
0
        /// <summary>
        /// Function to connect with a LaunchpadDevice
        /// </summary>
        /// <param name="device">The Launchpad to connect to.</param>
        /// <returns>Returns bool if connection was successful.</returns>
        public bool connect(LaunchpadDevice device)
        {
            foreach (InputDevice id in Midi.InputDevice.InstalledDevices)
            {
                if (id.Name.ToLower() == device._midiName.ToLower())
                {
                    targetInput = id;
                    id.Open();
                    targetInput.NoteOn += new InputDevice.NoteOnHandler(midiPress);
                    targetInput.StartReceiving(null);
                }
            }
            foreach (OutputDevice od in Midi.OutputDevice.InstalledDevices)
            {
                if (od.Name.ToLower() == device._midiName.ToLower())
                {
                    targetOutput = od;
                    od.Open();
                }
            }

            return(true); // targetInput.IsOpen && targetOutput.IsOpen;
        }
예제 #16
0
        /// <summary>
        /// Function to connect with a LaunchpadDevice
        /// </summary>
        /// <param name="device">The Launchpad to connect to.</param>
        /// <returns>Returns bool if connection was successful.</returns>
        public bool connect(LaunchpadDevice device)
        {
            foreach(InputDevice id in Midi.InputDevice.InstalledDevices)
            {
                if (id.Name.ToLower() == device._midiName.ToLower())
                {
                    targetInput = id;
                    id.Open();
                    targetInput.NoteOn += new InputDevice.NoteOnHandler(midiPress);
                    targetInput.StartReceiving(null);
                }
            }
            foreach (OutputDevice od in Midi.OutputDevice.InstalledDevices)
            {
                if (od.Name.ToLower() == device._midiName.ToLower())
                {
                    targetOutput = od;
                    od.Open();
                }
            }

            return true; // targetInput.IsOpen && targetOutput.IsOpen;
        }
예제 #17
0
 public Bulldog(LaunchpadDevice device)
 {
     mLaunchpadDevice = device;
     mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;
 }
예제 #18
0
        static void Main(string[] args)
        {
            LaunchpadDevice device;

            Console.WriteLine("Launchpad Tests");
            Console.WriteLine("Ted John 2013");
            Console.WriteLine("");

            try {
                device = new LaunchpadDevice();
                device.DoubleBuffered = true;

                Console.WriteLine("Launchpad found");
            } catch {
                Console.WriteLine("No launchpad found");
                Console.ReadLine();
                return;
            }

            Console.WriteLine("");
            Console.WriteLine("0: Grid toggle");
            Console.WriteLine("1: Scrolling message");
            Console.WriteLine("2: Bulldog");
            Console.WriteLine("3: Rain sequencer");
            Console.WriteLine("4: Reversi");
            Console.WriteLine("5: Snake");

            int i;

            while (!Int32.TryParse(Console.ReadLine(), out i))
            {
                Console.WriteLine("Try again...");
            }

            switch (i)
            {
            case 0:
                ToggleGrid toggleGrid = new ToggleGrid(device);
                toggleGrid.Run();
                break;

            case 1:
                Console.Write("Type a message:");
                string message = Console.ReadLine();

                ScrollingLetters scrollingLetters = new ScrollingLetters(device);
                scrollingLetters.Text = message.ToUpper();
                scrollingLetters.ScrollText();
                break;

            case 2:
                Bulldog bulldog = new Bulldog(device);
                bulldog.Play();
                break;

            case 3:
                RainSequencer rain = new RainSequencer(device);
                rain.Run();
                break;

            case 4:
                Reversi reversi = new Reversi(device);
                reversi.Run();
                break;

            case 5:
                Snake snake = new Snake(device);
                snake.Run();
                break;

            default:
                Console.WriteLine("No such application");
                break;
            }
        }
예제 #19
0
 public ScrollingLetters(LaunchpadDevice device)
 {
     mLaunchpadDevice = device;
 }
예제 #20
0
 /// <summary>
 /// Disconnects a given LaunchpadDevice
 /// </summary>
 /// <param name="device">The Launchpad to disconnect.</param>
 /// <returns>Returns bool if disconnection was successful.</returns>
 public bool disconnect(LaunchpadDevice device)
 {
     if (targetInput.IsOpen && targetOutput.IsOpen)
     {
         targetInput.StopReceiving();
         targetInput.Close();
         targetOutput.Close();
     }
     return !targetInput.IsOpen && !targetOutput.IsOpen;
 }
예제 #21
0
 public virtual void Draw(LaunchpadDevice device)
 {
 }
예제 #22
0
 public virtual void Update(LaunchpadDevice device, IEnumerable <LaunchpadEvent> evnts)
 {
 }
예제 #23
0
 internal LaunchpadButton(LaunchpadDevice launchpadDevice, ButtonType type, int index)
 {
     mLaunchpadDevice = launchpadDevice;
     mType            = type;
     mIndex           = index;
 }
 public LaunchpadService()
 {
     Device = new LaunchpadDevice(0);
 }