Proper basic support for Audio Visualizer.
authorStephaneLenclud
Wed, 04 Jan 2017 18:43:28 +0100
changeset 274920fea7a6427
parent 273 e5f85a895a62
child 275 a4a341accc89
Proper basic support for Audio Visualizer.
Clients/Idle/SharpDisplayClientIdle.csproj
Clients/Idle/packages.config
Clients/Message/SharpDisplayClientMessage.csproj
Clients/Message/packages.config
Clients/Test/FormClientTest.Designer.cs
Clients/Test/FormClientTest.cs
Clients/Test/SharpDisplayClientTest.csproj
Clients/Test/packages.config
Server/FormMain.cs
Server/SharpDisplayManager.csproj
Server/Spectrum/LineSpectrum.cs
Server/Spectrum/SpectrumBase.cs
Server/packages.config
     1.1 --- a/Clients/Idle/SharpDisplayClientIdle.csproj	Mon Jan 02 18:43:45 2017 +0100
     1.2 +++ b/Clients/Idle/SharpDisplayClientIdle.csproj	Wed Jan 04 18:43:28 2017 +0100
     1.3 @@ -66,8 +66,8 @@
     1.4      <Prefer32Bit>true</Prefer32Bit>
     1.5    </PropertyGroup>
     1.6    <ItemGroup>
     1.7 -    <Reference Include="SharpLibDisplay, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
     1.8 -      <HintPath>..\..\packages\SharpLibDisplay.0.2.6\lib\net40\SharpLibDisplay.dll</HintPath>
     1.9 +    <Reference Include="SharpLibDisplay, Version=0.2.8.30538, Culture=neutral, processorArchitecture=MSIL">
    1.10 +      <HintPath>..\..\packages\SharpLibDisplay.0.2.8\lib\net40\SharpLibDisplay.dll</HintPath>
    1.11        <Private>True</Private>
    1.12      </Reference>
    1.13      <Reference Include="System" />
     2.1 --- a/Clients/Idle/packages.config	Mon Jan 02 18:43:45 2017 +0100
     2.2 +++ b/Clients/Idle/packages.config	Wed Jan 04 18:43:28 2017 +0100
     2.3 @@ -1,4 +1,4 @@
     2.4  <?xml version="1.0" encoding="utf-8"?>
     2.5  <packages>
     2.6 -  <package id="SharpLibDisplay" version="0.2.6" targetFramework="net46" />
     2.7 +  <package id="SharpLibDisplay" version="0.2.8" targetFramework="net46" />
     2.8  </packages>
     2.9 \ No newline at end of file
     3.1 --- a/Clients/Message/SharpDisplayClientMessage.csproj	Mon Jan 02 18:43:45 2017 +0100
     3.2 +++ b/Clients/Message/SharpDisplayClientMessage.csproj	Wed Jan 04 18:43:28 2017 +0100
     3.3 @@ -65,8 +65,8 @@
     3.4      <Prefer32Bit>true</Prefer32Bit>
     3.5    </PropertyGroup>
     3.6    <ItemGroup>
     3.7 -    <Reference Include="SharpLibDisplay, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
     3.8 -      <HintPath>..\..\packages\SharpLibDisplay.0.2.6\lib\net40\SharpLibDisplay.dll</HintPath>
     3.9 +    <Reference Include="SharpLibDisplay, Version=0.2.8.30538, Culture=neutral, processorArchitecture=MSIL">
    3.10 +      <HintPath>..\..\packages\SharpLibDisplay.0.2.8\lib\net40\SharpLibDisplay.dll</HintPath>
    3.11        <Private>True</Private>
    3.12      </Reference>
    3.13      <Reference Include="System" />
     4.1 --- a/Clients/Message/packages.config	Mon Jan 02 18:43:45 2017 +0100
     4.2 +++ b/Clients/Message/packages.config	Wed Jan 04 18:43:28 2017 +0100
     4.3 @@ -1,4 +1,4 @@
     4.4  <?xml version="1.0" encoding="utf-8"?>
     4.5  <packages>
     4.6 -  <package id="SharpLibDisplay" version="0.2.6" targetFramework="net452" />
     4.7 +  <package id="SharpLibDisplay" version="0.2.8" targetFramework="net452" />
     4.8  </packages>
     4.9 \ No newline at end of file
     5.1 --- a/Clients/Test/FormClientTest.Designer.cs	Mon Jan 02 18:43:45 2017 +0100
     5.2 +++ b/Clients/Test/FormClientTest.Designer.cs	Wed Jan 04 18:43:28 2017 +0100
     5.3 @@ -46,6 +46,8 @@
     5.4              this.buttonTriggerEvents = new System.Windows.Forms.Button();
     5.5              this.textBoxEventName = new System.Windows.Forms.TextBox();
     5.6              this.label1 = new System.Windows.Forms.Label();
     5.7 +            this.buttonLayoutAudioVisualizer = new System.Windows.Forms.Button();
     5.8 +            this.buttonLayoutMultipleAudioVisualizers = new System.Windows.Forms.Button();
     5.9              ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPriority)).BeginInit();
    5.10              this.SuspendLayout();
    5.11              // 
    5.12 @@ -207,7 +209,7 @@
    5.13              // 
    5.14              // buttonTriggerEvents
    5.15              // 
    5.16 -            this.buttonTriggerEvents.Location = new System.Drawing.Point(11, 257);
    5.17 +            this.buttonTriggerEvents.Location = new System.Drawing.Point(8, 317);
    5.18              this.buttonTriggerEvents.Name = "buttonTriggerEvents";
    5.19              this.buttonTriggerEvents.Size = new System.Drawing.Size(75, 23);
    5.20              this.buttonTriggerEvents.TabIndex = 33;
    5.21 @@ -217,7 +219,7 @@
    5.22              // 
    5.23              // textBoxEventName
    5.24              // 
    5.25 -            this.textBoxEventName.Location = new System.Drawing.Point(11, 231);
    5.26 +            this.textBoxEventName.Location = new System.Drawing.Point(8, 291);
    5.27              this.textBoxEventName.Name = "textBoxEventName";
    5.28              this.textBoxEventName.Size = new System.Drawing.Size(202, 20);
    5.29              this.textBoxEventName.TabIndex = 34;
    5.30 @@ -225,17 +227,39 @@
    5.31              // label1
    5.32              // 
    5.33              this.label1.AutoSize = true;
    5.34 -            this.label1.Location = new System.Drawing.Point(11, 212);
    5.35 +            this.label1.Location = new System.Drawing.Point(8, 272);
    5.36              this.label1.Name = "label1";
    5.37              this.label1.Size = new System.Drawing.Size(67, 13);
    5.38              this.label1.TabIndex = 35;
    5.39              this.label1.Text = "Event name:";
    5.40              // 
    5.41 +            // buttonLayoutAudioVisualizer
    5.42 +            // 
    5.43 +            this.buttonLayoutAudioVisualizer.Location = new System.Drawing.Point(11, 207);
    5.44 +            this.buttonLayoutAudioVisualizer.Name = "buttonLayoutAudioVisualizer";
    5.45 +            this.buttonLayoutAudioVisualizer.Size = new System.Drawing.Size(94, 35);
    5.46 +            this.buttonLayoutAudioVisualizer.TabIndex = 36;
    5.47 +            this.buttonLayoutAudioVisualizer.Text = "Audio Visualizer Layout";
    5.48 +            this.buttonLayoutAudioVisualizer.UseVisualStyleBackColor = true;
    5.49 +            this.buttonLayoutAudioVisualizer.Click += new System.EventHandler(this.buttonLayoutAudioVisualizer_Click);
    5.50 +            // 
    5.51 +            // buttonLayoutMultipleAudioVisualizers
    5.52 +            // 
    5.53 +            this.buttonLayoutMultipleAudioVisualizers.Location = new System.Drawing.Point(111, 207);
    5.54 +            this.buttonLayoutMultipleAudioVisualizers.Name = "buttonLayoutMultipleAudioVisualizers";
    5.55 +            this.buttonLayoutMultipleAudioVisualizers.Size = new System.Drawing.Size(94, 35);
    5.56 +            this.buttonLayoutMultipleAudioVisualizers.TabIndex = 37;
    5.57 +            this.buttonLayoutMultipleAudioVisualizers.Text = "Multiple Audio Visualizers Layout";
    5.58 +            this.buttonLayoutMultipleAudioVisualizers.UseVisualStyleBackColor = true;
    5.59 +            this.buttonLayoutMultipleAudioVisualizers.Click += new System.EventHandler(this.buttonLayoutMultipleAudioVisualizers_Click);
    5.60 +            // 
    5.61              // FormClientTest
    5.62              // 
    5.63              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    5.64              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    5.65 -            this.ClientSize = new System.Drawing.Size(499, 292);
    5.66 +            this.ClientSize = new System.Drawing.Size(564, 351);
    5.67 +            this.Controls.Add(this.buttonLayoutMultipleAudioVisualizers);
    5.68 +            this.Controls.Add(this.buttonLayoutAudioVisualizer);
    5.69              this.Controls.Add(this.label1);
    5.70              this.Controls.Add(this.textBoxEventName);
    5.71              this.Controls.Add(this.buttonTriggerEvents);
    5.72 @@ -284,6 +308,8 @@
    5.73          private System.Windows.Forms.Button buttonTriggerEvents;
    5.74          private System.Windows.Forms.TextBox textBoxEventName;
    5.75          private System.Windows.Forms.Label label1;
    5.76 +        private System.Windows.Forms.Button buttonLayoutAudioVisualizer;
    5.77 +        private System.Windows.Forms.Button buttonLayoutMultipleAudioVisualizers;
    5.78      }
    5.79  }
    5.80  
     6.1 --- a/Clients/Test/FormClientTest.cs	Mon Jan 02 18:43:45 2017 +0100
     6.2 +++ b/Clients/Test/FormClientTest.cs	Wed Jan 04 18:43:28 2017 +0100
     6.3 @@ -405,5 +405,69 @@
     6.4          {
     6.5              iClient.TriggerEventsByName(textBoxEventName.Text);
     6.6          }
     6.7 +
     6.8 +        private void buttonLayoutAudioVisualizer_Click(object sender, EventArgs e)
     6.9 +        {
    6.10 +            SetLayoutAudioVisualizer();
    6.11 +        }
    6.12 +
    6.13 +        /// <summary>
    6.14 +        /// Define a layout with a single full screen visualizer.
    6.15 +        /// </summary>
    6.16 +        private void SetLayoutAudioVisualizer()
    6.17 +        {
    6.18 +            //Define layout dimension column by row (x,y)
    6.19 +            TableLayout layout = new TableLayout(1, 1);
    6.20 +            //First column take 100%
    6.21 +            layout.Columns[0].Width = 100F;
    6.22 +            //Send layout to server
    6.23 +            iClient.SetLayout(layout);
    6.24 +
    6.25 +            //Create our full screen audio visualizer field 
    6.26 +            AudioVisualizerField field = new AudioVisualizerField();
    6.27 +
    6.28 +            //Set fields
    6.29 +            iClient.CreateFields(new DataField[]
    6.30 +            {
    6.31 +                field,
    6.32 +            });
    6.33 +
    6.34 +        }
    6.35 +
    6.36 +        private void buttonLayoutMultipleAudioVisualizers_Click(object sender, EventArgs e)
    6.37 +        {
    6.38 +            SetLayoutMultipleAudioVisualizers();
    6.39 +        }
    6.40 +
    6.41 +        /// <summary>
    6.42 +        /// Define a layout with a single full screen visualizer.
    6.43 +        /// </summary>
    6.44 +        private void SetLayoutMultipleAudioVisualizers()
    6.45 +        {
    6.46 +            //Define layout dimension column by row (x,y)
    6.47 +            TableLayout layout = new TableLayout(2, 2);
    6.48 +            //First column take 100%
    6.49 +            layout.Columns[0].Width = 25F;
    6.50 +            layout.Columns[1].Width = 75F;
    6.51 +            //Send layout to server
    6.52 +            iClient.SetLayout(layout);
    6.53 +
    6.54 +            //Create our full screen audio visualizer field 
    6.55 +            AudioVisualizerField field1 = new AudioVisualizerField(0, 0);
    6.56 +            AudioVisualizerField field2 = new AudioVisualizerField(0, 1);
    6.57 +            AudioVisualizerField field3 = new AudioVisualizerField(1, 0);
    6.58 +            AudioVisualizerField field4 = new AudioVisualizerField(1, 1);
    6.59 +
    6.60 +            //Set fields
    6.61 +            iClient.CreateFields(new DataField[]
    6.62 +            {
    6.63 +                field1,
    6.64 +                field2,
    6.65 +                field3,
    6.66 +                field4,
    6.67 +            });
    6.68 +
    6.69 +        }
    6.70 +
    6.71      }
    6.72  }
     7.1 --- a/Clients/Test/SharpDisplayClientTest.csproj	Mon Jan 02 18:43:45 2017 +0100
     7.2 +++ b/Clients/Test/SharpDisplayClientTest.csproj	Wed Jan 04 18:43:28 2017 +0100
     7.3 @@ -84,8 +84,8 @@
     7.4      <NoWin32Manifest>true</NoWin32Manifest>
     7.5    </PropertyGroup>
     7.6    <ItemGroup>
     7.7 -    <Reference Include="SharpLibDisplay, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
     7.8 -      <HintPath>..\..\packages\SharpLibDisplay.0.2.6\lib\net40\SharpLibDisplay.dll</HintPath>
     7.9 +    <Reference Include="SharpLibDisplay, Version=0.2.8.30538, Culture=neutral, processorArchitecture=MSIL">
    7.10 +      <HintPath>..\..\packages\SharpLibDisplay.0.2.8\lib\net40\SharpLibDisplay.dll</HintPath>
    7.11        <Private>True</Private>
    7.12      </Reference>
    7.13      <Reference Include="System" />
     8.1 --- a/Clients/Test/packages.config	Mon Jan 02 18:43:45 2017 +0100
     8.2 +++ b/Clients/Test/packages.config	Wed Jan 04 18:43:28 2017 +0100
     8.3 @@ -1,4 +1,4 @@
     8.4  <?xml version="1.0" encoding="utf-8"?>
     8.5  <packages>
     8.6 -  <package id="SharpLibDisplay" version="0.2.6" targetFramework="net46" />
     8.7 +  <package id="SharpLibDisplay" version="0.2.8" targetFramework="net46" />
     8.8  </packages>
     8.9 \ No newline at end of file
     9.1 --- a/Server/FormMain.cs	Mon Jan 02 18:43:45 2017 +0100
     9.2 +++ b/Server/FormMain.cs	Wed Jan 04 18:43:28 2017 +0100
     9.3 @@ -674,11 +674,11 @@
     9.4              iLineSpectrum = new LineSpectrum(fftSize)
     9.5              {
     9.6                  SpectrumProvider = spectrumProvider,
     9.7 -                UseAverage = true,
     9.8 -                BarCount = 32,
     9.9 -                BarSpacing = 0,
    9.10 +                UseAverage = false,
    9.11 +                BarCount = 16,
    9.12 +                BarSpacing = 1,
    9.13                  IsXLogScale = true,
    9.14 -                ScalingStrategy = ScalingStrategy.Sqrt
    9.15 +                ScalingStrategy = ScalingStrategy.Decibel
    9.16              };
    9.17  
    9.18  
    9.19 @@ -727,24 +727,44 @@
    9.20          /// <summary>
    9.21          /// 
    9.22          /// </summary>
    9.23 -        private void GenerateAudioVisualization()
    9.24 +        private void UpdateAudioVisualization()
    9.25          {
    9.26              // For demo draft purposes just fetch the firt picture box control and update it with current audio spectrum
    9.27 -            foreach (Control ctrl in iTableLayoutPanel.Controls)
    9.28 +
    9.29 +            if (iCurrentClientData == null)
    9.30              {
    9.31 -                if (ctrl is PictureBox)
    9.32 +                return;
    9.33 +            }
    9.34 +
    9.35 +            // Update our math
    9.36 +            if (!iLineSpectrum.Update())
    9.37 +            {
    9.38 +                //Nothing changed no need to render
    9.39 +                return;
    9.40 +            }
    9.41 +
    9.42 +            // Check if our current client has an Audio Visualizer field
    9.43 +            // and render them as needed
    9.44 +            foreach (DataField f in iCurrentClientData.Fields)
    9.45 +            {
    9.46 +                if (f is AudioVisualizerField)
    9.47                  {
    9.48 -                    PictureBox pb = (PictureBox)ctrl;
    9.49 -                    Image image = pb.Image;
    9.50 -                    var newImage = iLineSpectrum.CreateSpectrumLine(pb.Size, Color.Black, Color.Black, Color.White, false);
    9.51 -                    if (newImage != null)
    9.52 +                    AudioVisualizerField avf = (AudioVisualizerField)f;
    9.53 +                    Control ctrl = iTableLayoutPanel.GetControlFromPosition(avf.Column, avf.Row);
    9.54 +
    9.55 +                    if (ctrl is PictureBox)
    9.56                      {
    9.57 -                        pb.Image = newImage;
    9.58 -                        if (image != null)
    9.59 -                            image.Dispose();
    9.60 +                        PictureBox pb = (PictureBox)ctrl;
    9.61 +                        Image image = pb.Image;
    9.62 +                        // TODO: recycle images
    9.63 +                        var newImage = iLineSpectrum.Render(pb.Size, Color.Black, Color.Black, Color.White, false);
    9.64 +                        if (newImage != null)
    9.65 +                        {
    9.66 +                            pb.Image = newImage;
    9.67 +                            if (image != null)
    9.68 +                                image.Dispose();
    9.69 +                        }
    9.70                      }
    9.71 -
    9.72 -                    break;
    9.73                  }
    9.74              }
    9.75          }
    9.76 @@ -1220,10 +1240,10 @@
    9.77                  }
    9.78              }
    9.79  
    9.80 -            GenerateAudioVisualization();
    9.81 +            UpdateAudioVisualization();
    9.82  
    9.83              //Compute instant FPS
    9.84 -      toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " +
    9.85 +            toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " +
    9.86                                             (1000/iTimerDisplay.Interval).ToString() + " FPS";
    9.87  
    9.88              LastTickTime = NewTickTime;
    9.89 @@ -1948,21 +1968,25 @@
    9.90                      Control ctrl = iTableLayoutPanel.GetControlFromPosition(tableField.Column, tableField.Row);
    9.91                      if (aField.IsTextField && ctrl is MarqueeLabel)
    9.92                      {
    9.93 -                        TextField textField = (TextField) aField;
    9.94 +                        TextField textField = (TextField)aField;
    9.95                          //Text field control already in place, just change the text
    9.96 -                        MarqueeLabel label = (MarqueeLabel) ctrl;
    9.97 +                        MarqueeLabel label = (MarqueeLabel)ctrl;
    9.98                          contentChanged = (label.Text != textField.Text || label.TextAlign != textField.Alignment);
    9.99                          label.Text = textField.Text;
   9.100                          label.TextAlign = textField.Alignment;
   9.101                      }
   9.102                      else if (aField.IsBitmapField && ctrl is PictureBox)
   9.103                      {
   9.104 -                        BitmapField bitmapField = (BitmapField) aField;
   9.105 +                        BitmapField bitmapField = (BitmapField)aField;
   9.106                          contentChanged = true; //TODO: Bitmap comp or should we leave that to clients?
   9.107                          //Bitmap field control already in place just change the bitmap
   9.108 -                        PictureBox pictureBox = (PictureBox) ctrl;
   9.109 +                        PictureBox pictureBox = (PictureBox)ctrl;
   9.110                          pictureBox.Image = bitmapField.Bitmap;
   9.111                      }
   9.112 +                    else if (aField is AudioVisualizerField && ctrl is PictureBox)
   9.113 +                    {
   9.114 +                        contentChanged = false; // Since nothing was changed
   9.115 +                    }
   9.116                      else
   9.117                      {
   9.118                          layoutChanged = true;
   9.119 @@ -2234,6 +2258,10 @@
   9.120                          {
   9.121                              textsRoot.Nodes.Add(new TreeNode("[Bitmap]"));
   9.122                          }
   9.123 +                        else if (field is AudioVisualizerField)
   9.124 +                        {
   9.125 +                            textsRoot.Nodes.Add(new TreeNode("[Audio Visualizer]"));
   9.126 +                        }
   9.127                          else if (field.IsRecordingField)
   9.128                          {
   9.129                              RecordingField recordingField = (RecordingField) field;
   9.130 @@ -2368,7 +2396,7 @@
   9.131                  //control.TabIndex = 2;
   9.132                  label.Font = cds.Font;
   9.133  
   9.134 -                TextField field = (TextField) aField;
   9.135 +                TextField field = (TextField)aField;
   9.136                  label.TextAlign = field.Alignment;
   9.137                  label.UseCompatibleTextRendering = true;
   9.138                  label.Text = field.Text;
   9.139 @@ -2386,11 +2414,24 @@
   9.140                  picture.Margin = new System.Windows.Forms.Padding(0);
   9.141                  picture.Name = "pictureBox" + aField;
   9.142                  //Set our image
   9.143 -                BitmapField field = (BitmapField) aField;
   9.144 +                BitmapField field = (BitmapField)aField;
   9.145                  picture.Image = field.Bitmap;
   9.146                  //
   9.147                  control = picture;
   9.148              }
   9.149 +            else if (aField is AudioVisualizerField)
   9.150 +            {
   9.151 +                //Create picture box
   9.152 +                PictureBox picture = new PictureBox();
   9.153 +                picture.AutoSize = true;
   9.154 +                picture.BackColor = System.Drawing.Color.Transparent;
   9.155 +                picture.Dock = System.Windows.Forms.DockStyle.Fill;
   9.156 +                picture.Location = new System.Drawing.Point(1, 1);
   9.157 +                picture.Margin = new System.Windows.Forms.Padding(0);
   9.158 +                picture.Name = "pictureBox" + aField;
   9.159 +                control = picture;
   9.160 +            }
   9.161 +
   9.162              //TODO: Handle recording field?
   9.163  
   9.164              return control;
    10.1 --- a/Server/SharpDisplayManager.csproj	Mon Jan 02 18:43:45 2017 +0100
    10.2 +++ b/Server/SharpDisplayManager.csproj	Wed Jan 04 18:43:28 2017 +0100
    10.3 @@ -128,8 +128,8 @@
    10.4        <HintPath>..\packages\LibMiniDisplay.1.1.8\lib\net20\MiniDisplayInterop.dll</HintPath>
    10.5        <Private>True</Private>
    10.6      </Reference>
    10.7 -    <Reference Include="SharpLibDisplay, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    10.8 -      <HintPath>..\packages\SharpLibDisplay.0.2.6\lib\net40\SharpLibDisplay.dll</HintPath>
    10.9 +    <Reference Include="SharpLibDisplay, Version=0.2.8.30538, Culture=neutral, processorArchitecture=MSIL">
   10.10 +      <HintPath>..\packages\SharpLibDisplay.0.2.8\lib\net40\SharpLibDisplay.dll</HintPath>
   10.11        <Private>True</Private>
   10.12      </Reference>
   10.13      <Reference Include="SharpLibHid, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
    11.1 --- a/Server/Spectrum/LineSpectrum.cs	Mon Jan 02 18:43:45 2017 +0100
    11.2 +++ b/Server/Spectrum/LineSpectrum.cs	Wed Jan 04 18:43:28 2017 +0100
    11.3 @@ -13,10 +13,11 @@
    11.4          private double _barSpacing;
    11.5          private double _barWidth;
    11.6          private Size _currentSize;
    11.7 -
    11.8 +        
    11.9 +        
   11.10          public LineSpectrum(FftSize fftSize)
   11.11          {
   11.12 -            FftSize = fftSize;
   11.13 +            FftSize = fftSize;            
   11.14          }
   11.15  
   11.16          [Browsable(false)]
   11.17 @@ -67,38 +68,54 @@
   11.18              }
   11.19          }
   11.20  
   11.21 +        /// <summary>
   11.22 +        /// Update our math.
   11.23 +        /// </summary>
   11.24 +        /// <returns></returns>
   11.25 +        public bool Update()
   11.26 +        {
   11.27 +            return SpectrumProvider.GetFftData(iFftBuffer, this);
   11.28 +        }
   11.29 +
   11.30          public Bitmap CreateSpectrumLine(Size size, Brush brush, Color background, bool highQuality)
   11.31          {
   11.32              if (!UpdateFrequencyMappingIfNessesary(size))
   11.33 +            {
   11.34                  return null;
   11.35 +            }
   11.36  
   11.37 -            var fftBuffer = new float[(int)FftSize];
   11.38 +            //get the fft result from the spectrum provider            
   11.39 +            using (var pen = new Pen(brush, (float)_barWidth))
   11.40 +            {
   11.41 +                var bitmap = new Bitmap(size.Width, size.Height);
   11.42  
   11.43 -            //get the fft result from the spectrum provider
   11.44 -            if (SpectrumProvider.GetFftData(fftBuffer, this))
   11.45 -            {
   11.46 -                using (var pen = new Pen(brush, (float)_barWidth))
   11.47 +                using (Graphics graphics = Graphics.FromImage(bitmap))
   11.48                  {
   11.49 -                    var bitmap = new Bitmap(size.Width, size.Height);
   11.50 +                    PrepareGraphics(graphics, highQuality);
   11.51 +                    graphics.Clear(background);
   11.52  
   11.53 -                    using (Graphics graphics = Graphics.FromImage(bitmap))
   11.54 -                    {
   11.55 -                        PrepareGraphics(graphics, highQuality);
   11.56 -                        graphics.Clear(background);
   11.57 +                    CreateSpectrumLineInternal(graphics, pen, iFftBuffer, size);
   11.58 +                }
   11.59  
   11.60 -                        CreateSpectrumLineInternal(graphics, pen, fftBuffer, size);
   11.61 -                    }
   11.62 -
   11.63 -                    return bitmap;
   11.64 -                }
   11.65 -            }
   11.66 -            return null;
   11.67 +            return bitmap;   
   11.68 +            }            
   11.69          }
   11.70  
   11.71 -        public Bitmap CreateSpectrumLine(Size size, Color color1, Color color2, Color background, bool highQuality)
   11.72 +        /// <summary>
   11.73 +        /// 
   11.74 +        /// </summary>
   11.75 +        /// <param name="size"></param>
   11.76 +        /// <param name="color1"></param>
   11.77 +        /// <param name="color2"></param>
   11.78 +        /// <param name="background"></param>
   11.79 +        /// <param name="highQuality"></param>
   11.80 +        /// <returns></returns>
   11.81 +        public Bitmap Render(Size size, Color color1, Color color2, Color background, bool highQuality)
   11.82          {
   11.83              if (!UpdateFrequencyMappingIfNessesary(size))
   11.84 +            {
   11.85                  return null;
   11.86 +            }
   11.87  
   11.88              using (
   11.89                  Brush brush = new LinearGradientBrush(new RectangleF(0, 0, (float)_barWidth, size.Height), color2,
    12.1 --- a/Server/Spectrum/SpectrumBase.cs	Mon Jan 02 18:43:45 2017 +0100
    12.2 +++ b/Server/Spectrum/SpectrumBase.cs	Wed Jan 04 18:43:28 2017 +0100
    12.3 @@ -15,7 +15,9 @@
    12.4          protected const double MaxDbValue = 0;
    12.5          protected const double DbScale = (MaxDbValue - MinDbValue);
    12.6  
    12.7 -        private int _fftSize;
    12.8 +
    12.9 +        protected float[] iFftBuffer;
   12.10 +        private int _fftSize;        
   12.11          private bool _isXLogScale;
   12.12          private int _maxFftIndex;
   12.13          private int _maximumFrequency = 20000;
   12.14 @@ -117,6 +119,7 @@
   12.15  
   12.16                  _fftSize = (int) value;
   12.17                  _maxFftIndex = _fftSize / 2 - 1;
   12.18 +                iFftBuffer = new float[_fftSize];
   12.19  
   12.20                  RaisePropertyChanged("FFTSize");
   12.21              }
    13.1 --- a/Server/packages.config	Mon Jan 02 18:43:45 2017 +0100
    13.2 +++ b/Server/packages.config	Wed Jan 04 18:43:28 2017 +0100
    13.3 @@ -3,7 +3,7 @@
    13.4    <package id="CSCore" version="1.1.0" targetFramework="net46" />
    13.5    <package id="LibMiniDisplay" version="1.1.8" targetFramework="net46" />
    13.6    <package id="Loamen.agsXMPP" version="1.3.1" targetFramework="net46" />
    13.7 -  <package id="SharpLibDisplay" version="0.2.6" targetFramework="net46" />
    13.8 +  <package id="SharpLibDisplay" version="0.2.8" targetFramework="net46" />
    13.9    <package id="SharpLibHarmony" version="0.7.0" targetFramework="net46" />
   13.10    <package id="SharpLibHid" version="1.4.2" targetFramework="net46" />
   13.11    <package id="SharpLibNotification" version="0.0.1" targetFramework="net46" />