public UwpMidiAccess(Windows.UI.Core.CoreDispatcher dispatcher) { _midiInDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), dispatcher); _midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), dispatcher); _midiInDeviceWatcher.Start(); _midiOutDeviceWatcher.Start(); }
public SettingsPage() { this.InitializeComponent(); inputDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher); inputDeviceWatcher.StartWatcher(); outputDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher); outputDeviceWatcher.StartWatcher(); //Set the slider back to the values the user put in velocitySlider.Value = (Settings.velocity - 27); volumeSlider.Value = (Settings.volume + 50); if (Settings.feedback == true) { volumeSlider.IsEnabled = true; velocitySlider.IsEnabled = false; } else { Feedback.IsChecked = true; volumeSlider.IsEnabled = false; velocitySlider.IsEnabled = true; } }
// using an Initialize method here instead of the constructor in order to // prevent a race condition between wiring up the event handlers and // finishing enumeration public void Initialize() { ConnectedInputDevices = new List <MidiDeviceInformation>(); ConnectedOutputDevices = new List <MidiDeviceInformation>(); // set up watchers so we know when input devices are added or removed _inputWatcher = DeviceInformation.CreateWatcher(MidiInPort.GetDeviceSelector()); _inputWatcher.EnumerationCompleted += InputWatcher_EnumerationCompleted; _inputWatcher.Updated += InputWatcher_Updated; _inputWatcher.Removed += InputWatcher_Removed; _inputWatcher.Added += InputWatcher_Added; _inputWatcher.Start(); // set up watcher so we know when output devices are added or removed _outputWatcher = DeviceInformation.CreateWatcher(MidiOutPort.GetDeviceSelector()); _outputWatcher.EnumerationCompleted += OutputWatcher_EnumerationCompleted; _outputWatcher.Updated += OutputWatcher_Updated; _outputWatcher.Removed += OutputWatcher_Removed; _outputWatcher.Added += OutputWatcher_Added; _outputWatcher.Start(); }
private async Task LoadInputDevicesAsync() { WriteDebug("Entering LoadInputDevicesAsync"); _devices = new List <MidiDeviceInformation>(); var selector = MidiOutPort.GetDeviceSelector(); WriteDebug("Selector = " + selector); var devices = await DeviceInformation.FindAllAsync(selector); WriteDebug("Devices count = " + devices.Count); foreach (DeviceInformation info in devices) { WriteDebug("Loading device information into collection " + info.Id); var midiDevice = new MidiDeviceInformation(); midiDevice.Id = info.Id; midiDevice.IsDefault = info.IsDefault; midiDevice.IsEnabled = info.IsEnabled; midiDevice.Name = info.Name; _devices.Add(midiDevice); } WriteDebug("Exiting LoadInputDevicesAsync"); }
public MainPage() { this.InitializeComponent(); var appView = ApplicationView.GetForCurrentView(); appView.Title = ""; // Titlebar var coreTitleBar = CoreApplication.GetCurrentView().TitleBar; coreTitleBar.ExtendViewIntoTitleBar = false; CreateKeyboard(); CreateSidebar(); // MIDI inputDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher); inputDeviceWatcher.StartWatcher(); outputDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher); outputDeviceWatcher.StartWatcher(); }
public MidiDeviceWatcher(MidiDeviceType ioType, CoreDispatcher dispatcher) { this.DeviceInformationList = new ObservableCollection <DeviceInformation>(); m_coreDispatcher = dispatcher; switch (ioType) { case MidiDeviceType.Input: { m_deviceSelectorString = MidiInPort.GetDeviceSelector(); break; } case MidiDeviceType.Output: { m_deviceSelectorString = MidiOutPort.GetDeviceSelector(); break; } default: { break; } } m_deviceWatcher = DeviceInformation.CreateWatcher(m_deviceSelectorString); m_deviceWatcher.Added += DeviceWatcher_Added; m_deviceWatcher.Removed += DeviceWatcher_Removed; m_deviceWatcher.Updated += DeviceWatcher_Updated; m_deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted; m_deviceType = ioType; }
/// <summary> /// Returns Device Information for all connected Launchpads /// </summary> /// <returns></returns> public static async Task <IEnumerable <DeviceInformation> > GetLaunchpadDeviceInformation() { // Get all output MIDI devices var outputs = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector()); return(outputs.Where(device => device.Name.ToLower().Contains("launchpad"))); }
public PianoPage() { this.InitializeComponent(); // Setup our device watchers for input and output MIDI devices. // Let's us know if devices are connected/disconnected while we're running // (And hopefully catches these gracefully so that we don't crash!) inputDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortComboBox, Dispatcher); inputDeviceWatcher.StartWatcher(); outputDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortComboBox, Dispatcher); outputDeviceWatcher.StartWatcher(); // Helper class to take care of MIDI Control messages, set it up here with the sliders msgHelper = new ControlMessageHelper(KB, SliderPitch, SliderMod, SliderVolume, SliderPan, Dispatcher); // Register Suspending to clean up any connections we have Application.Current.Suspending += Current_Suspending; // Register event handlers for KeyTapped and KeyReleased // (These events only occur when user taps/clicks on keys on screen) KB.K_KeyTapped += KB_K_KeyTapped; KB.K_KeyReleased += KB_K_KeyReleased; // Wait until page has finished loading before doing some UI/layout changes Loaded += PianoPage_Loaded; }
/// <summary> /// Query DeviceInformation class for Midi Output devices /// </summary> private async Task EnumerateMidiOutputDevices() { // Clear output devices OutputDevices.Clear(); OutputDeviceProperties.Clear(); outputDeviceProperties.IsEnabled = false; // Find all output MIDI devices string midiOutputQueryString = MidiOutPort.GetDeviceSelector(); DeviceInformationCollection midiOutputDevices = await DeviceInformation.FindAllAsync(midiOutputQueryString); // Return if no external devices are connected, and GS synth is not detected if (midiOutputDevices.Count == 0) { OutputDevices.Add("No MIDI output devices found!"); outputDevices.IsEnabled = false; NotifyUser("Please connect at least one external MIDI device for this demo to work correctly"); return; } // List specific device information for each output device foreach (DeviceInformation deviceInfo in midiOutputDevices) { OutputDevices.Add(deviceInfo.Name); outputDevices.IsEnabled = true; } NotifyUser("MIDI Output devices found!"); }
/// <summary> /// Constructor: Empty device lists, start the device watchers and /// set initial states for buttons /// </summary> public MidiDeviceEnumerationTests() { InitializeComponent(); rootGrid.DataContext = this; // Start with a clean slate ClearAllDeviceValues(); // Ensure Auto-detect devices toggle is on deviceAutoDetectToggle.IsOn = true; // Set up the MIDI input and output device watchers _midiInDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), Dispatcher, inputDevices, InputDevices); _midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), Dispatcher, outputDevices, OutputDevices); // Start watching for devices _midiInDeviceWatcher.Start(); _midiOutDeviceWatcher.Start(); // Disable manual enumeration buttons listInputDevicesButton.IsEnabled = false; listOutputDevicesButton.IsEnabled = false; Unloaded += MidiDeviceEnumerationTests_Unloaded; }
/// <summary> /// Method to enumrate all MIDI output devices connected and to setup the the first MIDI output device found. /// </summary> /// <returns></returns> private async Task EnumerateMidiOutputDevices() { // Create the query string for finding all MIDI output devices using MidiOutPort.GetDeviceSelector() string midiOutportQueryString = MidiOutPort.GetDeviceSelector(); // Find all MIDI output devices and collect it in a DeviceInformationCollection using FindAllAsync DeviceInformationCollection midiOutputDevices = await DeviceInformation.FindAllAsync(midiOutportQueryString); // If the size of the midiOutputDevice colloction is xero, // set the StatusTextBlock foreground color to red and the text property to "No MIDI output devices found" // and return. // Else set the StatusTextBlock foreground color to green and the text property to midiOutputdevices[0].Name if (midiOutputDevices.Count == 0) { // Set the StatusTextBlock foreground color to red StatusTextBlock.Foreground = new SolidColorBrush(Colors.Red); // Set the StatusTextBlock text to "No MIDI output devices found" StatusTextBlock.Text = "No MIDI output devices found"; return; } else { // Set the StatusTextBlock foreground color to green StatusTextBlock.Foreground = new SolidColorBrush(Colors.Green); // Set the StatusTextBlock text to the name of the first item in midiOutputDevices collection //StatusTextBlock.Text = midiOutputDevices[0].Name; } // Create an instance of DeviceInformation and set it to the first midi device in DeviceInformationCollection, midiOutputDevices DeviceInformation devInfo = midiOutputDevices[0]; // Return if DeviceInformation, devInfo, is null if (devInfo == null) { // Set the midi status TextBlock StatusTextBlock.Foreground = new SolidColorBrush(Colors.Red); StatusTextBlock.Text = "No device information of MIDI output"; return; } // Set the IMidiOutPort for the output midi device by calling MidiOutPort.FromIdAsync passing the Id property of the DevicInformation midiOutPort = await MidiOutPort.FromIdAsync(devInfo.Id); // Return if midiOutPort is null if (midiOutPort == null) { // Set the midi status TextBlock StatusTextBlock.Foreground = new SolidColorBrush(Colors.Red); StatusTextBlock.Text = "Unable to create MidiOutPort from output device"; return; } // Send the Program Change midi message to port of the output midi device // to set the initial instrument to Acoustic Grand Piano. midiOutPort.SendMessage(instrumentChange); }
public FakeMidiDevice() { int ports = 0; Inputs = DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector()).GetResults(); InputPortInfos = Inputs.Select(i => new WindowsPortInfo(i.Id, MidiPortType.Input, i.Name, ports++)).ToArray(); // freeze for port number Outputs = DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector()).GetResults(); OutputPortInfos = Outputs.Select(i => new WindowsPortInfo(i.Id, MidiPortType.Input, i.Name, ports++)).ToArray(); // freeze for port number }
public void Init(Integra7Random_Xamarin.MainPage mainPage, String deviceName, Picker OutputDeviceSelector, Picker InputDeviceSelector, object Dispatcher, byte MidiOutPortChannel, byte MidiInPortChannel) { this.mainPage = mainPage; midiOutputDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), OutputDeviceSelector, (CoreDispatcher)Dispatcher); midiInputDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), InputDeviceSelector, (CoreDispatcher)Dispatcher); midiOutputDeviceWatcher.StartWatcher(); midiInputDeviceWatcher.StartWatcher(); this.MidiOutPortChannel = MidiOutPortChannel; this.MidiInPortChannel = MidiInPortChannel; Init(deviceName); }
// Constructor using a combobox for full device watch: public MIDI(Integra7Random_Xamarin.MainPage mainPage, MainPage mainPage_UWP, Picker OutputDeviceSelector, Picker InputDeviceSelector, byte MidiOutPortChannel, byte MidiInPortChannel) { this.mainPage = mainPage; this.MainPage_UWP = mainPage_UWP; midiOutputDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), OutputDeviceSelector, mainPage_UWP.Dispatcher_UWP); midiInputDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), InputDeviceSelector, mainPage_UWP.Dispatcher_UWP); midiOutputDeviceWatcher.StartWatcher(); midiInputDeviceWatcher.StartWatcher(); this.MidiOutPortChannel = MidiOutPortChannel; this.MidiInPortChannel = MidiInPortChannel; }
private static DeviceInformationCollection GetDevices() { if (deviceInformationCollection == null) { string midiOutportQueryString = MidiOutPort.GetDeviceSelector(); Task <DeviceInformationCollection> getDeviceInformationTask = DeviceInformation.FindAllAsync(midiOutportQueryString).AsTask(); getDeviceInformationTask.Wait(); deviceInformationCollection = getDeviceInformationTask.Result; } return(deviceInformationCollection); }
public MyMidi(ListBox inBox, ListBox outBox, CoreDispatcher d) { midiInPortListBox = inBox; midiOutPortListBox = outBox; dispatcher = d; inputDeviceWatcher = new MyMidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, dispatcher); inputDeviceWatcher.StartWatcher(); outputDeviceWatcher = new MyMidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, dispatcher); outputDeviceWatcher.StartWatcher(); }
public MidiPage() { this.InitializeComponent(); // Set up the MIDI output device watcher _midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), Dispatcher, OutputDevicesList, OutputDevices); OutputDevicesList.ItemsSource = OutputDevices; // Start watching for devices _midiOutDeviceWatcher.Start(); Unloaded += MidiDeviceOutputTests_Unloaded; }
public MainPage() { InitializeComponent(); Background = new SolidColorBrush(Windows.UI.Colors.LightGray); // Keep up to date with connected MIDI devices deviceInFinder = new MIDIDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher); deviceInFinder.StartWatcher(); deviceOutFinder = new MIDIDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher); deviceOutFinder.StartWatcher(); DrawLayout(); uiDrawClock.Tick += ShowCurChord; uiDrawClock.Interval = new TimeSpan(20); }
public void SetupWatchersAndPorts() { Action enumerationInComplete = new Action(delegate() { Action enumerationOutComplete = new Action(delegate() { SetupMidiPorts(); }); outputDeviceWatcher = new MyMidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), enumerationOutComplete); outputDeviceWatcher.StartWatcher(); }); inputDeviceWatcher = new MyMidiDeviceWatcher(MidiInPort.GetDeviceSelector(), enumerationInComplete); inputDeviceWatcher.StartWatcher(); }
// // // private async Task PopulateMidiOutputDeviceList() { MidiOutputDevicesListBox.Items.Clear(); // midiOutputDevicesCollection = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector()); // foreach (var device in midiInputDevicesCollection) { MidiOutputDevicesListBox.Items.Add(device.Name); } // MidiOutputDevicesListBox.SelectedIndex = 0; }
/// <summary> /// Constructor: Start the device watcher and populate MIDI message types /// </summary> public Scenario3_SendMIDIMessages() { this.InitializeComponent(); // Initialize the list of active MIDI output devices this.midiOutPorts = new List <IMidiOutPort>(); // Set up the MIDI output device watcher this.midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), Dispatcher, this.outputDevices); // Start watching for devices this.midiOutDeviceWatcher.Start(); // Populate message types into list PopulateMessageTypes(); }
/// <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); }
// </SnippetEnumerateMidiOutputDevices> private void startButton_Click(object sender, RoutedEventArgs e) { //EnumerateMidiInputDevices(); //EnumerateMidiOutputDevices(); // <SnippetStartWatchers> inputDeviceWatcher = new MyMidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher); inputDeviceWatcher.StartWatcher(); outputDeviceWatcher = new MyMidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher); outputDeviceWatcher.StartWatcher(); // </SnippetStartWatchers> }
public async Task InitializeAsync(string deviceName) { var devices = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector()).AsTask(); var devInfo = devices?.FirstOrDefault(d => d.Name == deviceName); if (devInfo == null) { throw new Exception($"Device {deviceName} not found."); } currentMidiOutputDevice = await MidiOutPort.FromIdAsync(devInfo.Id).AsTask(); if (currentMidiOutputDevice == null) { throw new Exception($"Midi output port could not be found for device {deviceName}."); } }
public MainPage() { this.InitializeComponent(); inputDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), midiInPortListBox, Dispatcher); inputDeviceWatcher.StartWatcher(); outputDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), midiOutPortListBox, Dispatcher); outputDeviceWatcher.StartWatcher(); byte channel = 0; byte note = 60; byte velocity = 127; IMidiMessage midiMessageToSend = new MidiNoteOnMessage(channel, note, velocity); }
/// <summary> /// Constructor: Start the device watcher and populate MIDI message types /// </summary> public MidiDeviceOutputTests() { InitializeComponent(); rootGrid.DataContext = this; // Initialize the list of active MIDI output devices _midiOutPorts = new List <IMidiOutPort>(); // Set up the MIDI output device watcher _midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), Dispatcher, outputDevices, OutputDevices); // Start watching for devices _midiOutDeviceWatcher.Start(); // Populate message types into list PopulateMessageTypes(); Unloaded += MidiDeviceOutputTests_Unloaded; }
protected override void ProcessRecord() { string selector; switch (DeviceType.ToLower()) { case "inputport": selector = MidiInPort.GetDeviceSelector(); break; case "outputport": selector = MidiOutPort.GetDeviceSelector(); break; } var deviceWatcher = DeviceInformation.CreateWatcher(MidiInPort.GetDeviceSelector()); var midiDeviceWatcher = new MidiDeviceWatcher(deviceWatcher); WriteObject(midiDeviceWatcher); }
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); } }
public MainPage() { this.InitializeComponent(); App.Current.Suspending += Current_Suspending; mArduino = new ArduinoManager(); mGPIO = new GPIOManager(); mGameNoteIndexs = new int[5] { 0, 0, 0, 0, 0 }; mCurrentGameNote = new MidiGameNote[5]; mIsInited = false; mIsPlaying = false; Task.Run(async() => { SMFReader r = new SMFReader(); mSMF = await r.Read(@"Assets\out.mid"); var w = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), Dispatcher); w.Start(); var col = w.GetDeviceInformationCollection(); var l = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector()); MIDIPort = await MidiOutPort.FromIdAsync(l[0].Id); await mArduino.Init(); await mGPIO.Init(GpioController.GetDefault()); mGPIO.MidiButtonChanged += MGPIO_MidiButtonChanged; mGPIO.JoyButtonChanged += MGPIO_JoyButtonChanged; mPlayer = new SMFPlayer(mSMF, MIDIPort); mPlayer.OnLED += Player_OnLED; mPlayer.OnBarBeatChanged += Player_BarBeatChanged; mPlayer.OnTempoChanged += Player_OnTempoChanged; mGPIO.Ack(); mIsInited = true; }); mVolTimer = new DispatcherTimer(); mVolTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); mVolTimer.Tick += MVolTimer_Tick; mVolTimer.Start(); }
/// <summary> /// Constructor: Empty device lists, start the device watchers and /// set initial states for buttons /// </summary> public Scenario1_MIDIDeviceEnumeration() { this.InitializeComponent(); // Start with a clean slate ClearAllDeviceValues(); // Ensure Auto-detect devices toggle is on this.deviceAutoDetectToggle.IsOn = true; // Set up the MIDI input and output device watchers this.midiInDeviceWatcher = new MidiDeviceWatcher(MidiInPort.GetDeviceSelector(), Dispatcher, this.inputDevices); this.midiOutDeviceWatcher = new MidiDeviceWatcher(MidiOutPort.GetDeviceSelector(), Dispatcher, this.outputDevices); // Start watching for devices this.midiInDeviceWatcher.Start(); this.midiOutDeviceWatcher.Start(); // Disable manual enumeration buttons this.listInputDevicesButton.IsEnabled = false; this.listOutputDevicesButton.IsEnabled = false; }