diff --git a/YAMP-alpha/GraphVisualization.cs b/YAMP-alpha/GraphVisualization.cs index 9d54407..3f8c8b6 100644 --- a/YAMP-alpha/GraphVisualization.cs +++ b/YAMP-alpha/GraphVisualization.cs @@ -7,12 +7,22 @@ namespace YAMP_alpha { + public enum Channel + { + Left = 1, + Right = 2, + Both = 3 + } + public class GraphVisualization { private readonly List _left = new List(); - private readonly List _right = new List(); - + private readonly List _right = new List(); private readonly object _lockObj = new object(); + public Color RightChannelColor { get; set; } = Color.Red; + public Color LeftChannelColor { get; set; } = Color.DeepSkyBlue; + + public Channel RenderChannel { get; set; } = Channel.Both; public bool HasSample => _left.Count > 0 && _right.Count > 0; @@ -30,25 +40,35 @@ public Image Draw(int width, int height) var image = new Bitmap(width, height); using (Graphics g = Graphics.FromImage(image)) { - Draw(g, width, height); + Draw(g, width, height, 2); } return image; } - public void Draw(Graphics graphics, int width, int height) + public void Draw(Graphics graphics, int width, int height, int pixelsPerSample) { if (!HasSample) { return; } - const int pixelsPerSample = 2; var samplesLeft = GetSamplesToDraw(_left, width / pixelsPerSample).ToArray(); var samplesRight = GetSamplesToDraw(_right, width / pixelsPerSample).ToArray(); - //left channel: - graphics.DrawLines(new Pen(Color.DeepSkyBlue, 1), GetPoints(samplesLeft, pixelsPerSample, width, height).ToArray()); - //right channel: - graphics.DrawLines(new Pen(Color.FromArgb(150, Color.Red), 0.5f), GetPoints(samplesRight, pixelsPerSample, width, height).ToArray()); + switch (RenderChannel) + { + case Channel.Left: + graphics.DrawLines(new Pen(LeftChannelColor, 1), GetPoints(samplesLeft, pixelsPerSample, width, height).ToArray()); + break; + case Channel.Right: + graphics.DrawLines(new Pen(Color.FromArgb(150, RightChannelColor), 0.5f), GetPoints(samplesRight, pixelsPerSample, width, height).ToArray()); + break; + case Channel.Both: + graphics.DrawLines(new Pen(LeftChannelColor, 1), GetPoints(samplesLeft, pixelsPerSample, width, height).ToArray()); + graphics.DrawLines(new Pen(Color.FromArgb(150, RightChannelColor), 0.5f), GetPoints(samplesRight, pixelsPerSample, width, height).ToArray()); + break; + default: + break; + } } private IEnumerable GetPoints(float[] samples, int pixelsPerSample, int width, int height) @@ -71,7 +91,7 @@ private IEnumerable GetPoints(float[] samples, int pixelsPerSample, int w yield return new Point(0, halfY); yield return new Point(width, halfY); } - } + } private IEnumerable GetSamplesToDraw(List inputSamples, int numberOfSamplesRequested) { @@ -97,6 +117,6 @@ private IEnumerable GetSamplesToDraw(List inputSamples, int number if (Math.Abs(currentMax) < Math.Abs(samples[i])) currentMax = samples[i]; } - } + } } } diff --git a/YAMP-alpha/NewMain.cs b/YAMP-alpha/NewMain.cs index 08615eb..620b24d 100644 --- a/YAMP-alpha/NewMain.cs +++ b/YAMP-alpha/NewMain.cs @@ -481,7 +481,13 @@ private void tagEditorToolStripMenuItem_Click(object sender, EventArgs e) private void pictureBox1_DoubleClick(object sender, EventArgs e) { - visualisation = new GraphVisualization(); + if (visualisation == null) + { + visualisation = new GraphVisualization() + { + RenderChannel = Channel.Both + }; + } visualizer.Enabled = !visualizer.Enabled; if (visualizer.Enabled) {