Beispiel #1
0
        public IEnumerable <string> Dump(Song song, Action <double> onProgress)
        {
            var args = new StringBuilder($"\"{song.Filename}\" {song.Index}");

            AddArgIfSupported(args, "sampling_rate", _samplingRate);
            AddArgIfSupported(args, "fade_length", _fadeMs);
            AddArgIfSupported(args, "loop_count", _loopCount);
            AddArgIfSupported(args, "gap_length", _gapMs);
            if (song.ForceLength > TimeSpan.Zero)
            {
                AddArgIfSupported(args, "play_length", (long)song.ForceLength.TotalMilliseconds);
            }

            _processWrapper = new ProcessWrapper(
                _multiDumperPath,
                args.ToString());
            var progressParts = Enumerable.Repeat(0.0, song.Channels.Count).ToList();
            var r             = new Regex(@"(?<channel>\d+)\|(?<position>\d+)\|(?<total>\d+)");
            var stopwatch     = Stopwatch.StartNew();

            foreach (var match in _processWrapper.Lines().Select(l => r.Match(l)).Where(m => m.Success))
            {
                var channel = Convert.ToInt32(match.Groups["channel"].Value);
                if (channel < 0 || channel > song.Channels.Count)
                {
                    continue;
                }

                var position = Convert.ToDouble(match.Groups["position"].Value);
                var total    = Convert.ToDouble(match.Groups["total"].Value);
                progressParts[channel] = position / total;
                if (stopwatch.Elapsed.TotalMilliseconds > 100)
                {
                    // Update the progress every 100ms
                    onProgress?.Invoke(progressParts.Average());
                    stopwatch.Restart();
                }
            }
            _processWrapper.Dispose();
            _processWrapper = null;

            onProgress?.Invoke(1.0);

            var baseName = Path.Combine(
                Path.GetDirectoryName(song.Filename) ?? "",
                Path.GetFileNameWithoutExtension(song.Filename));

            return(song.Channels.Select(channel => $"{baseName} - {channel}.wav"));
        }
Beispiel #2
0
        public IEnumerable <string> Dump(Song song, Action <double> onProgress)
        {
            _processWrapper = new ProcessWrapper(
                _multiDumperPath,
                $"\"{song.Filename}\" {song.Index}");
            var progressParts = Enumerable.Repeat(0.0, song.Channels.Count).ToList();
            var r             = new Regex(@"(?<channel>\d+)\|(?<position>\d+)\|(?<total>\d+)");
            var stopwatch     = Stopwatch.StartNew();

            foreach (var match in _processWrapper.Lines().Select(l => r.Match(l)).Where(m => m.Success))
            {
                var channel = Convert.ToInt32(match.Groups["channel"].Value);
                if (channel < 0 || channel > song.Channels.Count)
                {
                    continue;
                }

                var position = Convert.ToDouble(match.Groups["position"].Value);
                var total    = Convert.ToDouble(match.Groups["total"].Value);
                progressParts[channel] = position / total;
                if (stopwatch.Elapsed.TotalMilliseconds > 100)
                {
                    // Update the progress every 100ms
                    onProgress?.Invoke(progressParts.Average());
                    stopwatch.Restart();
                }
            }
            _processWrapper.Dispose();
            _processWrapper = null;

            onProgress?.Invoke(1.0);

            var baseName = Path.Combine(
                Path.GetDirectoryName(song.Filename),
                Path.GetFileNameWithoutExtension(song.Filename));

            return(song.Channels.Select(channel => $"{baseName} - {channel}.wav"));
        }
Beispiel #3
0
 public void Dispose()
 {
     _processWrapper?.Dispose();
 }