Esempio n. 1
0
 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)
         );
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
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)
     );
Esempio n. 4
0
        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
                );
        }
Esempio n. 5
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);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        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);
            }
        }
        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);
        }