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(); }
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(); } }
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(); } } }
public GamePlayer(InputDevice input, MidiFile midifile, MidiOptions midiOption) { inputDevice = input; processer = new MidiProcesser(midifile, midiOption); inputDevice.NoteOn += delegate(NoteOnMessage msg) { ComputeScore(msg.Pitch, processer.Position); }; inputDevice.NoteOff += delegate(NoteOffMessage msg) { }; inputDevice.ProgramChange += delegate(ProgramChangeMessage msg) { }; inputDevice.PitchBend += delegate(PitchBendMessage msg) { }; }
public Summarizer(InputDevice inputDevice) { this.inputDevice = inputDevice; pitchesPressed = new Dictionary<Pitch, bool>(); inputDevice.NoteOn += new InputDevice.NoteOnHandler(this.NoteOn); inputDevice.NoteOff += new InputDevice.NoteOffHandler(this.NoteOff); PrintStatus(); }
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 Scaler(Clock clock, InputDevice inputDevice, OutputDevice outputDevice) { this.clock = clock; this.inputDevice = inputDevice; this.outputDevice = outputDevice; this.scaleToUse = 0; if (inputDevice != null) { inputDevice.NoteOn += new InputDevice.NoteOnHandler(this.NoteOn); } }
public Arpeggiator(InputDevice inputDevice, OutputDevice outputDevice, Clock clock) { this.inputDevice = inputDevice; this.outputDevice = outputDevice; this.clock = clock; if (inputDevice != null) { inputDevice.NoteOn += new InputDevice.NoteOnHandler(this.NoteOn); inputDevice.NoteOff += new InputDevice.NoteOffHandler(this.NoteOff); } }
public LearningPlayer(InputDevice input, MidiFile midifile, MidiOptions midiOption) { processer = new MidiProcesser(midifile, midiOption); inputDevice = input; inputDevice.NoteOn += delegate(NoteOnMessage msg) { ProcessPitch(msg.Pitch); }; processer.NoteOn += delegate(Channel channel, Pitch pitch, int velocity) { waitPitch = pitch; processer.Stop(); }; }
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 Arpeggiator(InputDevice inputDevice, OutputDevice outputDevice, Clock clock) { this.inputDevice = inputDevice; this.outputDevice = outputDevice; this.clock = clock; this.currentChordPattern = 0; this.currentScalePattern = 0; this.playingChords = false; this.lastSequenceForPitch = new Dictionary<Pitch, List<Pitch>>(); if (inputDevice != null) { inputDevice.NoteOn += new InputDevice.NoteOnHandler(this.NoteOn); inputDevice.NoteOff += new InputDevice.NoteOffHandler(this.NoteOff); } }
public void DisConnect() { if (_inputDevice != null) { _inputDevice.StopReceiving(); _inputDevice.Close(); _inputDevice.RemoveAllEventHandlers(); _inputDevice = null; } if (_outputDevice != null) { _outputDevice.Close(); _outputDevice = null; } }
public Launchpad(InputDevice inputDevice, OutputDevice outputDevice, Clock clock) { this.inputDevice = inputDevice; this.outputDevice = outputDevice; this.clock = clock; if (this.inputDevice.IsOpen) { this.inputDevice.Close(); } if (this.outputDevice.IsOpen) { this.outputDevice.Close(); } this.inputDevice.Open(); this.inputDevice.NoteOn += new InputDevice.NoteOnHandler(NoteOn); this.inputDevice.StartReceiving(null); this.outputDevice.Open(); this.ShowColours(); DemoSetup(); }
public void NextInput() { try { inputDevice.StopReceiving(); inputDevice.Close(); } catch (NullReferenceException) { } if (++input < InputDevice.InstalledDevices.Count) inputDevice = InputDevice.InstalledDevices[input]; else if (InputDevice.InstalledDevices.Count != 0) inputDevice = InputDevice.InstalledDevices[input = 0]; else { inputDevice = null; return; } inputDevice.Open(); inputDevice.NoteOn += new InputDevice.NoteOnHandler(NoteOn); inputDevice.NoteOff += new InputDevice.NoteOffHandler(NoteOff); inputDevice.StartReceiving(null); Display(); }
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); }
private void SetUpMidiListener() { midiDevice = InputDevice.InstalledDevices.FirstOrDefault(dev => dev.Name == settings.MidiInputDeviceName); if (midiDevice != null) { midiDevice.NoteOn += MidiInputDevice_NoteOn; } }
private void OpenButton_Click(object sender, EventArgs e) { if (InputDevice.InstalledDevices.Count > 0) { if (currentInputDevice != null && currentInputDevice.IsOpen) { currentInputDevice.StopReceiving(); currentInputDevice.NoteOn -= new InputDevice.NoteOnHandler(NoteOn); currentInputDevice.NoteOff -= new InputDevice.NoteOffHandler(NoteOff); currentInputDevice.Close(); } if (comboBox1.SelectedIndex >=0) { label1.Text = ""; currentInputDevice = InputDevice.InstalledDevices[comboBox1.SelectedIndex]; } if (currentInputDevice != null) { currentInputDevice.Open(); label1.Text = "Connected to" +currentInputDevice.Name; currentInputDevice.NoteOn += new InputDevice.NoteOnHandler(NoteOn); currentInputDevice.NoteOff += new InputDevice.NoteOffHandler(NoteOff); currentInputDevice.StartReceiving(null); // Note events will be received in another thread } } }
/// <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"); } }
/// <summary> /// Initialize a MIDI input device and add the noteon event /// </summary> public void InitializeInputDevice() { try { this.inputDevice = null; if (InputDevice.InstalledDevices.Count == 0) { PrintMessage("No input devices..."); return; } else { this.inputDevice = InputDevice.InstalledDevices[0]; } if (this.inputDevice.IsOpen) { this.inputDevice.Close(); } this.inputDevice.Open(); this.inputDevice.StartReceiving(null); this.inputDevice.NoteOn += new InputDevice.NoteOnHandler(this.NoteOn); PrintMessage(this.inputDevice.Name); } catch (DeviceException) { this.removeInputDevice(); PrintMessage("No input devices..."); } }
private void CloseMidiDevice(Midi.InputDevice _InputDevice) { _InputDevice.StopReceiving(); _InputDevice.ControlChange -= NoteCC; _InputDevice.Close(); }
// 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); }
/// <summary> /// Private method for constructing the array of MidiInputDevices by calling the Win32 api. /// </summary> /// <returns></returns> private static InputDevice[] MakeDeviceList() { uint inDevs = Win32API.midiInGetNumDevs(); InputDevice[] result = new InputDevice[inDevs]; for (uint deviceId = 0; deviceId < inDevs; deviceId++) { Win32API.MIDIINCAPS caps = new Win32API.MIDIINCAPS(); Win32API.midiInGetDevCaps((UIntPtr)deviceId, out caps); result[deviceId] = new InputDevice((UIntPtr)deviceId, caps); } return result; }
public void removeInputDevice() { try { if (this.inputDevice != null) { this.inputDevice.StopReceiving(); this.inputDevice.Close(); this.inputDevice.RemoveAllEventHandlers(); } this.inputDevice = null; } catch(DeviceException) {} }