public void Draw( Graphics graphics, SheetMusicRenderSettings settings, int width, int x ) { graphics.TranslateTransform(x, 0); Render(graphics, settings, width); graphics.TranslateTransform(-x, 0); //if (lastwidth != width) { // lastwidth = width; // bmp = // new Bitmap( // width, // (int)settings.Height // ); // using (var gfx = Graphics.FromImage(bmp)) { // gfx.CompositingQuality = CompositingQuality.HighQuality; // gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; // gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; // gfx.SmoothingMode = SmoothingMode.HighQuality; // gfx.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; // Render(gfx, settings, lastwidth); // } //} //return bmp; }
public virtual void Select( NoteSelection selection, RectangleF rectangle, SheetMusicRenderSettings settings, float width ) { }
void DrawMeasureDivision(Graphics gfx, SheetMusicRenderSettings settings, int width) { gfx.DrawLine( pen_measuredivision, width - 2 * pen_measuredivision.Width - Margin, settings.YVal(settings.Staff.Lines * 2 - 2), width - 2 * pen_measuredivision.Width - Margin, settings.YVal(0) ); }
public override void Select( NoteSelection selection, RectangleF rectangle, SheetMusicRenderSettings settings, float width ) { rectangle.X -= Margin; foreach (var chord in layoutmeasure.Chords) { var x = chord.X * width; var w = chord.Width * width; foreach (var note in chord.Notes) { var y = settings.YVal(note.HalfLine); var noteID = note.Core.Note.ID; var rect_head = new RectangleF( x - settings.NoteHeadRadius, y - settings.NoteHeadRadius, 2 * settings.NoteHeadRadius, 2 * settings.NoteHeadRadius ); if (rect_head.IntersectsWith(rectangle)) { selection.Selected_Start.Add(noteID); selection.Selected_End.Add(noteID); selection.Selected_Tone.Add(noteID); } else { var boxy = y; boxy -= settings.PixelsPerHalfLine * note.Transform.Steps; var rect_tail = new RectangleF( x + w - 2 * settings.ThumbMarginX, boxy - settings.PixelsPerHalfLine / 2, 2 * settings.ThumbMarginX, settings.PixelsPerHalfLine ); if (rect_tail.IntersectsWith(rectangle)) { selection.Selected_End.Add(noteID); } } } } }
protected override void Render(Graphics gfx, SheetMusicRenderSettings settings, int width) { var upper_str = simple.Upper.ToString(); var lower_str = simple.Lower.ToString(); var upper_sz = gfx.MeasureString(upper_str, settings.TimeSignatureFont); var lower_sz = gfx.MeasureString(lower_str, settings.TimeSignatureFont); gfx.DrawString(upper_str, settings.TimeSignatureFont, Brushes.Black, 0, settings.YVal(4) - upper_sz.Height); gfx.DrawString(lower_str, settings.TimeSignatureFont, Brushes.Black, 0, settings.YVal(0) - lower_sz.Height); }
static void DrawPitchTransform( Graphics gfx, Color color, PitchTransform transform, float x, float y, SheetMusicRenderSettings settings ) { const float separation = 20f; const float offset = 0f; if (transform.Steps > 0) { for (int i = 0; i < transform.Steps / 2; i++) { GlyphRenderer.Draw( "double-sharp", x - separation * i - offset, y, color, gfx, settings ); } if (transform.Steps % 2 != 0) { GlyphRenderer.Draw( "sharp", x - separation * (transform.Steps / 2) - offset, y, color, gfx, settings ); } } else if (transform.Steps < 0) { for (int i = 0; i < -transform.Steps; i++) { GlyphRenderer.Draw( "flat", x - separation * i - offset, y, color, gfx, settings ); } } }
protected override void Render(Graphics gfx, SheetMusicRenderSettings settings, int width) { gfx.TranslateTransform(Margin, 0); foreach (var chord in layoutmeasure.Chords) { NoteRenderer.DrawChord(gfx, settings, Color.Black, Color.Blue, chord, true, width - (int)(2 * Margin)); } DrawMeasureDivision(gfx, settings, width); gfx.TranslateTransform(-Margin, 0); }
static void DrawLedger( Graphics gfx, float x, float halfline, SheetMusicRenderSettings settings ) => gfx.DrawLine( settings.StaffLinePen, x - settings.LedgerPixelWidth / 2, settings.YVal(halfline), x + settings.LedgerPixelWidth / 2, settings.YVal(halfline) );
public static void DrawChord( Graphics graphics, SheetMusicRenderSettings settings, Color color, Color fieldcolor, ChordLayout chord, bool drawfield, int width ) { var x = chord.X * width; var notewidth = chord.Width * width; foreach (var note in chord.Notes) { DrawNote( graphics, color, fieldcolor, note, chord.StemDirection, chord.StemSide, note.Transform, x, notewidth, settings.YVal(chord.StemStartHalfLines), drawfield, settings ); } DrawFlags( graphics, color, x, chord.FlagDirection, chord, chord.FlagLength, settings.YVal(chord.StemStartHalfLines), chord.FlagSlope, chord.TiedFlags, chord.FreeFlags, chord.StemDirection, chord.StemSide, settings, width, chord.Past2nd ); }
static void DrawNoteStem_L( Graphics gfx, Color color, float x, float y, NoteStemDirection direction, float y_end, SheetMusicRenderSettings settings ) { if (direction != NoteStemDirection.None) { gfx.DrawLine(new Pen(color, 3.0f), x - settings.NoteHeadRadius, y, x - settings.NoteHeadRadius, y_end); } }
public static void Draw( string name, float x, float y, Color color, Graphics graphics, SheetMusicRenderSettings settings ) { var matrix = new ColorMatrix(); matrix.Matrix00 = color.R / 255f; matrix.Matrix11 = color.G / 255f; matrix.Matrix22 = color.B / 255f; matrix.Matrix33 = color.A / 255f; var attributes = new ImageAttributes(); attributes.SetColorMatrix(matrix); var glyph = glyphs[name]; // 2 lines should be the height of the glyph var scale = 4 * settings.PixelsPerLine / glyph.Height; graphics.DrawImage( glyph, new Rectangle( (int)(x - scale * glyph.Width / 2), (int)(y - scale * glyph.Height / 2), (int)(scale * glyph.Width), (int)(scale * glyph.Height) ), 0, 0, glyph.Width, glyph.Height, GraphicsUnit.Pixel, attributes ); }
static void DrawNoteHead( Graphics gfx, Color color, float x, float y, float y_dots, bool fill, int dots, SheetMusicRenderSettings settings ) { gfx.DrawEllipse(new Pen(color, 2.5f), x - settings.NoteHeadRadius, y - settings.NoteHeadRadius, 2 * settings.NoteHeadRadius, 2 * settings.NoteHeadRadius); if (fill) { gfx.FillEllipse(new SolidBrush(color), x - settings.NoteHeadRadius, y - settings.NoteHeadRadius, 2 * settings.NoteHeadRadius, 2 * settings.NoteHeadRadius); } for (int i = 0; i < dots; i++) { gfx.FillEllipse(new SolidBrush(color), x + settings.NoteHeadRadius + i * settings.DotSpacing + settings.DotInitialSpacing, y_dots - settings.DotRadius, settings.DotRadius * 2F, settings.DotRadius * 2F); } }
static void DrawNote( Graphics gfx, Color color, Color fieldcolor, NoteLayout note, NoteStemDirection direction, NoteStemSide side, PitchTransform transform, float x, float notewidth, float stem_end, bool drawfield, SheetMusicRenderSettings settings ) { var halfline = settings.Staff.GetHalfLine(note.Key); for (int i = halfline / 2; i < 0; i++) { DrawLedger(gfx, x, 2 * i, settings); } for (int i = (halfline / 2 - settings.Staff.Lines + 1); i > 0; i--) { DrawLedger(gfx, x, 2 * (settings.Staff.Lines + i - 1), settings); } var y = settings.YVal(note.HalfLine); var fill = note.Core.Length.Length > LengthClass.Half; var dots = note.Core.Length.Dots; var y_dots = settings.YVal(note.HalfLine + (note.HalfLine + 1) % 2); var selected_start = settings.Selection.Selected_Start.Contains(note.Core.Note.ID); var selected_end = settings.Selection.Selected_End.Contains(note.Core.Note.ID); var selected_tone = settings.Selection.Selected_Tone.Contains(note.Core.Note.ID); var fieldcolorinterpolation = (selected_end ? 1 : 0) + (selected_start ? 1 : 0) + (selected_tone ? 1 : 0); DrawPitchTransform( gfx, color, transform, x - 2 * settings.NoteHeadRadius, y, settings ); if (note.Core.ID.Instance == 0) { if (drawfield) { var fieldbcolor = color.Lerp(fieldcolor, fieldcolorinterpolation / 3f).Alpha(0.5); var fieldfcolor = fieldcolorinterpolation == 3 ? fieldcolor : color; var thumbpen = new Pen(fieldfcolor, settings.ThumbWidth); var fieldy = y; gfx.FillRectangle( new SolidBrush(fieldbcolor), x, fieldy - settings.PixelsPerHalfLine / 2, notewidth, settings.PixelsPerHalfLine ); gfx.DrawLine( thumbpen, x + settings.ThumbPadding, fieldy, x + notewidth - 2 * settings.ThumbPadding, fieldy ); gfx.DrawLine( thumbpen, x + notewidth - settings.ThumbMarginX, fieldy - settings.PixelsPerHalfLine / 2 + settings.ThumbMarginY, x + notewidth - settings.ThumbMarginX, fieldy + settings.PixelsPerHalfLine / 2 - settings.ThumbMarginY ); } } DrawNoteHead(gfx, fieldcolorinterpolation == 3 ? fieldcolor : color, x, y, y_dots, fill, dots, settings); if (side == NoteStemSide.Left) { DrawNoteStem_L(gfx, color, x, y, direction, stem_end, settings); } else if (side == NoteStemSide.Right) { DrawNoteStem_R(gfx, color, x, y, direction, stem_end, settings); } }
public abstract float MinWidth(SheetMusicRenderSettings settings);
public override float MinWidth(SheetMusicRenderSettings settings) => settings.PixelsScale * settings.PixelsPerLine * 2;
public virtual float PixelAtTime(Time offset, float width, SheetMusicRenderSettings settings) => float.NaN;
void DrawCaret( Graphics gfx, SheetMusicRenderSettings settings, bool active, MusicTrack track, float scrollX ) { var caretx = GetLeft(editor.Cursor.Caret.Focus, track) - scrollX; var caretunitx = GetLeft(editor.Cursor.Caret.Focus + editor.Cursor.Caret.Unit.Value, track) - scrollX; var caretstaff = track .Adornment .Staffs .Intersecting(editor.Cursor.Caret.Focus) .First() .Value; PitchTransform transform; var caretkey = track .Adornment .KeySignatures .Intersecting(editor.Cursor.Caret.Focus) .First() .Value .Key(editor.Cursor.Tone.Value, out transform); var carety = settings.YVal(caretstaff.GetHalfLine(caretkey)); var caret_pen_x = new Pen(Color.DarkSeaGreen, active ? 2.5f : 1.2f); var caret_pen_y = new Pen(Color.Red, active ? 3f : 1.4f); gfx .DrawLine( caret_pen_x, caretx, 0, caretx, settings.Height ); gfx .DrawLine( caret_pen_y, caretx, carety, caretunitx, carety ); var cursorcolor = active ? Color.FromArgb(200, Color.DeepSkyBlue) : Color.FromArgb(100, Color.Aquamarine); var cursor_focusduration = new Duration { Start = editor.Cursor.Caret.Focus, Length = editor.Cursor.Caret.Unit.Value }; var cursor_notelayout = new NoteLayout( new PerceptualNote( default(PerceptualNoteID), cursor_focusduration, PerceptualTime.Decompose(editor.Cursor.Caret.Unit.Value).First().Key, track.Rhythm.Intersecting(cursor_focusduration).First(), new Note( default(NoteID), cursor_focusduration, editor.Cursor.Tone.Value ) ), settings .Staff .GetHalfLine(caretkey), 0, 0, caretkey, transform ); var cursor_chordlayout = new ChordLayout(cursor_notelayout); if (cursor_chordlayout.Length.Length > LengthClass.Whole) { cursor_chordlayout.StemDirection = settings.Staff.GetStemDirection(cursor_notelayout.Key); cursor_chordlayout.StemSide = cursor_chordlayout.StemDirection == NoteStemDirection.Down ? NoteStemSide.Left : NoteStemSide.Right; cursor_chordlayout.StemStartHalfLines = cursor_chordlayout.StemDirection == NoteStemDirection.Down ? cursor_notelayout.HalfLine - 5 : cursor_notelayout.HalfLine + 5; } if (cursor_chordlayout.Length.Length > LengthClass.Quarter) { cursor_chordlayout.FreeFlags = cursor_chordlayout.Length.Length - LengthClass.Quarter; cursor_chordlayout.FlagDirection = cursor_chordlayout.StemDirection == NoteStemDirection.Down ? FlagDirection.Left : FlagDirection.Right; } gfx.TranslateTransform(caretx, 0); NoteRenderer .DrawChord( gfx, settings, cursorcolor, Color.SeaGreen, cursor_chordlayout, false, 500 ); gfx.TranslateTransform(-caretx, 0); }
void DrawToGraphics(Graphics gfx) { gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //gfx.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; //gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; gfx.DrawString(timesRedrawn.ToString(), Font, Brushes.Red, PointF.Empty); var scrollX = GetLeft(editor.Pin.Time.ActualTime.Value); foreach (var track in editor.Tracks.Cast <MusicTrack>()) { var active = ReferenceEquals(track, editor.ActiveTrack); // draw sheet items var starttimes = track .Memory .Analyses <RenderedSheetMusicItem>(Duration.Eternity) .Select(item => item.Duration) .Select(duration => duration.Start) .Distinct() .ToList(); starttimes.Sort(); SheetMusicRenderSettings focussettings = null; if (starttimes.Count != 0) { var focusstarttime = default(Time); var focusitems = new List <RenderedSheetMusicItem>(); float x = GetLeft(focusstarttime) - scrollX; while (x < Width) { if (focusitems.Count == 0) { if (starttimes.Count == 0) { break; } focusstarttime = starttimes[0]; starttimes.RemoveAt(0); focusitems .AddRange( track .Memory .Analyses <RenderedSheetMusicItem>(focusstarttime) .Select(focusitem => focusitem.Value) ); focusitems.Sort((a, b) => b.Priority.CompareTo(a.Priority)); focussettings = GetSettings(focusstarttime, track); // draw staff for (int line = 0; line < focussettings.Staff.Lines; line++) { gfx.DrawLine( focussettings.StaffLinePen, x, focussettings.YVal(line * 2), x + focusitems.Sum(focusitem => itemwidths[track][focusitem]), focussettings.YVal(line * 2) ); } } var item = focusitems[0]; focusitems.RemoveAt(0); var width = itemwidths[track][item]; if (x + width > 0) { item.Draw(gfx, focussettings, (int)width, (int)x); } x += width; } } DrawCaret(gfx, GetSettings(editor.Cursor.Caret.Focus, track), active, track, scrollX); if (trackheights.ContainsKey(track)) { gfx.TranslateTransform(0, trackheights[track]); } } gfx.ResetTransform(); mouseselector.Draw(gfx); }
float GetLeft(Time time, MusicTrack track) { var starttimes = track .Memory .Analyses <RenderedSheetMusicItem>(Duration.Eternity) .Select(item => item.Duration) .Select(duration => duration.Start) .Distinct() .ToList(); starttimes.Sort(); SheetMusicRenderSettings focussettings = null; float x = 0; if (starttimes.Count != 0) { var focusstarttime = default(Time); var focusitems = new List <IDuratedItem <RenderedSheetMusicItem> >(); x = GetLeft(focusstarttime); while (focusstarttime <= time) { if (focusitems.Count == 0) { if (starttimes.Count == 0) { break; } focusstarttime = starttimes[0]; starttimes.RemoveAt(0); focusitems .AddRange( track .Memory .Analyses <RenderedSheetMusicItem>(focusstarttime) ); focusitems.Sort((a, b) => b.Value.Priority.CompareTo(a.Value.Priority)); focussettings = GetSettings(focusstarttime, track); } var focusitem = focusitems[0]; var item = focusitem.Value; focusitems.RemoveAt(0); var width = itemwidths[track][item]; if (item.Stretchy && focusitem.Duration.Contains(time)) { return(x + item.PixelAtTime(time - focusitem.Duration.Start, width, focussettings)); } x += width; } } return(x); }
IEnumerable <Tuple <RectangleF, SheetMusicRenderSettings, RenderedSheetMusicItem> > GetItemsWithRects(MusicTrack track) { var scrollX = GetLeft(editor.Pin.Time.ActualTime.Value); var yoffset = editor.Tracks.TakeWhile(t => !ReferenceEquals(t, track)).Sum(t => trackheights[t as MusicTrack]); var starttimes = track .Memory .Analyses <RenderedSheetMusicItem>(Duration.Eternity) .Select(item => item.Duration) .Select(duration => duration.Start) .Distinct() .ToList(); starttimes.Sort(); SheetMusicRenderSettings focussettings = null; if (starttimes.Count != 0) { var focusstarttime = starttimes[0]; var focusitems = new List <RenderedSheetMusicItem>(); float x = 0 - scrollX; while (x < Width) { if (focusitems.Count == 0) { if (starttimes.Count == 0) { break; } focusstarttime = starttimes[0]; starttimes.RemoveAt(0); focusitems .AddRange( track .Memory .Analyses <RenderedSheetMusicItem>(focusstarttime) .Select(focusitem => focusitem.Value) ); focusitems.Sort((a, b) => b.Priority.CompareTo(a.Priority)); focussettings = GetSettings(focusstarttime, track); } var item = focusitems[0]; focusitems.RemoveAt(0); var width = itemwidths[track][item]; yield return (new Tuple <RectangleF, SheetMusicRenderSettings, RenderedSheetMusicItem>( new RectangleF( x, yoffset, width, focussettings.Height ), focussettings, item )); x += width; } } }
public override float MinWidth(SheetMusicRenderSettings settings) => (float)Math.Max( Math.Ceiling(Math.Log10(simple.Upper)), Math.Ceiling(Math.Log10(simple.Lower)) ) * settings.PixelsScale * 25F;
public override float PixelAtTime(Time offset, float width, SheetMusicRenderSettings settings) => Time.FloatDiv(offset, layoutmeasure.Duration.Length) * (width - 1.5f * Margin) + Margin + 0 * settings.NoteHeadRadius;
static void DrawFlags( Graphics gfx, Color color, float x, FlagDirection direction, ChordLayout chord, float length, float y_start, float slope, int flags_tied, int flags_free, NoteStemDirection stemdirection, NoteStemSide side, SheetMusicRenderSettings settings, int width, bool past2nd ) { var diff = stemdirection == NoteStemDirection.Down ? -1 : 1; var dir_scale = direction == FlagDirection.Left ? -1 : 1; var startX = x; // line / vpx -> px[y] / px[x] // multiply by (px/line) / (px/vpx) if (side == NoteStemSide.Left) { startX -= settings.NoteHeadRadius; } else if (side == NoteStemSide.Right) { startX += settings.NoteHeadRadius; } if (past2nd) { if (side == NoteStemSide.Left) { length += settings.NoteHeadRadius / width; } else if (side == NoteStemSide.Right) { length -= settings.NoteHeadRadius / width; } } if (flags_tied > 0) { for (int i = 0; i < flags_tied + flags_free; i++) { gfx.DrawLine( new Pen(color, 5.0f), startX, y_start + diff * i * settings.LinesBetweenFlags * settings.PixelsPerLine, x + length * dir_scale * width, y_start + diff * i * settings.LinesBetweenFlags * settings.PixelsPerLine + 0.5f * (slope * settings.PixelsPerLine) * ((startX - (x + length * dir_scale * width)) / width) ); if (i == flags_free && past2nd) { if (chord.LastLengthClass < chord.Length.Length) { length /= 2f; } } } } else if (flags_free > 0) { for (int i = 0; i < flags_free; i++) { gfx.DrawLine( new Pen(color, 5.0f), startX, y_start + diff * i * settings.LinesBetweenFlags * settings.PixelsPerLine, startX + diff * 15, y_start + diff * i * settings.LinesBetweenFlags * settings.PixelsPerLine + diff * 15 ); } } }
protected abstract void Render(Graphics gfx, SheetMusicRenderSettings settings, int width);
protected override void Render(Graphics gfx, SheetMusicRenderSettings settings, int width) { //TODO: render }
public override float MinWidth(SheetMusicRenderSettings settings) => layoutmeasure.ScaleX * settings.PixelsPerX * settings.PixelsScale + 2 * Margin;