Exemplo n.º 1
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);
        }