private void CustomVisualizer_Draw(IVisualizer sender, VisualizerDrawEventArgs args) { if (!MainPageViewModel.Current.IsVisualizing) { return; } var drawingSession = (CanvasDrawingSession)args.DrawingSession; float barWidth = canvasWidth / (2 * Consts.SpectrumBarCount); // Calculate spectum metrics var barSize = new Vector2(barWidth, canvasHeight - 2 * barWidth); // Get the data if data exists and source is in play state, else use empty var spectrumData = args.Data != null && Visualizer.Source?.PlaybackState == SourcePlaybackState.Playing ? args.Data.Spectrum.LogarithmicTransform(Consts.SpectrumBarCount, 20f, 20000f) : _emptySpectrum; _previousSpectrum = spectrumData.ApplyRiseAndFall(_previousSpectrum, _rmsRiseTime, _rmsFallTime, _frameDuration); _previousPeakSpectrum = spectrumData.ApplyRiseAndFall(_previousPeakSpectrum, _peakRiseTime, _peakFallTime, _frameDuration); var logSpectrum = _previousSpectrum.ConvertToDecibels(-50, 0); var logPeakSpectrum = _previousPeakSpectrum.ConvertToDecibels(-50, 0); var step = canvasWidth / Consts.SpectrumBarCount; var flaw = (step - barSize.X) / 2; using (var brush = new CanvasLinearGradientBrush(drawingSession, new CanvasGradientStop[] { new CanvasGradientStop() { Color = Context.CurrentColor[0], Position = 0f }, new CanvasGradientStop() { Color = Context.CurrentColor[1], Position = 1f } }) { StartPoint = new Vector2(canvasWidth, 0), EndPoint = new Vector2(0, canvasHeight) }) { // Draw spectrum bars for (int index = 0; index < Consts.SpectrumBarCount; index++) { float barX = step * index + flaw; // use average of 2 channel float spectrumBarHeight = barSize.Y * (1.0f - (logSpectrum[0][index] + logSpectrum[1][index]) / -100.0f); drawingSession.FillRoundedRectangle(barX, canvasHeight - barWidth - spectrumBarHeight, barSize.X, spectrumBarHeight, barSize.X / 2, barSize.X / 2, brush); } } // Spectrum points to draw a slow decay line for (int index = 0; index < Consts.SpectrumBarCount; index++) { float X = (index + 0.5f) * step; float spectrumBarHeight = barSize.Y * (1.0f - (logPeakSpectrum[0][index] + logPeakSpectrum[1][index]) / -100.0f); var decayPoint = new Vector2(X, canvasHeight - barWidth - spectrumBarHeight); drawingSession.FillCircle(decayPoint, barSize.X / 2, Context.CurrentColor[0]); } }
private void PositionDisplay_Draw(IVisualizer sender, VisualizerDrawEventArgs args) { if (args.PresentationTime != null) { string timeString = args.PresentationTime.Value.ToString("mm\\:ss\\.ff"); var ds = (CanvasDrawingSession)args.DrawingSession; ds.DrawText(timeString, 0, 0, Colors.Gray); } }
private void CustomVisualizer_Draw(IVisualizer sender, VisualizerDrawEventArgs args) { if (!MainPageViewModel.Current.IsVisualizing || Context.Palette == null) { return; } lock (drawingLock) { var drawingSession = (CanvasDrawingSession)args.DrawingSession; float barWidth = canvasWidth / barCount; // Calculate spectum metrics var barSize = new Vector2(barWidth, canvasHeight - 2 * barWidth); // Get the data if data exists and source is in play state, else use empty var spectrumData = args.Data != null && Visualizer.Source?.PlaybackState == SourcePlaybackState.Playing ? args.Data.Spectrum.LogarithmicTransform(barCount, 20f, 20000f) : _emptySpectrum; _previousSpectrum = spectrumData.ApplyRiseAndFall(_previousSpectrum, _rmsRiseTime, _rmsFallTime, _frameDuration); _previousPeakSpectrum = spectrumData.ApplyRiseAndFall(_previousPeakSpectrum, _peakRiseTime, _peakFallTime, _frameDuration); var logSpectrum = _previousSpectrum.ConvertToDecibels(-50, 0); var logPeakSpectrum = _previousPeakSpectrum.ConvertToDecibels(-50, 0); var step = canvasWidth / barCount; var flaw = (step - barSize.X) / 2; // Draw spectrum bars for (int index = 0, j = 0; index < barCount; index++, j++) { float barX = step * index + flaw; // use average of 2 channel and add a offset to pretty float spectrumBarHeight = barSize.Y * (1.0f - (logSpectrum[0][index] + logSpectrum[1][index]) / -100.0f) + barSize.X; if (j >= Context.Palette.Count) { j = 0; } drawingSession.FillRoundedRectangle(barX, 0, barSize.X, spectrumBarHeight, barSize.X / 2, barSize.X / 2, Context.Palette[j]); drawingSession.FillRectangle(barX, 0, barSize.X, spectrumBarHeight - barSize.X / 2, Context.Palette[j]); } } }
private void Visualizer_Draw(object sender, VisualizerDrawEventArgs args) { }