Ejemplo n.º 1
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
                );
        }
Ejemplo n.º 2
0
        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
                        );
                }
            }
        }
Ejemplo n.º 3
0
        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);
        }