public LaunchpadDevice(int index) { InitialiseButtons(); int i = 0; mInputDevice = InputDevice.InstalledDevices.Where(x => x.Name.Contains("Launchpad")). FirstOrDefault(x => i++ == index); i = 0; mOutputDevice = OutputDevice.InstalledDevices.Where(x => x.Name.Contains("Launchpad")). FirstOrDefault(x => i++ == index); if (mInputDevice == null) throw new LaunchpadException("Unable to find input device."); if (mOutputDevice == null) throw new LaunchpadException("Unable to find output device."); mInputDevice.Open(); mOutputDevice.Open(); mInputDevice.StartReceiving(new Clock(120)); mInputDevice.NoteOn += mInputDevice_NoteOn; mInputDevice.ControlChange += mInputDevice_ControlChange; Reset(); }
public void Connect() { if (_inputDevice == null) { _inputDevice = (from device in InputDevice.InstalledDevices where device.Name == _deviceName select device).FirstOrDefault(); if (_inputDevice != null) { _inputDevice.Open(); _inputDevice.NoteOn += OnInputDeviceNoteOn; _inputDevice.NoteOff += OnInputDeviceNoteOff; _inputDevice.ControlChange += OnInputDeviewControlChange; _inputDevice.StartReceiving(null); } } if (_outputDevice == null) { _outputDevice = (from device in OutputDevice.InstalledDevices where device.Name == _deviceName select device).FirstOrDefault(); if (_outputDevice != null) { _outputDevice.Open(); _outputDevice.SilenceAllNotes(); } } }
private void MidiActive(object sender, RoutedEventArgs e) { if ((sender as CheckBox).IsChecked ?? false) { if (inputDevices.SelectedIndex == -1) { return; } d = Midi.InputDevice.InstalledDevices[inputDevices.SelectedIndex]; d.NoteOn += D_NoteOn; d.NoteOff += D_NoteOff; d.ProgramChange += D_ProgramChange; d.ControlChange += D_ControlChange; if (!d.IsOpen) { d.Open(); } d.StartReceiving(null); } else { d.StopReceiving(); d.Close(); } }
private void OpenMidiDevice(Midi.InputDevice _InputDevice) { if (!_InputDevice.IsOpen) { _InputDevice.Open(); _InputDevice.ControlChange += new InputDevice.ControlChangeHandler(NoteCC); _InputDevice.StartReceiving(null); // Note events will be received in another thread Console.ReadKey(); // This thread waits for a keypress ... } }
private void Form1_Load(object sender, EventArgs e) { clock.Start(); inputDevice = InputDevice.InstalledDevices[0]; inputDevice.Open(); inputDevice.NoteOn += msg => { noteCollector.ProcessMidiMessage(msg); messages.Add(msg); notesControl1.Invalidate(); }; inputDevice.NoteOff += msg => { noteCollector.ProcessMidiMessage(msg); notesControl1.Invalidate(); }; inputDevice.StartReceiving(clock); }
public Midi.OutputDevice matrixOut; // Yeet Output in private void requestMatrixInfo() { //Setup Midi Console.WriteLine("Looking for Midi input device " + matrix.Name); int i = 0; foreach (Midi.InputDevice inputDevice in Midi.InputDevice.InstalledDevices) { Console.WriteLine(inputDevice.Name); if (inputDevice.Name == matrix.Name) { Console.WriteLine("Midi Input Connected: " + inputDevice.Name); matrixIn = Midi.InputDevice.InstalledDevices[i]; if (!matrixIn.IsOpen) { matrixIn.Open(); matrixIn.SysEx += new Midi.InputDevice.SysExHandler(ReceiveSysEx); matrixIn.StartReceiving(null, true); } break; } i++; } Console.WriteLine("Looking for Midi output device " + matrix.Name); i = 0; foreach (Midi.OutputDevice outputDevice in Midi.OutputDevice.InstalledDevices) { Console.WriteLine(outputDevice.Name); if (outputDevice.Name == matrix.Name) { Console.WriteLine("Midi Output Connected: " + outputDevice.Name); matrixOut = Midi.OutputDevice.InstalledDevices[i]; if (!matrixOut.IsOpen) { matrixOut.Open(); } break; } i++; } matrixOut.SendSysEx(new byte[] { 240, 0, 2, 3, 1, 0, 17, 16, 247 }); //获取设备名字 matrixOut.SendSysEx(new byte[] { 240, 0, 2, 3, 1, 0, 17, 17, 247 }); //获取设备序列号String matrixOut.SendSysEx(new byte[] { 240, 0, 2, 3, 1, 0, 17, 18, 0, 247 }); //获取设备固件String matrixOut.SendSysEx(new byte[] { 240, 0, 2, 3, 1, 0, 17, 18, 1, 247 }); //获取设备固件Bytes }
public MainWindow() { InitializeComponent(); this.DataContext = _text; List <string> ports = SerialPort.GetPortNames().ToList(); ports.Sort(); _serialPort = _serialPort = new SerialPort(ports.Last(), 31250, Parity.None, 8, StopBits.One); _serialPort.Open(); _midiDevice = Midi.InputDevice.InstalledDevices.First(); _midiDevice.Open(); _midiDevice.NoteOn += MidiDeviceOnNoteOn; _midiDevice.NoteOff += MidiDeviceOnNoteOff; _midiDevice.PitchBend += MidiDevicePitchBend; _midiDevice.ControlChange += MidiDeviceControlChange; _midiDevice.StartReceiving(null); }
/// <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; }
private void btnRecieve_Click(object sender, EventArgs e) { if (listBox1.SelectedItem == null) { MessageBox.Show("No device selected!"); return; } inDevice = (InputDevice)listBox1.SelectedItem; try { inDevice.Open(); inDevice.NoteOn += new InputDevice.NoteOnHandler(NoteOn); inDevice.StartReceiving(null); // Note events will be received in another thread btnRecieve.Enabled = false; btnClose.Enabled = true; } catch (Midi.DeviceException) { MessageBox.Show("Device is already openend in another program", "Error"); } }
// Switches input devices, turning off the old one (if any) and turning on the new one. private void UseInputDevice(InputDevice newInputDevice) { if (newInputDevice == inputDevice) { return; } if (inputDevice != null) { if (inputDevice.IsOpen) { if (inputDevice.IsReceiving) { inputDevice.StopReceiving(); } inputDevice.Close(); } inputDevice.NoteOn -= noteOnHandler; inputDevice.NoteOff -= noteOffHandler; } inputDevice = newInputDevice; inputDevice.NoteOn += noteOnHandler; inputDevice.NoteOff += noteOffHandler; inputDevice.Open(); inputDevice.StartReceiving(null); }