# HG changeset patch
# User StephaneLenclud
# Date 1483551808 -3600
# Node ID 920fea7a64277cd13d1db8615a5cf8fa74c700cf
# Parent e5f85a895a6208e06848d4ec666db6660e666332
Proper basic support for Audio Visualizer.
diff -r e5f85a895a62 -r 920fea7a6427 Clients/Idle/SharpDisplayClientIdle.csproj
--- a/Clients/Idle/SharpDisplayClientIdle.csproj Mon Jan 02 18:43:45 2017 +0100
+++ b/Clients/Idle/SharpDisplayClientIdle.csproj Wed Jan 04 18:43:28 2017 +0100
@@ -66,8 +66,8 @@
true
-
- ..\..\packages\SharpLibDisplay.0.2.6\lib\net40\SharpLibDisplay.dll
+
+ ..\..\packages\SharpLibDisplay.0.2.8\lib\net40\SharpLibDisplay.dll
True
diff -r e5f85a895a62 -r 920fea7a6427 Clients/Idle/packages.config
--- a/Clients/Idle/packages.config Mon Jan 02 18:43:45 2017 +0100
+++ b/Clients/Idle/packages.config Wed Jan 04 18:43:28 2017 +0100
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff -r e5f85a895a62 -r 920fea7a6427 Clients/Message/SharpDisplayClientMessage.csproj
--- a/Clients/Message/SharpDisplayClientMessage.csproj Mon Jan 02 18:43:45 2017 +0100
+++ b/Clients/Message/SharpDisplayClientMessage.csproj Wed Jan 04 18:43:28 2017 +0100
@@ -65,8 +65,8 @@
true
-
- ..\..\packages\SharpLibDisplay.0.2.6\lib\net40\SharpLibDisplay.dll
+
+ ..\..\packages\SharpLibDisplay.0.2.8\lib\net40\SharpLibDisplay.dll
True
diff -r e5f85a895a62 -r 920fea7a6427 Clients/Message/packages.config
--- a/Clients/Message/packages.config Mon Jan 02 18:43:45 2017 +0100
+++ b/Clients/Message/packages.config Wed Jan 04 18:43:28 2017 +0100
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff -r e5f85a895a62 -r 920fea7a6427 Clients/Test/FormClientTest.Designer.cs
--- a/Clients/Test/FormClientTest.Designer.cs Mon Jan 02 18:43:45 2017 +0100
+++ b/Clients/Test/FormClientTest.Designer.cs Wed Jan 04 18:43:28 2017 +0100
@@ -46,6 +46,8 @@
this.buttonTriggerEvents = new System.Windows.Forms.Button();
this.textBoxEventName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
+ this.buttonLayoutAudioVisualizer = new System.Windows.Forms.Button();
+ this.buttonLayoutMultipleAudioVisualizers = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownPriority)).BeginInit();
this.SuspendLayout();
//
@@ -207,7 +209,7 @@
//
// buttonTriggerEvents
//
- this.buttonTriggerEvents.Location = new System.Drawing.Point(11, 257);
+ this.buttonTriggerEvents.Location = new System.Drawing.Point(8, 317);
this.buttonTriggerEvents.Name = "buttonTriggerEvents";
this.buttonTriggerEvents.Size = new System.Drawing.Size(75, 23);
this.buttonTriggerEvents.TabIndex = 33;
@@ -217,7 +219,7 @@
//
// textBoxEventName
//
- this.textBoxEventName.Location = new System.Drawing.Point(11, 231);
+ this.textBoxEventName.Location = new System.Drawing.Point(8, 291);
this.textBoxEventName.Name = "textBoxEventName";
this.textBoxEventName.Size = new System.Drawing.Size(202, 20);
this.textBoxEventName.TabIndex = 34;
@@ -225,17 +227,39 @@
// label1
//
this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(11, 212);
+ this.label1.Location = new System.Drawing.Point(8, 272);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(67, 13);
this.label1.TabIndex = 35;
this.label1.Text = "Event name:";
//
+ // buttonLayoutAudioVisualizer
+ //
+ this.buttonLayoutAudioVisualizer.Location = new System.Drawing.Point(11, 207);
+ this.buttonLayoutAudioVisualizer.Name = "buttonLayoutAudioVisualizer";
+ this.buttonLayoutAudioVisualizer.Size = new System.Drawing.Size(94, 35);
+ this.buttonLayoutAudioVisualizer.TabIndex = 36;
+ this.buttonLayoutAudioVisualizer.Text = "Audio Visualizer Layout";
+ this.buttonLayoutAudioVisualizer.UseVisualStyleBackColor = true;
+ this.buttonLayoutAudioVisualizer.Click += new System.EventHandler(this.buttonLayoutAudioVisualizer_Click);
+ //
+ // buttonLayoutMultipleAudioVisualizers
+ //
+ this.buttonLayoutMultipleAudioVisualizers.Location = new System.Drawing.Point(111, 207);
+ this.buttonLayoutMultipleAudioVisualizers.Name = "buttonLayoutMultipleAudioVisualizers";
+ this.buttonLayoutMultipleAudioVisualizers.Size = new System.Drawing.Size(94, 35);
+ this.buttonLayoutMultipleAudioVisualizers.TabIndex = 37;
+ this.buttonLayoutMultipleAudioVisualizers.Text = "Multiple Audio Visualizers Layout";
+ this.buttonLayoutMultipleAudioVisualizers.UseVisualStyleBackColor = true;
+ this.buttonLayoutMultipleAudioVisualizers.Click += new System.EventHandler(this.buttonLayoutMultipleAudioVisualizers_Click);
+ //
// FormClientTest
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(499, 292);
+ this.ClientSize = new System.Drawing.Size(564, 351);
+ this.Controls.Add(this.buttonLayoutMultipleAudioVisualizers);
+ this.Controls.Add(this.buttonLayoutAudioVisualizer);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBoxEventName);
this.Controls.Add(this.buttonTriggerEvents);
@@ -284,6 +308,8 @@
private System.Windows.Forms.Button buttonTriggerEvents;
private System.Windows.Forms.TextBox textBoxEventName;
private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.Button buttonLayoutAudioVisualizer;
+ private System.Windows.Forms.Button buttonLayoutMultipleAudioVisualizers;
}
}
diff -r e5f85a895a62 -r 920fea7a6427 Clients/Test/FormClientTest.cs
--- a/Clients/Test/FormClientTest.cs Mon Jan 02 18:43:45 2017 +0100
+++ b/Clients/Test/FormClientTest.cs Wed Jan 04 18:43:28 2017 +0100
@@ -405,5 +405,69 @@
{
iClient.TriggerEventsByName(textBoxEventName.Text);
}
+
+ private void buttonLayoutAudioVisualizer_Click(object sender, EventArgs e)
+ {
+ SetLayoutAudioVisualizer();
+ }
+
+ ///
+ /// Define a layout with a single full screen visualizer.
+ ///
+ private void SetLayoutAudioVisualizer()
+ {
+ //Define layout dimension column by row (x,y)
+ TableLayout layout = new TableLayout(1, 1);
+ //First column take 100%
+ layout.Columns[0].Width = 100F;
+ //Send layout to server
+ iClient.SetLayout(layout);
+
+ //Create our full screen audio visualizer field
+ AudioVisualizerField field = new AudioVisualizerField();
+
+ //Set fields
+ iClient.CreateFields(new DataField[]
+ {
+ field,
+ });
+
+ }
+
+ private void buttonLayoutMultipleAudioVisualizers_Click(object sender, EventArgs e)
+ {
+ SetLayoutMultipleAudioVisualizers();
+ }
+
+ ///
+ /// Define a layout with a single full screen visualizer.
+ ///
+ private void SetLayoutMultipleAudioVisualizers()
+ {
+ //Define layout dimension column by row (x,y)
+ TableLayout layout = new TableLayout(2, 2);
+ //First column take 100%
+ layout.Columns[0].Width = 25F;
+ layout.Columns[1].Width = 75F;
+ //Send layout to server
+ iClient.SetLayout(layout);
+
+ //Create our full screen audio visualizer field
+ AudioVisualizerField field1 = new AudioVisualizerField(0, 0);
+ AudioVisualizerField field2 = new AudioVisualizerField(0, 1);
+ AudioVisualizerField field3 = new AudioVisualizerField(1, 0);
+ AudioVisualizerField field4 = new AudioVisualizerField(1, 1);
+
+ //Set fields
+ iClient.CreateFields(new DataField[]
+ {
+ field1,
+ field2,
+ field3,
+ field4,
+ });
+
+ }
+
}
}
diff -r e5f85a895a62 -r 920fea7a6427 Clients/Test/SharpDisplayClientTest.csproj
--- a/Clients/Test/SharpDisplayClientTest.csproj Mon Jan 02 18:43:45 2017 +0100
+++ b/Clients/Test/SharpDisplayClientTest.csproj Wed Jan 04 18:43:28 2017 +0100
@@ -84,8 +84,8 @@
true
-
- ..\..\packages\SharpLibDisplay.0.2.6\lib\net40\SharpLibDisplay.dll
+
+ ..\..\packages\SharpLibDisplay.0.2.8\lib\net40\SharpLibDisplay.dll
True
diff -r e5f85a895a62 -r 920fea7a6427 Clients/Test/packages.config
--- a/Clients/Test/packages.config Mon Jan 02 18:43:45 2017 +0100
+++ b/Clients/Test/packages.config Wed Jan 04 18:43:28 2017 +0100
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff -r e5f85a895a62 -r 920fea7a6427 Server/FormMain.cs
--- a/Server/FormMain.cs Mon Jan 02 18:43:45 2017 +0100
+++ b/Server/FormMain.cs Wed Jan 04 18:43:28 2017 +0100
@@ -674,11 +674,11 @@
iLineSpectrum = new LineSpectrum(fftSize)
{
SpectrumProvider = spectrumProvider,
- UseAverage = true,
- BarCount = 32,
- BarSpacing = 0,
+ UseAverage = false,
+ BarCount = 16,
+ BarSpacing = 1,
IsXLogScale = true,
- ScalingStrategy = ScalingStrategy.Sqrt
+ ScalingStrategy = ScalingStrategy.Decibel
};
@@ -727,24 +727,44 @@
///
///
///
- private void GenerateAudioVisualization()
+ private void UpdateAudioVisualization()
{
// For demo draft purposes just fetch the firt picture box control and update it with current audio spectrum
- foreach (Control ctrl in iTableLayoutPanel.Controls)
+
+ if (iCurrentClientData == null)
{
- if (ctrl is PictureBox)
+ return;
+ }
+
+ // Update our math
+ if (!iLineSpectrum.Update())
+ {
+ //Nothing changed no need to render
+ return;
+ }
+
+ // Check if our current client has an Audio Visualizer field
+ // and render them as needed
+ foreach (DataField f in iCurrentClientData.Fields)
+ {
+ if (f is AudioVisualizerField)
{
- PictureBox pb = (PictureBox)ctrl;
- Image image = pb.Image;
- var newImage = iLineSpectrum.CreateSpectrumLine(pb.Size, Color.Black, Color.Black, Color.White, false);
- if (newImage != null)
+ AudioVisualizerField avf = (AudioVisualizerField)f;
+ Control ctrl = iTableLayoutPanel.GetControlFromPosition(avf.Column, avf.Row);
+
+ if (ctrl is PictureBox)
{
- pb.Image = newImage;
- if (image != null)
- image.Dispose();
+ PictureBox pb = (PictureBox)ctrl;
+ Image image = pb.Image;
+ // TODO: recycle images
+ var newImage = iLineSpectrum.Render(pb.Size, Color.Black, Color.Black, Color.White, false);
+ if (newImage != null)
+ {
+ pb.Image = newImage;
+ if (image != null)
+ image.Dispose();
+ }
}
-
- break;
}
}
}
@@ -1220,10 +1240,10 @@
}
}
- GenerateAudioVisualization();
+ UpdateAudioVisualization();
//Compute instant FPS
- toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " +
+ toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " +
(1000/iTimerDisplay.Interval).ToString() + " FPS";
LastTickTime = NewTickTime;
@@ -1948,21 +1968,25 @@
Control ctrl = iTableLayoutPanel.GetControlFromPosition(tableField.Column, tableField.Row);
if (aField.IsTextField && ctrl is MarqueeLabel)
{
- TextField textField = (TextField) aField;
+ TextField textField = (TextField)aField;
//Text field control already in place, just change the text
- MarqueeLabel label = (MarqueeLabel) ctrl;
+ MarqueeLabel label = (MarqueeLabel)ctrl;
contentChanged = (label.Text != textField.Text || label.TextAlign != textField.Alignment);
label.Text = textField.Text;
label.TextAlign = textField.Alignment;
}
else if (aField.IsBitmapField && ctrl is PictureBox)
{
- BitmapField bitmapField = (BitmapField) aField;
+ BitmapField bitmapField = (BitmapField)aField;
contentChanged = true; //TODO: Bitmap comp or should we leave that to clients?
//Bitmap field control already in place just change the bitmap
- PictureBox pictureBox = (PictureBox) ctrl;
+ PictureBox pictureBox = (PictureBox)ctrl;
pictureBox.Image = bitmapField.Bitmap;
}
+ else if (aField is AudioVisualizerField && ctrl is PictureBox)
+ {
+ contentChanged = false; // Since nothing was changed
+ }
else
{
layoutChanged = true;
@@ -2234,6 +2258,10 @@
{
textsRoot.Nodes.Add(new TreeNode("[Bitmap]"));
}
+ else if (field is AudioVisualizerField)
+ {
+ textsRoot.Nodes.Add(new TreeNode("[Audio Visualizer]"));
+ }
else if (field.IsRecordingField)
{
RecordingField recordingField = (RecordingField) field;
@@ -2368,7 +2396,7 @@
//control.TabIndex = 2;
label.Font = cds.Font;
- TextField field = (TextField) aField;
+ TextField field = (TextField)aField;
label.TextAlign = field.Alignment;
label.UseCompatibleTextRendering = true;
label.Text = field.Text;
@@ -2386,11 +2414,24 @@
picture.Margin = new System.Windows.Forms.Padding(0);
picture.Name = "pictureBox" + aField;
//Set our image
- BitmapField field = (BitmapField) aField;
+ BitmapField field = (BitmapField)aField;
picture.Image = field.Bitmap;
//
control = picture;
}
+ else if (aField is AudioVisualizerField)
+ {
+ //Create picture box
+ PictureBox picture = new PictureBox();
+ picture.AutoSize = true;
+ picture.BackColor = System.Drawing.Color.Transparent;
+ picture.Dock = System.Windows.Forms.DockStyle.Fill;
+ picture.Location = new System.Drawing.Point(1, 1);
+ picture.Margin = new System.Windows.Forms.Padding(0);
+ picture.Name = "pictureBox" + aField;
+ control = picture;
+ }
+
//TODO: Handle recording field?
return control;
diff -r e5f85a895a62 -r 920fea7a6427 Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj Mon Jan 02 18:43:45 2017 +0100
+++ b/Server/SharpDisplayManager.csproj Wed Jan 04 18:43:28 2017 +0100
@@ -128,8 +128,8 @@
..\packages\LibMiniDisplay.1.1.8\lib\net20\MiniDisplayInterop.dll
True
-
- ..\packages\SharpLibDisplay.0.2.6\lib\net40\SharpLibDisplay.dll
+
+ ..\packages\SharpLibDisplay.0.2.8\lib\net40\SharpLibDisplay.dll
True
diff -r e5f85a895a62 -r 920fea7a6427 Server/Spectrum/LineSpectrum.cs
--- a/Server/Spectrum/LineSpectrum.cs Mon Jan 02 18:43:45 2017 +0100
+++ b/Server/Spectrum/LineSpectrum.cs Wed Jan 04 18:43:28 2017 +0100
@@ -13,10 +13,11 @@
private double _barSpacing;
private double _barWidth;
private Size _currentSize;
-
+
+
public LineSpectrum(FftSize fftSize)
{
- FftSize = fftSize;
+ FftSize = fftSize;
}
[Browsable(false)]
@@ -67,38 +68,54 @@
}
}
+ ///
+ /// Update our math.
+ ///
+ ///
+ public bool Update()
+ {
+ return SpectrumProvider.GetFftData(iFftBuffer, this);
+ }
+
public Bitmap CreateSpectrumLine(Size size, Brush brush, Color background, bool highQuality)
{
if (!UpdateFrequencyMappingIfNessesary(size))
+ {
return null;
+ }
- var fftBuffer = new float[(int)FftSize];
+ //get the fft result from the spectrum provider
+ using (var pen = new Pen(brush, (float)_barWidth))
+ {
+ var bitmap = new Bitmap(size.Width, size.Height);
- //get the fft result from the spectrum provider
- if (SpectrumProvider.GetFftData(fftBuffer, this))
- {
- using (var pen = new Pen(brush, (float)_barWidth))
+ using (Graphics graphics = Graphics.FromImage(bitmap))
{
- var bitmap = new Bitmap(size.Width, size.Height);
+ PrepareGraphics(graphics, highQuality);
+ graphics.Clear(background);
- using (Graphics graphics = Graphics.FromImage(bitmap))
- {
- PrepareGraphics(graphics, highQuality);
- graphics.Clear(background);
+ CreateSpectrumLineInternal(graphics, pen, iFftBuffer, size);
+ }
- CreateSpectrumLineInternal(graphics, pen, fftBuffer, size);
- }
-
- return bitmap;
- }
- }
- return null;
+ return bitmap;
+ }
}
- public Bitmap CreateSpectrumLine(Size size, Color color1, Color color2, Color background, bool highQuality)
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public Bitmap Render(Size size, Color color1, Color color2, Color background, bool highQuality)
{
if (!UpdateFrequencyMappingIfNessesary(size))
+ {
return null;
+ }
using (
Brush brush = new LinearGradientBrush(new RectangleF(0, 0, (float)_barWidth, size.Height), color2,
diff -r e5f85a895a62 -r 920fea7a6427 Server/Spectrum/SpectrumBase.cs
--- a/Server/Spectrum/SpectrumBase.cs Mon Jan 02 18:43:45 2017 +0100
+++ b/Server/Spectrum/SpectrumBase.cs Wed Jan 04 18:43:28 2017 +0100
@@ -15,7 +15,9 @@
protected const double MaxDbValue = 0;
protected const double DbScale = (MaxDbValue - MinDbValue);
- private int _fftSize;
+
+ protected float[] iFftBuffer;
+ private int _fftSize;
private bool _isXLogScale;
private int _maxFftIndex;
private int _maximumFrequency = 20000;
@@ -117,6 +119,7 @@
_fftSize = (int) value;
_maxFftIndex = _fftSize / 2 - 1;
+ iFftBuffer = new float[_fftSize];
RaisePropertyChanged("FFTSize");
}
diff -r e5f85a895a62 -r 920fea7a6427 Server/packages.config
--- a/Server/packages.config Mon Jan 02 18:43:45 2017 +0100
+++ b/Server/packages.config Wed Jan 04 18:43:28 2017 +0100
@@ -3,7 +3,7 @@
-
+