private void OnInputDeviceSelected(object sender, SelectedItemChangedEventArgs args) { IMidiPortDetails device = args.SelectedItem as IMidiPortDetails; if (device != null) { _messages.Clear(); var input = _access.OpenInputAsync(device.Id).Result; _messages.Add("Using " + device.Id); input.MessageReceived += (obj, e) => { Device.BeginInvokeOnMainThread(() => { try { _messages.Add($"{e.Timestamp} {e.Start} {e.Length} {e.Data[0].ToString("X")}"); Messages.ScrollTo(_messages.Last(), ScrollToPosition.MakeVisible, true); if (_synthesizer != null) { _synthesizer.Send(e.Data, e.Start, e.Length, e.Timestamp); } } catch (Exception exp) { Debug.WriteLine(exp); } }); }; } }
private void ConfirmButtonPressed(object sender, RoutedEventArgs e) { input = access.OpenInputAsync(LaunchPadInputs.SelectedValue.ToString()).Result; output = access.OpenOutputAsync(LaunchPadOutputs.SelectedValue.ToString()).Result; try { lpmngr = new LaunchPadManager(access, input, output); InitMacroGrid(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "LaunchPad Macros", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
public MidiManager(IMonitor monitor) { this.Monitor = monitor; this.Monitor.Log("Initializing MIDI Framework", LogLevel.Info); midi = MidiAccessManager.Default; var numdevices = midi.Inputs.Count(); if (numdevices <= 0) { this.Monitor.Log("No Devices Found. Please connect MIDI Device to use this mod.", LogLevel.Info); this.Monitor.Log("Any Mods requiring this framework will be disabled.", LogLevel.Info); return; } inDevice = new List <IMidiInput>(); this.Monitor.Log($"Midi Framework Initialized. Found {numdevices} device{ ((numdevices == 0 || numdevices > 1) ? ("s") : ("")) }", LogLevel.Info); for (int i = 0; i < numdevices; i++) { inDevice.Add(midi.OpenInputAsync(midi.Inputs.ElementAt(i).Id).Result); this.Monitor.Log($"Device {i}: {inDevice[i].Details.Name}", LogLevel.Debug); } }
private async Task PollMidiConnection() { //Checking for added devices int numDevices = midi.Inputs.Count(); if (numDevices > inDevice.Count) { foreach (IMidiPortDetails details in midi.Inputs) { IMidiInput input = inDevice.Find(x => x.Details.Name.Equals(details.Name)); if (input == null) { IMidiInput newInput = midi.OpenInputAsync(details.Id).Result; inDevice.Add(newInput); this.Monitor.Log($"{newInput.Details.Name} connected", LogLevel.Info); break; } } } //Checking for removed devices if (numDevices < inDevice.Count) { foreach (IMidiInput input in inDevice) { IMidiPortDetails details = midi.Inputs.ToList().Find(x => x.Id.Equals(input.Details.Id)); if (details == null) { this.Monitor.Log($"{input.Details.Name} disconnected", LogLevel.Info); await input.CloseAsync(); inDevice.Remove(input); break; } } } await Task.Delay(1000 / 60); }
public static IMidiInput MidiInDevice(string name = null) { if (string.IsNullOrEmpty(name)) { name = Midi.MidiInDeviceName; } try { if (!D_midiIn.ContainsKey(name)) { D_midiIn.TryAdd(name, access.OpenInputAsync(access.Inputs.Where(x => x.Name == name).First().Id).Result); D_midiIn[name].MessageReceived += Poubub.HumanInterface.Midi.Event_Received; } return(D_midiIn[name]); } catch (Exception ex) { Debug.WriteLine(ex); ClearMidiDevices(); } return(null); }