Example #1
0
 void onClosed(object sender, FormClosedEventArgs e)
 {
     mahPort.shutdown();
     pthrough.Join();
     DeregisterOurDevice();
     lock (inLock)
     {
         if (inPort.IsOpen)
         {
             inPort.Stop();
             inPort.Close();
         }
     }
     lock (outLock)
     {
         if (outPort.IsOpen)
         {
             outPort.Close();
         }
     }
     trayIcon.Icon = null;
     trayIcon.Dispose();
     if (config_changed == true)
     {
         config.Save(ConfigurationSaveMode.Full);
     }
 }
Example #2
0
        public void Stop()
        {
            _inPort.Stop();
            _inPort.Close();
            _outPort.Close();

            Debug.WriteLine(_diagnosticsReceiver.ToString());
        }
Example #3
0
 public void Stop()
 {
     _inPort.Stop();
     _inPort.Close();
 }
Example #4
0
 public void Dispose()
 {
     port.Stop();
     port.Close();
 }
        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");
                }
            }
        }