Ejemplo n.º 1
0
        // 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
            {
            }
        }
Ejemplo n.º 2
0
 protected override void Dispose(DisposeObjectKind disposeKind)
 {
     if (disposeKind == DisposeObjectKind.ManagedAndUnmanagedResources)
     {
         _inPort.Dispose();
     }
 }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
 public async Task CloseAsync()
 {
     Connection = MidiPortConnectionState.Pending;
     await Task.Run(() => {
         input.Dispose();
         Connection = MidiPortConnectionState.Closed;
     });
 }
Ejemplo n.º 5
0
        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();
            }
        }
Ejemplo n.º 7
0
 public void ResetMidiInput()
 {
     try
     {
         if (midiInPort != null)
         {
             midiInPort.MessageReceived -= MidiInPort_MessageReceived;
             midiInPort.Dispose();
             midiInPort = null;
             GC.Collect();
         }
     }
     catch { }
 }
Ejemplo n.º 8
0
        public void TeardownWatchers()
        {
            inputDeviceWatcher.StopWatcher();
            inputDeviceWatcher = null;

            outputDeviceWatcher.StopWatcher();
            outputDeviceWatcher = null;

            midiInPort.MessageReceived -= MidiInPort_MessageReceived;
            midiInPort.Dispose();
            midiInPort = null;

            midiOutPort.Dispose();
            midiOutPort = null;
        }
Ejemplo n.º 9
0
        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>
        }
Ejemplo n.º 10
0
 public void Dispose()
 {
     _inPort.Dispose();
     _outPort.Dispose();
 }
Ejemplo n.º 11
0
 protected override void Dispose(DisposeObjectKind disposeKind)
 {
     _inPort.Dispose();
 }
Ejemplo n.º 12
0
 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");
                }
            }
        }