private static void Render(Settings settings, AudioLoader loader) { if (settings.OutputFile != null) { // Emit normalized data to a WAV file for later mixing if (settings.MasterAudioFile == null && !settings.NoMasterMix) { settings.MasterAudioFile = settings.OutputFile + ".wav"; loader.MixToFile(settings.MasterAudioFile, !settings.NoMasterMixReplayGain); } } Console.WriteLine("Generating background image..."); var backgroundImage = new BackgroundRenderer(settings.Width, settings.Height, ParseColor(settings.BackgroundColor)); if (settings.BackgroundImageFile != null) { using (var bm = Image.FromFile(settings.BackgroundImageFile)) { backgroundImage.Add(new ImageInfo(bm, ContentAlignment.MiddleCenter, true, DockStyle.None, 0.5f)); } } if (settings.LogoImageFile != null) { using (var bm = Image.FromFile(settings.LogoImageFile)) { backgroundImage.Add(new ImageInfo(bm, ContentAlignment.BottomRight, false, DockStyle.None, 1)); } } if (settings.VgmFile != null) { var gd3 = Gd3Tag.LoadFromVgm(settings.VgmFile); var gd3Text = gd3.ToString(); if (gd3Text.Length > 0) { backgroundImage.Add(new TextInfo(gd3Text, settings.Gd3Font, settings.Gd3FontSize, ContentAlignment.BottomLeft, FontStyle.Regular, DockStyle.Bottom, ParseColor(settings.Gd3FontColor))); } } var renderer = new WaveformRenderer { BackgroundImage = backgroundImage.Image, Columns = settings.Columns, FramesPerSecond = settings.FramesPerSecond, Width = settings.Width, Height = settings.Height, SamplingRate = loader.SampleRate, RenderedLineWidthInSamples = settings.ViewWidthMs * loader.SampleRate / 1000, RenderingBounds = backgroundImage.WaveArea }; if (settings.GridLineWidth > 0) { renderer.Grid = new WaveformRenderer.GridConfig { Color = ParseColor(settings.GridColor), Width = settings.GridLineWidth, DrawBorder = settings.GridBorder }; } if (settings.ZeroLineWidth > 0) { renderer.ZeroLine = new WaveformRenderer.ZeroLineConfig { Color = ParseColor(settings.ZeroLineColor), Width = settings.ZeroLineWidth }; } // Add the data to the renderer foreach (var channel in loader.Data) { renderer.AddChannel(new Channel( channel.Samples, ParseColor(settings.LineColor), settings.LineWidth, GuessChannelName(channel.Filename), CreateTriggerAlgorithm(settings.TriggerAlgorithm), settings.TriggerLookahead)); } if (settings.ChannelLabelsFont != null) { renderer.ChannelLabels = new WaveformRenderer.LabelConfig { Color = ParseColor(settings.ChannelLabelsColor), FontName = settings.ChannelLabelsFont, Size = settings.ChannelLabelsSize }; } var outputs = new List <IGraphicsOutput>(); if (settings.FfMpegPath != null) { Console.WriteLine("Adding FFMPEG renderer..."); outputs.Add(new FfmpegOutput(settings.FfMpegPath, settings.OutputFile, settings.Width, settings.Height, settings.FramesPerSecond, settings.FfMpegExtraOptions, settings.MasterAudioFile)); } if (settings.PreviewFrameskip > 0) { Console.WriteLine("Adding preview renderer..."); outputs.Add(new PreviewOutput(settings.PreviewFrameskip)); } try { Console.WriteLine("Rendering..."); var sw = Stopwatch.StartNew(); renderer.Render(outputs); sw.Stop(); int numFrames = (int)(loader.Length.TotalSeconds * settings.FramesPerSecond); Console.WriteLine($"Rendering complete in {sw.Elapsed:g}, average {numFrames / sw.Elapsed.TotalSeconds:N} fps"); } catch (Exception ex) { // Should mean it was cancelled Console.WriteLine($"Rendering cancelled: {ex.Message}"); } finally { foreach (var graphicsOutput in outputs) { graphicsOutput.Dispose(); } } }
private static void Render(Settings settings, IReadOnlyCollection <Channel> channels) { Console.WriteLine("Generating background image..."); var backgroundImage = new BackgroundRenderer(settings.Width, settings.Height, ParseColor(settings.BackgroundColor)); if (settings.BackgroundImageFile != null) { using (var bm = Image.FromFile(settings.BackgroundImageFile)) { backgroundImage.Add(new ImageInfo(bm, ContentAlignment.MiddleCenter, true, DockStyle.None, 0.5f)); } } if (!string.IsNullOrEmpty(settings.LogoImageFile)) { using (var bm = Image.FromFile(settings.LogoImageFile)) { backgroundImage.Add(new ImageInfo(bm, ContentAlignment.BottomRight, false, DockStyle.None, 1)); } } if (settings.VgmFile != null) { var gd3 = Gd3Tag.LoadFromVgm(settings.VgmFile); var gd3Text = gd3.ToString(); if (gd3Text.Length > 0) { backgroundImage.Add(new TextInfo(gd3Text, settings.Gd3Font, settings.Gd3FontSize, ContentAlignment.BottomLeft, FontStyle.Regular, DockStyle.Bottom, ParseColor(settings.Gd3FontColor))); } } if (settings.MaximumAspectRatio > 0.0) { Console.WriteLine($"Determining column count for maximum aspect ratio {settings.MaximumAspectRatio}:"); for (var columns = 1; columns < 100; ++columns) { var width = backgroundImage.WaveArea.Width / columns; var rows = channels.Count / columns + (channels.Count % columns == 0 ? 0 : 1); var height = backgroundImage.WaveArea.Height / rows; var ratio = (double)width / height; Console.WriteLine($"- {columns} columns => {width} x {height} pixels => ratio {ratio}"); if (ratio < settings.MaximumAspectRatio) { settings.Columns = columns; break; } } } var renderer = new WaveformRenderer { BackgroundImage = backgroundImage.Image, Columns = settings.Columns, FramesPerSecond = settings.FramesPerSecond, Width = settings.Width, Height = settings.Height, SamplingRate = channels.First().SampleRate, RenderingBounds = backgroundImage.WaveArea }; if (settings.GridLineWidth > 0) { foreach (var channel in channels) { channel.BorderColor = ParseColor(settings.GridColor); channel.BorderWidth = settings.GridLineWidth; channel.BorderEdges = settings.GridBorder; } } // Add the data to the renderer foreach (var channel in channels) { renderer.AddChannel(channel); } var outputs = new List <IGraphicsOutput>(); if (settings.FfMpegPath != null) { Console.WriteLine("Adding FFMPEG renderer..."); outputs.Add(new FfmpegOutput(settings.FfMpegPath, settings.OutputFile, settings.Width, settings.Height, settings.FramesPerSecond, settings.FfMpegExtraOptions, settings.MasterAudioFile)); } if (settings.PreviewFrameskip > 0) { Console.WriteLine("Adding preview renderer..."); outputs.Add(new PreviewOutput(settings.PreviewFrameskip, true)); } try { Console.WriteLine("Rendering..."); var sw = Stopwatch.StartNew(); renderer.Render(outputs); sw.Stop(); int numFrames = (int)(channels.Max(x => x.Length).TotalSeconds *settings.FramesPerSecond); Console.WriteLine($"Rendering complete in {sw.Elapsed:g}, average {numFrames / sw.Elapsed.TotalSeconds:N} fps"); } catch (Exception ex) { // Should mean it was cancelled Console.WriteLine($"Rendering cancelled: {ex.Message}"); } finally { foreach (var graphicsOutput in outputs) { graphicsOutput.Dispose(); } } }