示例#1
0
        /// <summary>
        /// Create a new MidiOutPort for the selected device
        /// </summary>
        /// <param name="sender">Element that fired the event</param>
        /// <param name="e">Event arguments</param>
        private async void outputDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Get the selected output MIDI device
            int selectedOutputDeviceIndex = outputDevices.SelectedIndex;

            messageType.IsEnabled   = false;
            JingleBells.IsEnabled   = false;
            HappyBirthday.IsEnabled = false;
            resetButton.IsEnabled   = false;

            // Try to create a MidiOutPort
            if (selectedOutputDeviceIndex < 0)
            {
                NotifyUser("Select a MIDI output device to be able to send messages to it");
                return;
            }

            DeviceInformationCollection devInfoCollection = _midiOutDeviceWatcher.GetDeviceInformationCollection();

            if (devInfoCollection == null)
            {
                NotifyUser("Device not found!");
                return;
            }

            DeviceInformation devInfo = devInfoCollection[selectedOutputDeviceIndex];

            if (devInfo == null)
            {
                NotifyUser("Device not found!");
                return;
            }

            _currentMidiOutputDevice = await MidiOutPort.FromIdAsync(devInfo.Id);

            if (_currentMidiOutputDevice == null)
            {
                NotifyUser("Unable to create MidiOutPort from output device");
                return;
            }

            // We have successfully created a MidiOutPort; add the device to the list of active devices
            if (!_midiOutPorts.Contains(_currentMidiOutputDevice))
            {
                _midiOutPorts.Add(_currentMidiOutputDevice);
            }

            // Enable message type list & reset button
            messageType.IsEnabled   = true;
            JingleBells.IsEnabled   = true;
            HappyBirthday.IsEnabled = true;
            resetButton.IsEnabled   = true;

            NotifyUser("Output Device selected successfully! Waiting for message type selection...");
        }
        /// <summary>
        /// Change the active output MIDI device
        /// </summary>
        /// <param name="sender">Element that fired the event</param>
        /// <param name="e">Event arguments</param>
        private void outputDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Get the selected output MIDI device
            int selectedOutputDeviceIndex = outputDevices.SelectedIndex;

            // Try to display the appropriate device properties
            if (selectedOutputDeviceIndex < 0)
            {
                // Clear output device properties
                OutputDeviceProperties.Clear();
                OutputDeviceProperties.Add("Select a MIDI output device to view its properties");
                outputDeviceProperties.IsEnabled = false;
                NotifyUser("Select a MIDI output device to view its properties");
                return;
            }

            DeviceInformationCollection devInfoCollection = _midiOutDeviceWatcher.GetDeviceInformationCollection();

            if (devInfoCollection == null)
            {
                OutputDeviceProperties.Clear();
                OutputDeviceProperties.Add("Device not found!");
                outputDeviceProperties.IsEnabled = false;
                NotifyUser("Device not found!");
                return;
            }

            DeviceInformation devInfo = devInfoCollection[selectedOutputDeviceIndex];

            if (devInfo == null)
            {
                OutputDeviceProperties.Clear();
                OutputDeviceProperties.Add("Device not found!");
                outputDeviceProperties.IsEnabled = false;
                NotifyUser("Device not found!");
                return;
            }

            // Display the found properties
            DisplayDeviceProperties(devInfo, outputDeviceProperties, OutputDeviceProperties);
            NotifyUser("Device information found!");
        }