Server/Spectrum/LineSpectrum.cs
changeset 274 920fea7a6427
parent 273 e5f85a895a62
child 275 a4a341accc89
     1.1 --- a/Server/Spectrum/LineSpectrum.cs	Mon Jan 02 18:43:45 2017 +0100
     1.2 +++ b/Server/Spectrum/LineSpectrum.cs	Wed Jan 04 18:43:28 2017 +0100
     1.3 @@ -13,10 +13,11 @@
     1.4          private double _barSpacing;
     1.5          private double _barWidth;
     1.6          private Size _currentSize;
     1.7 -
     1.8 +        
     1.9 +        
    1.10          public LineSpectrum(FftSize fftSize)
    1.11          {
    1.12 -            FftSize = fftSize;
    1.13 +            FftSize = fftSize;            
    1.14          }
    1.15  
    1.16          [Browsable(false)]
    1.17 @@ -67,38 +68,54 @@
    1.18              }
    1.19          }
    1.20  
    1.21 +        /// <summary>
    1.22 +        /// Update our math.
    1.23 +        /// </summary>
    1.24 +        /// <returns></returns>
    1.25 +        public bool Update()
    1.26 +        {
    1.27 +            return SpectrumProvider.GetFftData(iFftBuffer, this);
    1.28 +        }
    1.29 +
    1.30          public Bitmap CreateSpectrumLine(Size size, Brush brush, Color background, bool highQuality)
    1.31          {
    1.32              if (!UpdateFrequencyMappingIfNessesary(size))
    1.33 +            {
    1.34                  return null;
    1.35 +            }
    1.36  
    1.37 -            var fftBuffer = new float[(int)FftSize];
    1.38 +            //get the fft result from the spectrum provider            
    1.39 +            using (var pen = new Pen(brush, (float)_barWidth))
    1.40 +            {
    1.41 +                var bitmap = new Bitmap(size.Width, size.Height);
    1.42  
    1.43 -            //get the fft result from the spectrum provider
    1.44 -            if (SpectrumProvider.GetFftData(fftBuffer, this))
    1.45 -            {
    1.46 -                using (var pen = new Pen(brush, (float)_barWidth))
    1.47 +                using (Graphics graphics = Graphics.FromImage(bitmap))
    1.48                  {
    1.49 -                    var bitmap = new Bitmap(size.Width, size.Height);
    1.50 +                    PrepareGraphics(graphics, highQuality);
    1.51 +                    graphics.Clear(background);
    1.52  
    1.53 -                    using (Graphics graphics = Graphics.FromImage(bitmap))
    1.54 -                    {
    1.55 -                        PrepareGraphics(graphics, highQuality);
    1.56 -                        graphics.Clear(background);
    1.57 +                    CreateSpectrumLineInternal(graphics, pen, iFftBuffer, size);
    1.58 +                }
    1.59  
    1.60 -                        CreateSpectrumLineInternal(graphics, pen, fftBuffer, size);
    1.61 -                    }
    1.62 -
    1.63 -                    return bitmap;
    1.64 -                }
    1.65 -            }
    1.66 -            return null;
    1.67 +            return bitmap;   
    1.68 +            }            
    1.69          }
    1.70  
    1.71 -        public Bitmap CreateSpectrumLine(Size size, Color color1, Color color2, Color background, bool highQuality)
    1.72 +        /// <summary>
    1.73 +        /// 
    1.74 +        /// </summary>
    1.75 +        /// <param name="size"></param>
    1.76 +        /// <param name="color1"></param>
    1.77 +        /// <param name="color2"></param>
    1.78 +        /// <param name="background"></param>
    1.79 +        /// <param name="highQuality"></param>
    1.80 +        /// <returns></returns>
    1.81 +        public Bitmap Render(Size size, Color color1, Color color2, Color background, bool highQuality)
    1.82          {
    1.83              if (!UpdateFrequencyMappingIfNessesary(size))
    1.84 +            {
    1.85                  return null;
    1.86 +            }
    1.87  
    1.88              using (
    1.89                  Brush brush = new LinearGradientBrush(new RectangleF(0, 0, (float)_barWidth, size.Height), color2,