public async void InputDeviceChanged(Picker DeviceSelector) { try { if (!String.IsNullOrEmpty((String)DeviceSelector.SelectedItem)) { var midiInDeviceInformationCollection = midiInputDeviceWatcher.DeviceInformationCollection; if (midiInDeviceInformationCollection == null) { return; } DeviceInformation midiInDevInfo = midiInDeviceInformationCollection[DeviceSelector.SelectedIndex]; if (midiInDevInfo == null) { return; } midiInPort = await MidiInPort.FromIdAsync(midiInDevInfo.Id); if (midiInPort == null) { System.Diagnostics.Debug.WriteLine("Unable to create MidiInPort from input device"); return; } midiInPort.MessageReceived += MidiInPort_MessageReceived; } } catch { } }
/// <summary> /// The user selected a new MIDI input device. /// </summary> /// <param name="selectedMidiDeviceIndex">Index of the currently selected MIDI input device as int</param> /// <param name="e">PropertyChangedEventArgs</param> private async void SelectedMidiDeviceChanged(object selectedMidiDeviceIndex, PropertyChangedEventArgs e) { // Check that the current list of devices actually contains any devices. if ((this.availableMidiDevices == null) || (this.availableMidiDevices.Count < 1)) { return; } // Check that the currently selected index actually exists in the current list of devices. if (this.availableMidiDevices[(int)selectedMidiDeviceIndex] == null) { return; } // Get information about the device that was selected. DeviceInformation selectedDeviceInfo = this.availableMidiDevices[(int)selectedMidiDeviceIndex]; // This might fail if the user has selected a device that was disconnected in the mean time. if (selectedDeviceInfo == null) { return; } // Bind the current MIDI input port to the selected device. var midiInPort = await MidiInPort.FromIdAsync(selectedDeviceInfo.Id); // This might fail if the device is not accepted as MIDI input source. if (midiInPort == null) { return; } // Subscribe to receive MIDI messages. midiInPort.MessageReceived += MidiMessageReceived; }
// // // public async Task setMidiInputPortId(Windows.Devices.Enumeration.DeviceInformation Di) { this.midiInputPort = await MidiInPort.FromIdAsync(Di.Id); // this.midiInputPort.MessageReceived += MidiInputDevice_MessageReceived; }
public async Task InitInput(String inputDeviceName) { DeviceInformationCollection midiInputDevices = await DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector()); DeviceInformation midiInDevInfo = null; foreach (DeviceInformation device in midiInputDevices) { if (device.Name.Contains(inputDeviceName) && !device.Name.Contains("CTRL")) { midiInDevInfo = device; break; } } if (midiInDevInfo != null) { midiInPort = await MidiInPort.FromIdAsync(midiInDevInfo.Id); } if (midiInPort == null) { System.Diagnostics.Debug.WriteLine("Unable to create MidiInPort from input device"); } else { midiInPort.MessageReceived += MidiInPort_MessageReceived; } }
private async Task EnumerateDevices() { var inputDevices = await DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector()); deepMind = null; foreach (DeviceInformation device in inputDevices) { if (device.Name.Contains("DeepMind")) { if (deepMind != null) { deepMind.Dispose(); } deepMind = await MidiInPort.FromIdAsync(device.Id); this.textBlock.Text = "Captured device!"; } } if (deepMind == null) { return; } deepMind.MessageReceived += DeepMind_MessageReceived; }
public async Task CreateInput(Device source, Listener acceptor) { if (source is MidiDevice d) { var inPort = await MidiInPort.FromIdAsync(d.info.Id); inPort.MessageReceived += (sender, args) => { switch (args.Message) { case MidiNoteOnMessage on: acceptor.SendMessage(new NoteOnEvent { Note = on.Note, Velocity = on.Velocity }); break; case MidiNoteOffMessage off: acceptor.SendMessage(new NoteOffEvent { Note = off.Note, Velocity = off.Velocity }); break; } }; } else { throw new ArgumentException("Was given unlisted device"); } }
protected override async Task ProcessRecordAsync() { if (!string.IsNullOrWhiteSpace(Id)) { var port = await MidiInPort.FromIdAsync(Id); if (port != null) { WriteDebug("Acquired input port: " + port.DeviceId); } else { throw new ArgumentException("No input port available with that Id. You can get the Id through the MidiDeviceInformation returned from Get-Midi[Input|Output]DeviceInformation.", "Id"); } // we need to wrap this because PowerShell doesn't understand WinRT/UWP events var inputPort = new MidiInputPort(port); WriteObject(inputPort); } else { throw new ArgumentException("Parameter required. You can get the Id through the MidiDeviceInformation returned from Get-Midi[In|Out]DeviceInformation.", "Id"); } }
private async void midiInPortListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var deviceInformationCollection = inputDeviceWatcher.DeviceInformationCollection; if (deviceInformationCollection == null) { return; } DeviceInformation devInfo = deviceInformationCollection[midiInPortListBox.SelectedIndex]; if (devInfo == null) { return; } midiInPort = await MidiInPort.FromIdAsync(devInfo.Id); if (midiInPort == null) { System.Diagnostics.Debug.WriteLine("Unable to create MidiInPort from input device"); return; } midiInPort.MessageReceived += MidiInPort_MessageReceived; }
/// <summary> /// Change the input MIDI device from which to receive messages /// </summary> /// <param name="sender">Element that fired the event</param> /// <param name="e">Event arguments</param> private async void inputDevices_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Get the selected input MIDI device int selectedInputDeviceIndex = (sender as ListBox).SelectedIndex; // Try to create a MidiInPort if (selectedInputDeviceIndex < 0) { // Clear input device messages this.inputDeviceMessages.Items.Clear(); this.inputDeviceMessages.Items.Add("Select a MIDI input device to be able to see its messages"); this.inputDeviceMessages.IsEnabled = false; this.rootPage.NotifyUser("Select a MIDI input device to be able to see its messages", NotifyType.StatusMessage); return; } DeviceInformationCollection devInfoCollection = this.midiInDeviceWatcher.GetDeviceInformationCollection(); if (devInfoCollection == null) { this.inputDeviceMessages.Items.Clear(); this.inputDeviceMessages.Items.Add("Device not found!"); this.inputDeviceMessages.IsEnabled = false; this.rootPage.NotifyUser("Device not found!", NotifyType.ErrorMessage); return; } DeviceInformation devInfo = devInfoCollection[selectedInputDeviceIndex]; if (devInfo == null) { this.inputDeviceMessages.Items.Clear(); this.inputDeviceMessages.Items.Add("Device not found!"); this.inputDeviceMessages.IsEnabled = false; this.rootPage.NotifyUser("Device not found!", NotifyType.ErrorMessage); return; } var currentMidiInputDevice = await MidiInPort.FromIdAsync(devInfo.Id); if (currentMidiInputDevice == null) { this.rootPage.NotifyUser("Unable to create MidiInPort from input device", NotifyType.ErrorMessage); return; } // We have successfully created a MidiInPort; add the device to the list of active devices, and set up message receiving if (!this.midiInPorts.Contains(currentMidiInputDevice)) { this.midiInPorts.Add(currentMidiInputDevice); currentMidiInputDevice.MessageReceived += MidiInputDevice_MessageReceived; } // Clear any previous input messages this.inputDeviceMessages.Items.Clear(); this.inputDeviceMessages.IsEnabled = true; this.rootPage.NotifyUser("Input Device selected successfully! Waiting for messages...", NotifyType.StatusMessage); }
public async Task <IMidiInputPort> OpenInput(int portNumber) { var port = InputPortInfos.First(p => p.PortNumber == portNumber); var result = MidiInPort.FromIdAsync(port.Id); await result; return(new WindowsMidiInputPort(result.GetResults())); }
public async Task <IMidiInput> OpenInputAsync(string portId) { var inputs = await GetInputsAsync(); var details = inputs.Cast <UwpMidiPortDetails> ().FirstOrDefault(d => d.Id == portId); var input = MidiInPort.FromIdAsync(portId).GetResults(); return(new UwpMidiInput(input, details)); }
public Task <IMidiInput> OpenInputAsync(string portId) { return(Task <IMidiInput> .Run(async() => { var inputs = Inputs; var details = inputs.Cast <UwpMidiPortDetails>().FirstOrDefault(d => d.Id.Equals(portId)); var input = await MidiInPort.FromIdAsync(portId); return (IMidiInput) new UwpMidiInput(input, details); })); }
/// <summary> /// Passes a MIDI input port to the MIDIListener /// </summary> /// <param name="portID">the port that is passed</param> /// <returns>task</returns> private async Task SetListener(string portID) { MidiInPort listening = await MidiInPort.FromIdAsync(portID); if (listening == null) { Debug.WriteLine("Unable to create MIDI-in port."); return; } listener = new MIDIListener(listening); uiDrawClock.Start(); }
public async void InitializeMidi(string midiInToPCDeviceId, string midiOutToLaunchpadDeviceId) { // acquire the MIDI ports // TODO: Exception handling _midiIn = await MidiInPort.FromIdAsync(midiInToPCDeviceId); _midiIn.MessageReceived += OnMidiInMessageReceived; _midiOut = (MidiOutPort)await MidiOutPort.FromIdAsync(midiOutToLaunchpadDeviceId); SetPadMappingMode(PadMappingMode.XY); }
static async Task Main(string[] args) { Console.WriteLine("Reading Devices and subscribing to events..."); string deviceSelector = MidiInPort.GetDeviceSelector(); var midiInputDevices = await DeviceInformation.FindAllAsync(deviceSelector); var device = midiInputDevices.FirstOrDefault(); Console.WriteLine($"Reading from device {device.Name}"); var port = await MidiInPort.FromIdAsync(device.Id); port.MessageReceived += MidiDeviceService_MessageReceived; Console.ReadKey(); }
/// <summary> /// Gets a launchpad object for a connected device /// </summary> /// <param name="id">The id of the launchpad</param> /// <returns></returns> public static async Task <Launchpad> Launchpad(string id) { List <DeviceInformation> inputs = (await DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector())).ToList(); List <DeviceInformation> outputs = (await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector())).ToList(); // Find the launchpad input foreach (var inputDeviceInfo in inputs) { try { if (inputDeviceInfo.Id.Contains(id)) { // Find the launchpad output foreach (var outputDeviceInfo in outputs) { // If not a match continue if (!outputDeviceInfo.Id.Contains(id)) { continue; } var inPort = await MidiInPort.FromIdAsync(inputDeviceInfo.Id); var outPort = await MidiOutPort.FromIdAsync(outputDeviceInfo.Id); // Return an MK2 if detected if (outputDeviceInfo.Name.ToLower().Contains("mk2")) { return(new LaunchpadMk2(outputDeviceInfo.Name, inPort, outPort)); } return(null); // Otherwise return Standard //return new LaunchpadS(outputDeviceInfo.Name, inPort, outPort); } } } catch (Exception ex) { Debug.WriteLine(ex); } } // Return null if no devices matched the device name provided return(null); }
private async void DefaultMidiDevices() { string midiOutputQueryString = MidiOutPort.GetDeviceSelector(); string midiInputQueryString = MidiInPort.GetDeviceSelector(); // Find all MIDI output and input devices and collect it DeviceInformationCollection midiOutDevices = await DeviceInformation.FindAllAsync(midiOutputQueryString); DeviceInformationCollection midiInDevices = await DeviceInformation.FindAllAsync(midiInputQueryString); // Set the MIDI device from the found MIDI devices if (midiInDevices.Count > 0) { Settings.midiInPort = await MidiInPort.FromIdAsync(midiInDevices[0].Id); } if (midiOutDevices.Count > 0) { Settings.midiOutPort = await MidiOutPort.FromIdAsync(midiOutDevices[0].Id); } }
internal static void _StartListening(string id) { async Task StartListening() { var inPort = await MidiInPort.FromIdAsync(id); if (inPort == null) { return; } inPort.MessageReceived += MessageReceived; } if (id == null || watchedDevices.Contains(id)) { return; } Task.Run(async() => await StartListening()).Wait(); watchedDevices.Add(id); }
// Handler for SelectionChanged on MIDI Input ListBox private async void MidiInPortComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var deviceInformationCollection = inputDeviceWatcher.DeviceInformationCollection; // If we have selected a device, disable Sliders & Buttons if (midiInPortComboBox.SelectedIndex > -1) { UpdateUserInputs(false); } else { UpdateUserInputs(true); return; } if (deviceInformationCollection == null) { return; } DeviceInformation devInfo = deviceInformationCollection[midiInPortComboBox.SelectedIndex]; if (devInfo == null) { return; } midiInPort = await MidiInPort.FromIdAsync(devInfo.Id); if (midiInPort == null) { System.Diagnostics.Debug.WriteLine("Unable to create MidiInPort from input device"); return; } // Attach a handler to take care of any MIDI messages received from input midiInPort.MessageReceived += MidiInPort_MessageReceived; }
private async Task EnumerateMidiInputDevices() { // Find all input MIDI devices string midiInputQueryString = MidiInPort.GetDeviceSelector(); DeviceInformationCollection midiInputDevices = await DeviceInformation.FindAllAsync(midiInputQueryString); DeviceInformation firstMidiDevice = midiInputDevices.FirstOrDefault(); if (firstMidiDevice == null) { return; } var midiInPort = await MidiInPort.FromIdAsync(firstMidiDevice.Id); if (midiInPort == null) { System.Diagnostics.Debug.WriteLine("Unable to create MidiInPort from input device"); return; } //todo move me midiInPort.MessageReceived += MidiInPort_MessageReceived; }
private static async Task EnumerateMidiInputDevices() { // Find all input MIDI devices string midiInputQueryString = MidiInPort.GetDeviceSelector(); DeviceInformationCollection midiInputDevices = await DeviceInformation.FindAllAsync(midiInputQueryString); // Return if no external devices are connected if (midiInputDevices.Count == 0) { Console.WriteLine("No devices"); return; } // Else, add each connected input device to the list foreach (DeviceInformation deviceInfo in midiInputDevices) { MidiInPort x = await MidiInPort.FromIdAsync(deviceInfo.Id); x.MessageReceived += MessageHandler; Console.WriteLine("Got device " + deviceInfo.Name); } }
public async void SetupMidiPorts() { var inDeviceInformationCollection = inputDeviceWatcher.DeviceInformationCollection; var outDeviceInformationCollection = outputDeviceWatcher.DeviceInformationCollection; if (inDeviceInformationCollection == null || outDeviceInformationCollection == null) { Console.WriteLine("Could not find any MIDI devices."); SetupComplete = true; return; } DeviceInformation inDevInfo = null; string midiControllerName = "X-TOUCH MINI"; foreach (var info in inDeviceInformationCollection) { if (info.Name.Contains(midiControllerName)) { inDevInfo = info; } } DeviceInformation outDevInfo = null; foreach (var info in outDeviceInformationCollection) { if (info.Name.Contains(midiControllerName)) { outDevInfo = info; } } if (inDevInfo == null || outDevInfo == null) { Console.WriteLine("Could not find a MIDI device with name: " + midiControllerName); SetupComplete = true; return; } midiInPort = await MidiInPort.FromIdAsync(inDevInfo.Id); if (midiInPort == null) { Console.WriteLine("Unable to create MidiInPort from input device " + inDevInfo.Name); SetupComplete = true; return; } midiInPort.MessageReceived += MidiInPort_MessageReceived; midiOutPort = await MidiOutPort.FromIdAsync(outDevInfo.Id); if (midiOutPort == null) { Console.WriteLine("Unable to create MidiOutPort from output device " + outDevInfo.Name); SetupComplete = true; return; } Console.WriteLine("Sucessfully found MIDI device with name: " + inDevInfo.Name); // Sending these MIDI messages to reset the knobs on this thread sometimes causes // a cyclic redundacny check error. Solution might be to simply call this reset sometime later... // Maybe from the main thread after setup is complete? // Or maybe this only happens the first time after resuming from sleep? Maybe because I'm not // cleaning up resources properly? for (byte controller = 0; controller < 18; controller++) { ResetKnob(controller); } SetupComplete = true; }
private async void midiInPortListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { m.midiInPort = await MidiInPort.FromIdAsync(m.inputDeviceWatcher.DeviceInformationCollection[midiInPortListBox.SelectedIndex].Id); m.midiInPort.MessageReceived += MidiInPort_MessageReceived; }
/// <summary> /// sets the input device to receive midi messages from /// </summary> /// <param name="devInfo">device to use</param> public async void connectToInputDevice(MidiDeviceInformation devInfo) { midiIn = await MidiInPort.FromIdAsync(devInfo.Id); midiIn.MessageReceived += MidiInputDevice_MessageReceived; }