protected override void OnPaint(PaintEventArgs e) { if (moving) { e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; } else { e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear; } if (spectrogramImage == null) { e.Graphics.Clear(Color.White); return; } projectionHeightRatio = spectrogramImage.Height / projectionRect.Height; projectionWidthRatio = spectrogramImage.Width / projectionRect.Width; e.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; e.Graphics.DrawImage(spectrogramImage, new Rectangle(PADDING_LEFT, 0, this.Width - PADDING_LEFT, this.Height - PADDING_BOTTOM), projectionRect, GraphicsUnit.Pixel); e.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; if (ShowNoteAnnotations) { SpectrogramHandler.NoteAnnotation[] noteAnnotations = DrawNoteAnnotations(); if (noteAnnotations != null) { float penSize = Math.Min(Math.Max(2 * projectionHeightRatio, 1), 12); using (Pen p = new Pen(Color.Green, penSize)) { foreach (SpectrogramHandler.NoteAnnotation note in noteAnnotations) { int alpha = Math.Min(Math.Max((int)(note.magnitude / MySpectrogramHandler.GetMaxNoteMagnitude() * 255), 127), 220); p.Color = Color.FromArgb(alpha, 0, 128, 0); e.Graphics.DrawLine(p, new Point(note.shape.X, (int)(note.shape.Y + penSize / 2)), new Point(note.shape.X + note.shape.Width, (int)(note.shape.Y + penSize / 2))); if (penSize > 4) { e.Graphics.DrawString(note.name, new Font(Form1.fonts.Families[0], penSize), new SolidBrush(Color.White), new Point(note.shape.X + 5, (int)(note.shape.Y - penSize / 2))); } } } } } if (ShowChordKeyAnnotations) { SpectrogramHandler.ChordAnnotation[] chordAnnotations = DrawChordAnnotations(); if (chordAnnotations != null) { foreach (SpectrogramHandler.ChordAnnotation chord in chordAnnotations) { Pen p = new Pen(Color.FromArgb(200, Analyser.GetNoteColor(30, 60, (int)chord.confidence)), 5); e.Graphics.DrawLine(p, new Point(chord.shape.X + 2, chord.shape.Y), new Point(chord.shape.X + chord.shape.Width - 2, chord.shape.Y)); int textX = Math.Max(chord.shape.X, PADDING_LEFT) + Math.Min(chord.shape.Width, this.Width - PADDING_LEFT) / 2 - 4 * chord.name.Length; e.Graphics.DrawString(chord.name, new Font(Form1.fonts.Families[0], 8), new SolidBrush(Color.White), new Point(textX, chord.shape.Y + 6)); } } SpectrogramHandler.KeyAnnotation[] keyAnnotations = DrawKeyAnnotations(); if (keyAnnotations != null) { using (Pen p = new Pen(Color.FromArgb(200, Color.Green), 10)) { foreach (SpectrogramHandler.KeyAnnotation key in keyAnnotations) { e.Graphics.DrawLine(p, new Point(key.shape.X + 2, key.shape.Y), new Point(key.shape.X + key.shape.Width - 2, key.shape.Y)); int textX = Math.Max(key.shape.X, PADDING_LEFT) + Math.Min(key.shape.Width, this.Width - PADDING_LEFT) / 2 - 4 * key.name.Length; e.Graphics.DrawString(key.name, new Font(Form1.fonts.Families[0], 8), new SolidBrush(Color.White), new Point(textX, key.shape.Y - 10)); } } } } if (projectionRect != prevProjectionRect) { Overlay.DrawTimeAxis(); Overlay.DrawFrequencyAxis(); prevProjectionRect = projectionRect; } base.OnPaint(e); }
public void GenerateAnnotations() { MySpectrogramHandler.GenerateAnnotations(); }