// private const bool _debug = false; #endregion private void LayoutNotes(Graphics g, int widthStave) { DebugWrite(string.Format("Layout({0}/{1}): ", _isLayoutDirty, widthStave != _oldWidth)); if (_tune != null && _tune.Count > 0 && (_isLayoutDirty || widthStave != _oldWidth)) { _isLayoutDirty = false; int x = widthStave; g.ScaleTransform(_scale, _scale); _score = new Score(widthStave); MusicPaths.StartUp(new Size(widthStave - 10, 0)); ScoreLine scoreLine = null; IAwareNote note = null; for (int iNote = 0; iNote < _tune.Count; iNote++) { if (iNote == 0) { scoreLine = new ScoreLine(_score.Count, g.Transform, iNote); x = 35; } if (widthStave < x + 24) { scoreLine.MaxNoteNo = iNote; scoreLine.MaxNotePosition = note.SpanPosition; _score += scoreLine; g.TranslateTransform(0F, _height); scoreLine = new ScoreLine(_score.Count, g.Transform, iNote); x = 35; } note = _tune[iNote]; int y = 32; if (note.PianoKey != PianoKey.Rest) { y += 18 - 3 * (note.NoteLetter.NoteIndex() - NoteLetter.C.NoteIndex()) - 21 * (note.PianoKey.Octave() - PianoKey.C_4.Octave()); } var width = 20 + Math.Abs((int)note.SharpFlat) * 7 + note.Length.DotCount * 4; var notePos = new ScoreNotePosition(x, y, width, note.SpanPosition, note.SpanLength, iNote); scoreLine += notePos; x += width; } scoreLine.MaxNoteNo = _tune.Count - 1; scoreLine.MaxNotePosition = note.SpanPosition; _score += scoreLine; _oldWidth = widthStave; Panel2.AutoScrollMinSize = new SizeF(_oldWidth, 75 + _height + (int)g.Transform.Elements[5]).ToSize(); DebugWrite(" done"); } else if (_tune == null || _tune.Count == 0) { Panel2.AutoScrollMinSize = g.VisibleClipBounds.Size.ToSize(); DebugWrite(" skipped"); } DebugWriteLine(); }
/// <summary>TODO</summary> public HighlightMessage(Action <NextNoteEventArgs> sink, float time, IAwareNote note) : base(time) { _note = note; _msgSink = sink; }
public NextNoteEventArgs(IAwareNote note) : base() { _position = note.SpanPosition; _length = note.SpanLength; }
private void PaintNotes(Graphics g) { DebugWrite("PaintList: "); if (_tune != null && _score != null && _score.Count != 0 && !g.IsClipEmpty) { var loc = new PointF(5, 22); var size = new Size(_score.Width - 10, 0); var paths = MusicPaths.Get; g.SmoothingMode = _highQuality ? SmoothingMode.HighQuality : SmoothingMode.Default; g.SmoothingMode = SmoothingMode.HighQuality; DebugWrite(g.VisibleClipBounds.ToString()); foreach (IScoreLine scoreLine in _score) { g.Transform = scoreLine.Matrix; g.TranslateTransform(0, Panel2.AutoScrollPosition.Y, MatrixOrder.Append); var r = new RectangleF(0, 0, _score.Width - 10, _height + 50); if (InClip(g.VisibleClipBounds, r)) { DebugWrite(scoreLine.Index + ", "); DrawPianoStaff(g, loc, size, _spacing); foreach (IScoreNotePosition notePos in scoreLine) { IAwareNote note = (IAwareNote)_tune[notePos.NoteNo]; int x = notePos.X, y = notePos.Y; if (InClip(g.VisibleClipBounds, new RectangleF(x, 0, notePos.Width, _height + 50))) { if (note.PianoKey == PianoKey.Rest) { note.DrawRest(g, new Point(x, y)); } else if (note.PianoKey == PianoKey.Bar) { DrawBar(g, new Point(x, y), _spacing); } else { int i = (int)note.SharpFlat; while (i > 0) { paths.Sharp.Draw(g, new PointF(x, y)); x += 7; i--; } while (i < 0) { paths.Flat.Draw(g, new PointF(x, y)); x += 7; i++; } // Stem stem = y < 23 ? Stem.Down : Stem.Up; // middle treble staff Stem stem = y > 51 ? Stem.Down : Stem.Up; // Middle-C note.DrawNote(g, new Point(x, y), stem); // Draw staff-extension (leger) lines for note if (y == 50) { g.DrawLine(_penThin, x - 3, 52, x + 12, 52); } int y2 = y, y3 = 88, y4 = 16; while (y2 > 83) { g.DrawLine(_penThin, x - 3, y3, x + 12, y3); y2 -= 6; y3 += 6; } while (y2 < 17) { g.DrawLine(_penThin, x - 3, y4, x + 12, y4); y2 += 6; y4 -= 6; } } x += 20; for (int i = 0; i < note.Length.DotCount; i++) { g.FillEllipse(Brushes.Black, x - 10F, ((y + 3) / 6) * 6, 3F, 3F); x += 4; } } } } } } DebugWriteLine(); }