/// <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 ListView).SelectedIndex; // Try to create a MidiInPort if (selectedInputDeviceIndex < 0) { // Clear input device messages InputDeviceMessages.Clear(); InputDeviceMessages.Add("Select a MIDI input device to be able to see its messages"); inputDeviceMessages.IsEnabled = false; NotifyUser("Select a MIDI input device to be able to see its messages"); return; } DeviceInformationCollection devInfoCollection = _midiInDeviceWatcher.GetDeviceInformationCollection(); if (devInfoCollection == null) { InputDeviceMessages.Clear(); InputDeviceMessages.Add("Device not found!"); inputDeviceMessages.IsEnabled = false; NotifyUser("Device not found!"); return; } DeviceInformation devInfo = devInfoCollection[selectedInputDeviceIndex]; if (devInfo == null) { InputDeviceMessages.Clear(); InputDeviceMessages.Add("Device not found!"); inputDeviceMessages.IsEnabled = false; NotifyUser("Device not found!"); return; } var currentMidiInputDevice = await MidiInPort.FromIdAsync(devInfo.Id); if (currentMidiInputDevice == null) { NotifyUser("Unable to create MidiInPort from input device"); return; } // We have successfully created a MidiInPort; add the device to the list of active devices, and set up message receiving if (!_midiInPorts.Contains(currentMidiInputDevice)) { _midiInPorts.Add(currentMidiInputDevice); currentMidiInputDevice.MessageReceived += MidiInputDevice_MessageReceived; } // Clear any previous input messages InputDeviceMessages.Clear(); inputDeviceMessages.IsEnabled = true; NotifyUser("Input Device selected successfully! Waiting for messages..."); }
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(); }