Published v1.4.2
authorStephaneLenclud
Thu, 05 Jan 2017 14:54:43 +0100
changeset 275a4a341accc89
parent 274 920fea7a6427
child 276 7cd495550d5f
Published v1.4.2
Fixing issues with Audio Visualizer bitmaps created when form is not visible.
Now reusing Audio Visualizer bitmap for better performance and memory usage.
Server/FormMain.cs
Server/SharpDisplayManager.csproj
Server/Spectrum/LineSpectrum.cs
     1.1 --- a/Server/FormMain.cs	Wed Jan 04 18:43:28 2017 +0100
     1.2 +++ b/Server/FormMain.cs	Thu Jan 05 14:54:43 2017 +0100
     1.3 @@ -93,6 +93,7 @@
     1.4          DateTime LastTickTime;
     1.5          Display iDisplay;
     1.6          System.Drawing.Bitmap iBmp;
     1.7 +        //TODO: Align that with what we did from Audio Visualizers bitmaps?
     1.8          bool iCreateBitmap; //Workaround render to bitmap issues when minimized
     1.9          ServiceHost iServiceHost;
    1.10          // Our collection of clients sorted by session id.
    1.11 @@ -729,8 +730,7 @@
    1.12          /// </summary>
    1.13          private void UpdateAudioVisualization()
    1.14          {
    1.15 -            // For demo draft purposes just fetch the firt picture box control and update it with current audio spectrum
    1.16 -
    1.17 +            // No point if we don't have a current client
    1.18              if (iCurrentClientData == null)
    1.19              {
    1.20                  return;
    1.21 @@ -755,14 +755,9 @@
    1.22                      if (ctrl is PictureBox)
    1.23                      {
    1.24                          PictureBox pb = (PictureBox)ctrl;
    1.25 -                        Image image = pb.Image;
    1.26 -                        // TODO: recycle images
    1.27 -                        var newImage = iLineSpectrum.Render(pb.Size, Color.Black, Color.Black, Color.White, false);
    1.28 -                        if (newImage != null)
    1.29 +                        if (iLineSpectrum.Render(pb.Image, Color.Black, Color.Black, Color.White, false))
    1.30                          {
    1.31 -                            pb.Image = newImage;
    1.32 -                            if (image != null)
    1.33 -                                image.Dispose();
    1.34 +                            pb.Invalidate();
    1.35                          }
    1.36                      }
    1.37                  }
    1.38 @@ -1197,6 +1192,8 @@
    1.39                  }
    1.40              }
    1.41  
    1.42 +            UpdateAudioVisualization();
    1.43 +
    1.44              //Update our display
    1.45              if (iDisplay.IsOpen())
    1.46              {
    1.47 @@ -1238,9 +1235,7 @@
    1.48  
    1.49                      iDisplay.SwapBuffers();
    1.50                  }
    1.51 -            }
    1.52 -
    1.53 -            UpdateAudioVisualization();
    1.54 +            }            
    1.55  
    1.56              //Compute instant FPS
    1.57              toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " +
    1.58 @@ -2429,6 +2424,19 @@
    1.59                  picture.Location = new System.Drawing.Point(1, 1);
    1.60                  picture.Margin = new System.Windows.Forms.Padding(0);
    1.61                  picture.Name = "pictureBox" + aField;
    1.62 +                picture.SizeChanged += (sender, e) =>
    1.63 +                {
    1.64 +                    // Somehow bitmap created when our from is invisible are not working
    1.65 +                    // Mark our form visibility status
    1.66 +                    bool visible = Visible;
    1.67 +                    // Make sure it's visible
    1.68 +                    Visible = true;
    1.69 +                    // Adjust our bitmap size when control size changes
    1.70 +                    picture.Image = new System.Drawing.Bitmap(picture.Width, picture.Height, PixelFormat.Format32bppArgb);
    1.71 +                    // Restore our form visibility
    1.72 +                    Visible = visible;
    1.73 +                };
    1.74 +                
    1.75                  control = picture;
    1.76              }
    1.77  
     2.1 --- a/Server/SharpDisplayManager.csproj	Wed Jan 04 18:43:28 2017 +0100
     2.2 +++ b/Server/SharpDisplayManager.csproj	Thu Jan 05 14:54:43 2017 +0100
     2.3 @@ -34,7 +34,7 @@
     2.4      <WebPage>index.htm</WebPage>
     2.5      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     2.6      <ApplicationRevision>0</ApplicationRevision>
     2.7 -    <ApplicationVersion>1.3.5.0</ApplicationVersion>
     2.8 +    <ApplicationVersion>1.4.2.0</ApplicationVersion>
     2.9      <UseApplicationTrust>false</UseApplicationTrust>
    2.10      <CreateDesktopShortcut>true</CreateDesktopShortcut>
    2.11      <PublishWizardCompleted>true</PublishWizardCompleted>
     3.1 --- a/Server/Spectrum/LineSpectrum.cs	Wed Jan 04 18:43:28 2017 +0100
     3.2 +++ b/Server/Spectrum/LineSpectrum.cs	Thu Jan 05 14:54:43 2017 +0100
     3.3 @@ -77,28 +77,21 @@
     3.4              return SpectrumProvider.GetFftData(iFftBuffer, this);
     3.5          }
     3.6  
     3.7 -        public Bitmap CreateSpectrumLine(Size size, Brush brush, Color background, bool highQuality)
     3.8 +        private bool CreateSpectrumLine(Image aImage, Brush brush, Color background, bool highQuality)
     3.9          {
    3.10 -            if (!UpdateFrequencyMappingIfNessesary(size))
    3.11 -            {
    3.12 -                return null;
    3.13 -            }
    3.14 -
    3.15              //get the fft result from the spectrum provider            
    3.16              using (var pen = new Pen(brush, (float)_barWidth))
    3.17              {
    3.18 -                var bitmap = new Bitmap(size.Width, size.Height);
    3.19 -
    3.20 -                using (Graphics graphics = Graphics.FromImage(bitmap))
    3.21 +                using (Graphics graphics = Graphics.FromImage(aImage))
    3.22                  {
    3.23                      PrepareGraphics(graphics, highQuality);
    3.24                      graphics.Clear(background);
    3.25  
    3.26 -                    CreateSpectrumLineInternal(graphics, pen, iFftBuffer, size);
    3.27 +                    CreateSpectrumLineInternal(graphics, pen, iFftBuffer, aImage.Size);
    3.28                  }
    3.29 +            }
    3.30  
    3.31 -            return bitmap;   
    3.32 -            }            
    3.33 +            return true;         
    3.34          }
    3.35  
    3.36          /// <summary>
    3.37 @@ -110,21 +103,26 @@
    3.38          /// <param name="background"></param>
    3.39          /// <param name="highQuality"></param>
    3.40          /// <returns></returns>
    3.41 -        public Bitmap Render(Size size, Color color1, Color color2, Color background, bool highQuality)
    3.42 +        public bool Render(Image aImage, Color color1, Color color2, Color background, bool highQuality)
    3.43          {
    3.44 -            if (!UpdateFrequencyMappingIfNessesary(size))
    3.45 +            if (!UpdateFrequencyMappingIfNessesary(aImage.Size))
    3.46              {
    3.47 -                return null;
    3.48 +                return false;
    3.49              }
    3.50  
    3.51 -            using (
    3.52 -                Brush brush = new LinearGradientBrush(new RectangleF(0, 0, (float)_barWidth, size.Height), color2,
    3.53 -                    color1, LinearGradientMode.Vertical))
    3.54 +            using (Brush brush = new LinearGradientBrush(new RectangleF(0, 0, (float)_barWidth, aImage.Size.Height), color2, color1, LinearGradientMode.Vertical))
    3.55              {
    3.56 -                return CreateSpectrumLine(size, brush, background, highQuality);
    3.57 +                return CreateSpectrumLine(aImage, brush, background, highQuality);
    3.58              }
    3.59          }
    3.60  
    3.61 +        /// <summary>
    3.62 +        /// 
    3.63 +        /// </summary>
    3.64 +        /// <param name="graphics"></param>
    3.65 +        /// <param name="pen"></param>
    3.66 +        /// <param name="fftBuffer"></param>
    3.67 +        /// <param name="size"></param>
    3.68          private void CreateSpectrumLineInternal(Graphics graphics, Pen pen, float[] fftBuffer, Size size)
    3.69          {
    3.70              int height = size.Height;