private async void MidiDeviceSelected(object sender, SelectionChangedEventArgs e) { var selectedDevice = (MidiDeviceInfo)OutputDevicesList.SelectedItem; if (selectedDevice != null) { _currentDevice?.Dispose(); _currentDevice = await MidiOutPort.FromIdAsync(selectedDevice.Id); KeyboardKeys.IsEnabled = true; } }
// Called when app is suspending private void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) { // Clean up out watchers inputDeviceWatcher.StopWatcher(); inputDeviceWatcher = null; outputDeviceWatcher.StopWatcher(); outputDeviceWatcher = null; // Remove EventHandlers and try dispose of input & output ports try { midiInPort.MessageReceived -= MidiInPort_MessageReceived; midiInPort.Dispose(); midiInPort = null; } catch { } try { midiOutPort.Dispose(); midiOutPort = null; } catch { } }
public static uint midiOutClose(IntPtr hmo) { if (s_midiOutPort != null) { s_midiOutPort.Dispose(); } s_midiOutPort = null; return(MidiWinApi.MMSYSERR_NOERROR); }
public void ResetMidiOutput() { try { if (midiOutPort != null) { midiOutPort.Dispose(); midiOutPort = null; GC.Collect(); } } catch { } }
public void TeardownWatchers() { inputDeviceWatcher.StopWatcher(); inputDeviceWatcher = null; outputDeviceWatcher.StopWatcher(); outputDeviceWatcher = null; midiInPort.MessageReceived -= MidiInPort_MessageReceived; midiInPort.Dispose(); midiInPort = null; midiOutPort.Dispose(); midiOutPort = null; }
/// <summary> /// Eventhandler to clean up the MIDI connection, when the app is suspended. /// The object midiOutPort is disposed and set to null /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void App_Suspending(object sender, SuspendingEventArgs e) { try { // Dispose the Midi Output port midiOutPort.Dispose(); // Set the midiOutPort to null midiOutPort = null; } catch { // Do noting. A cleanup has already been made } }
private void CleanUp() { // <SnippetCleanUp> inputDeviceWatcher.StopWatcher(); inputDeviceWatcher = null; outputDeviceWatcher.StopWatcher(); outputDeviceWatcher = null; midiInPort.MessageReceived -= MidiInPort_MessageReceived; midiInPort.Dispose(); midiInPort = null; midiOutPort.Dispose(); midiOutPort = null; // </SnippetCleanUp> }
public void Close() { port.Dispose(); }