// 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 { } }
protected override void Dispose(DisposeObjectKind disposeKind) { if (disposeKind == DisposeObjectKind.ManagedAndUnmanagedResources) { _inPort.Dispose(); } }
private async Task EnumerateDevices() { var inputDevices = await DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector()); deepMind = null; foreach (DeviceInformation device in inputDevices) { if (device.Name.Contains("DeepMind")) { if (deepMind != null) { deepMind.Dispose(); } deepMind = await MidiInPort.FromIdAsync(device.Id); this.textBlock.Text = "Captured device!"; } } if (deepMind == null) { return; } deepMind.MessageReceived += DeepMind_MessageReceived; }
public async Task CloseAsync() { Connection = MidiPortConnectionState.Pending; await Task.Run(() => { input.Dispose(); Connection = MidiPortConnectionState.Closed; }); }
protected override void OnNavigatedFrom(NavigationEventArgs e) { base.OnNavigatedFrom(e); if (deepMind != null) { deepMind.Dispose(); } }
public void ReleaseMidi() { if (_midiIn != null) { _midiIn.MessageReceived -= OnMidiInMessageReceived; _midiIn.Dispose(); } if (_midiOut != null) { _midiOut.Dispose(); } }
public void ResetMidiInput() { try { if (midiInPort != null) { midiInPort.MessageReceived -= MidiInPort_MessageReceived; midiInPort.Dispose(); midiInPort = 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; }
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 Dispose() { _inPort.Dispose(); _outPort.Dispose(); }
protected override void Dispose(DisposeObjectKind disposeKind) { _inPort.Dispose(); }
public void Close() { port.Dispose(); }
public RecordResult StartRecording(RecordOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } int[] inputIds = options.MidiInputs.SelectMany(GetMidiInputId).Distinct().ToArray(); if (inputIds.Length == 0) { return(new RecordResult($"No MIDI inputs for '{string.Join(", ", options.MidiInputs)}' could be located")); } _logger.LogInformation($"Working dir: {Environment.CurrentDirectory}"); var delayToSave = TimeSpan.FromMilliseconds(options.DelayToSave); _logger.LogInformation($"Delay to save: {delayToSave}"); var pathFormatString = options.PathFormatString; _logger.LogInformation($"Output Path: {pathFormatString}"); var midiResolution = options.MidiResolution; _logger.LogInformation($"MIDI resolution: {midiResolution}"); var receiverFactory = new ObservableReceiverFactory(_logger); var savingPoints = receiverFactory .Throttle(delayToSave) .Select(x => x.AbsoluteTime); _ = receiverFactory .Window(savingPoints) .Select(x => x .Aggregate(ImmutableList <MidiFileEvent> .Empty, (l, i) => l.Add(i))) .ForEachAsync(midiFile => midiFile .ForEachAsync(SaveMidiFile)); var midiIns = new List <MidiInPort>(); foreach (var inputId in inputIds) { var midiIn = new MidiInPort { Successor = receiverFactory.Build(inputId) }; midiIn.Open(inputId); midiIn.Start(); midiIns.Add(midiIn); } return(new RecordResult(() => { foreach (var midiIn in midiIns) { midiIn.Stop(); midiIn.Dispose(); } })); void SaveMidiFile(ImmutableList <MidiFileEvent> eventList) { var context = new MidiFileContext(eventList, DateTime.Now, Guid.NewGuid()); string filePath = context.BuildFilePath(pathFormatString); _logger.LogInformation($"Saving {eventList.Count} events to file {filePath}..."); try { MidiFileSerializer.Serialize(eventList, filePath, midiResolution); } catch (Exception ex) { _logger.LogError(ex, "There was an error when saving the file"); } } }