Пример #1
0
 public void DrawPercussionClef(Clef element, ScoreRendererBase renderer)
 {
     renderer.DrawLine(new Point(element.TextBlockLocation.X + 10, scoreService.CurrentLinePositions[1]),
                       new Point(element.TextBlockLocation.X + 10, scoreService.CurrentLinePositions[3]), new Pen(element.CoalesceColor(renderer), 3), element);
     renderer.DrawLine(new Point(element.TextBlockLocation.X + 15, scoreService.CurrentLinePositions[1]),
                       new Point(element.TextBlockLocation.X + 15, scoreService.CurrentLinePositions[3]), new Pen(element.CoalesceColor(renderer), 3), element);
 }
Пример #2
0
        private void DrawLyrics(ScoreRendererBase renderer, Note element)
        {
            double versePositionY = scoreService.CurrentLinePositions[4] + 10;                //Default value if default-y is not set

            foreach (Lyrics lyrics in element.Lyrics)
            {
                var textPosition = lyrics.DefaultYPosition.HasValue ?
                                   scoreService.CurrentLinePositions[0] - renderer.TenthsToPixels(lyrics.DefaultYPosition.Value) :
                                   versePositionY;

                StringBuilder sBuilder = new StringBuilder();
                sBuilder.Append(lyrics.Text);

                //TODO: Dodać do kalkulacji wyliczoną szerokość stringa w poprzednim lyricu i odkomentować :)
                //A, i jeszcze wtedy wywalić warunek na middleDistance.
                //double middleDistanceBetweenTwoLyrics = (scoreService.CursorPositionX - renderer.State.LastNoteEndXPosition) / 2.0d;
                // double hyphenXPosition = scoreService.CursorPositionX - middleDistanceBetweenTwoLyrics;
                //if ((lyrics.Type == SyllableType.Middle || lyrics.Type == SyllableType.End) && middleDistanceBetweenTwoLyrics > 20)
                //{
                //    renderer.DrawString("-", FontStyles.LyricsFont, hyphenXPosition, textPositionY, element);
                //}
                //else
                if (lyrics.Type == SyllableType.Begin || lyrics.Type == SyllableType.Middle)
                {
                    sBuilder.Append("-");
                }

                renderer.DrawString(sBuilder.ToString(), MusicFontStyles.LyricsFont, scoreService.CursorPositionX, textPosition, lyrics);

                if (!lyrics.DefaultYPosition.HasValue)
                {
                    versePositionY += 12;                                                    //Move down if default-y is not set
                }
            }
        }
        private void BeforeDrawRepeatSign(ScoreRendererBase renderer, Barline element, double?measureWidth)
        {
            if (element.RepeatSign == RepeatSignType.Forward && scoreService.CurrentStaff.Elements.IndexOf(element) > 0)
            {
                if (!renderer.IsSMuFLFont)
                {
                    scoreService.CursorPositionX -= 8;   //TODO: Temporary workaround!!
                }
                else if (!renderer.CanDrawCharacterInBounds)
                {
                    scoreService.CursorPositionX -= renderer.LinespacesToPixels(1);
                }
            }

            if (renderer.Settings.IgnoreCustomElementPositions || !measureWidth.HasValue)
            {
                scoreService.CursorPositionX += 2 * (element.RepeatSign == RepeatSignType.Backward ? 1 : -1);
            }
            if (element.Location == HorizontalPlacement.Right)
            {
                measurementService.LastMeasurePositionX = scoreService.CursorPositionX;
            }

            if (scoreService.CurrentStaffNo > 1 && element.RenderedXPositionForFirstStaffInMultiStaffPart > 0)
            {
                scoreService.CursorPositionX = element.RenderedXPositionForFirstStaffInMultiStaffPart;
            }
        }
Пример #4
0
 private void DrawTies(ScoreRendererBase renderer, Note element, double notePositionY)
 {
     if (element.TieType == NoteTieType.Start)
     {
         measurementService.TieStartPoint = new Point(scoreService.CursorPositionX, notePositionY);
     }
     else if (element.TieType != NoteTieType.None)             //Stop or StopAndStartAnother / Stop lub StopAndStartAnother
     {
         double arcWidth  = scoreService.CursorPositionX - measurementService.TieStartPoint.X - 12;
         double arcHeight = arcWidth * 0.7d;
         if (element.StemDirection == VerticalDirection.Down)
         {
             renderer.DrawArc(new Rectangle(measurementService.TieStartPoint.X + 16, measurementService.TieStartPoint.Y + 22,
                                            arcWidth, arcHeight), 180, 180, new Pen(renderer.CoalesceColor(element), 1.5), element);
         }
         else if (element.StemDirection == VerticalDirection.Up)
         {
             renderer.DrawArc(new Rectangle(measurementService.TieStartPoint.X + 16, measurementService.TieStartPoint.Y + 22,
                                            arcWidth, arcHeight), 0, 180, new Pen(renderer.CoalesceColor(element), 1.5), element);
         }
         if (element.TieType == NoteTieType.StopAndStartAnother)
         {
             measurementService.TieStartPoint = new Point(scoreService.CursorPositionX + 2, notePositionY);
         }
     }
 }
        private void DrawTiesInternal(ScoreRendererBase renderer, double arcStartX, double arcStartY, double arcEndY, double arcWidth, double arcHeight, int modifierY, Note element, Pen tiePen, double tieMidpointThickness)
        {
            var gap = tieMidpointThickness - tiePen.Thickness;

            renderer.DrawBezier(
                new Point(arcStartX, arcStartY),
                new Point(arcStartX + 0.25 * arcWidth, arcStartY + arcHeight * modifierY),
                new Point(arcStartX + 0.75 * arcWidth, arcStartY + arcHeight * modifierY),
                new Point(arcStartX + arcWidth, arcEndY),
                tiePen,
                element);
            if (gap >= tiePen.Thickness)
            {
                renderer.DrawBezier(
                    new Point(arcStartX, arcStartY),
                    new Point(arcStartX + 0.25 * arcWidth, arcStartY + (arcHeight + tieMidpointThickness / 2) * modifierY),
                    new Point(arcStartX + 0.75 * arcWidth, arcStartY + (arcHeight + tieMidpointThickness / 2) * modifierY),
                    new Point(arcStartX + arcWidth, arcEndY),
                    tiePen,
                    element);
            }
            renderer.DrawBezier(
                new Point(arcStartX, arcStartY),
                new Point(arcStartX + 0.25 * arcWidth, arcStartY + (arcHeight + tieMidpointThickness) * modifierY),
                new Point(arcStartX + 0.75 * arcWidth, arcStartY + (arcHeight + tieMidpointThickness) * modifierY),
                new Point(arcStartX + arcWidth, arcEndY),
                tiePen,
                element);
        }
        private void DrawOrnaments(ScoreRendererBase renderer, Note element, double notePositionY, FontProfile fontProfile)
        {
            foreach (Ornament ornament in element.Ornaments)
            {
                double yPosition;
                if (ornament.DefaultYPosition.HasValue)
                {
                    var yShift = renderer.TenthsToPixels(ornament.DefaultYPosition.Value);
                    yPosition = scoreService.CurrentLinePositions[0] + yShift;
                }
                else
                {
                    yPosition = notePositionY + (ornament.Placement == VerticalPlacement.Above ? -20 : 20);
                }

                yPosition = CorrectOrnamentYPositionToAvoidIntersection(renderer, ornament.Placement, renderer.LinespacesToPixels(1), yPosition, element, notePositionY);

                Mordent mordent = ornament as Mordent;
                if (mordent != null)
                {
                    if (renderer.IsSMuFLFont)
                    {
                        renderer.DrawCharacter(mordent.GetCharacter(fontProfile.MusicFont),
                                               MusicFontStyles.MusicFont, scoreService.CursorPositionX - element.GetNoteheadWidthPx(renderer) / 2,
                                               yPosition, element);
                    }
                    else
                    {
                        renderer.DrawCharacter(fontProfile.MusicFont.MordentShort, MusicFontStyles.GraceNoteFont, scoreService.CursorPositionX, yPosition, element);
                        renderer.DrawCharacter(fontProfile.MusicFont.Mordent, MusicFontStyles.GraceNoteFont, scoreService.CursorPositionX + 5.5, yPosition, element);
                    }
                }
            }
        }
        private void DrawLedgerLines(ScoreRendererBase renderer, Note element, double notePositionY)
        {
            var ledgerLinePen = renderer.CreatePenFromDefaults(element, "legerLineThickness", s => s.DefaultStaffLineThickness);

            double startPositionX = scoreService.CursorPositionX - (renderer.IsSMuFLFont ? element.GetNoteheadWidthPx(renderer) * 0.5 : 0);
            double endPositionX   = scoreService.CursorPositionX + (renderer.IsSMuFLFont ? element.GetNoteheadWidthPx(renderer) * 1.5 : renderer.LinespacesToPixels(element.GetNoteheadWidthLs(renderer) * 2.2));

            if (notePositionY > scoreService.CurrentLinePositions[4] + renderer.Settings.LineSpacing / 2.0f)
            {
                for (double i = scoreService.CurrentLinePositions[4]; i < notePositionY - renderer.Settings.LineSpacing / 2.0f; i += renderer.Settings.LineSpacing)
                {
                    renderer.DrawLine(
                        new Point(startPositionX, i + renderer.Settings.LineSpacing),
                        new Point(endPositionX, i + renderer.Settings.LineSpacing), ledgerLinePen, element);
                }
            }
            if (notePositionY < scoreService.CurrentLinePositions[0] - renderer.Settings.LineSpacing / 2)
            {
                for (double i = scoreService.CurrentLinePositions[0]; i > notePositionY + renderer.Settings.LineSpacing / 2.0f; i -= renderer.Settings.LineSpacing)
                {
                    renderer.DrawLine(
                        new Point(startPositionX, i - renderer.Settings.LineSpacing),
                        new Point(endPositionX, i - renderer.Settings.LineSpacing), ledgerLinePen, element);
                }
            }
        }
        private void DrawRepeatSignAsText(ScoreRendererBase renderer, Barline element, double?measureWidth, double shiftX, FontProfile fontProfile)
        {
            var positionY = scoreService.CurrentLinePositions[renderer.IsSMuFLFont ? 4 : 2];

            renderer.DrawCharacter(element.GetCharacter(fontProfile.MusicFont), MusicFontStyles.StaffFont, scoreService.CursorPositionX + shiftX,
                                   positionY, element);
        }
Пример #9
0
        public override void Render(Clef element, ScoreRendererBase renderer, FontProfile fontProfile)
        {
            if (!(fontProfile.IsSMuFLFont))
            {
                var yPosition        = element.OctaveChange > 0 ? scoreService.CurrentLinePositions[0] - renderer.LinespacesToPixels(2) : scoreService.CurrentLinePositions[4] + renderer.LinespacesToPixels(3.5);
                var octaveChangeText = GetOctaveChangeNumberForPolihymniaFont(element.OctaveChange);
                renderer.DrawString(octaveChangeText, MusicFontStyles.DirectionFont, element.TextBlockLocation.X + 6, yPosition, element);
            }

            //Don't draw clef if it's current clef:
            if (!WasSystemChanged && element.TypeOfClef == scoreService.CurrentClef.TypeOfClef && element.Pitch == scoreService.CurrentClef.Pitch && element.Line == scoreService.CurrentClef.Line)
            {
                return;
            }

            element.TextBlockLocation = new Point(scoreService.CursorPositionX, scoreService.CurrentLinePositions[4] - (element.Line - 1) * renderer.Settings.LineSpacing);

            scoreService.CurrentClef = element;
            if (element.TypeOfClef == ClefType.Percussion)
            {
                DrawPercussionClef(element, renderer);
            }
            else
            {
                renderer.DrawCharacter(element.GetCharacter(fontProfile.MusicFont), MusicFontStyles.MusicFont, element.TextBlockLocation.X, element.TextBlockLocation.Y, element);
            }

            scoreService.CursorPositionX += 20;
        }
        /// <summary>
        /// Draw musical symbol
        /// </summary>
        /// <param name="element">Element to draw</param>
        /// <param name="renderer">Renderer</param>
        public override void Render(MusicalSymbol element, ScoreRendererBase renderer)
        {
            var performanceStopwatch = new Stopwatch();

            try
            {
                if (Debugger.IsAttached)
                {
                    performanceStopwatch.Start();
                }

                if (element.IsBreakpointSet)
                {
                    Debugger.Break();
                }
                var startPositionX = scoreService.CursorPositionX;
                Render((TElement)element, renderer, renderer.Settings?.MusicFontProfile);
                element.RenderedWidth = scoreService.CursorPositionX - startPositionX;
            }
            finally
            {
                if (Debugger.IsAttached)
                {
                    performanceStopwatch.Stop();
                    element.ActualRenderingTime = performanceStopwatch.Elapsed;
                }
            }
        }
Пример #11
0
        private void DrawFermataSign(ScoreRendererBase renderer, Note element, double notePositionY)
        {
            if (element.HasFermataSign)
            {
                double ferPos         = notePositionY - renderer.Settings.TextBlockHeight;
                string fermataVersion = renderer.Settings.CurrentFont.FermataUp;

                renderer.DrawString(fermataVersion, MusicFontStyles.MusicFont, scoreService.CursorPositionX, ferPos, element);
            }
        }
        private void DrawTrills(ScoreRendererBase renderer, Note element, double notePositionY, FontProfile fontProfile)
        {
            if (element.TrillMark != NoteTrillMark.None)
            {
                var    placement = element.TrillMark == NoteTrillMark.Above ? VerticalPlacement.Above : VerticalPlacement.Below;
                double trillPos  = CorrectOrnamentYPositionToAvoidIntersection(renderer, placement, renderer.LinespacesToPixels(2), notePositionY, element, notePositionY);

                renderer.DrawCharacter(fontProfile.MusicFont.Trill, MusicFontStyles.MusicFont, scoreService.CursorPositionX - 1, trillPos, element);
            }
        }
        private void DrawSlurs(ScoreRendererBase renderer, Note element, double notePositionY, FontProfile fontProfile)
        {
            if (!element.Slurs.Any())
            {
                return;
            }

            foreach (var slur in element.Slurs)
            {
                slurRenderStrategies.First(s => s.IsRelevant(element, slur)).Draw(renderer, slur, element, notePositionY);
            }
        }
 private void DrawDots(ScoreRendererBase renderer, Note element, double notePositionY, FontProfile fontProfile)
 {
     if (element.NumberOfDots > 0)
     {
         scoreService.CursorPositionX += 16;
     }
     for (int i = 0; i < element.NumberOfDots; i++)
     {
         renderer.DrawCharacter(fontProfile.MusicFont.AugmentationDot, MusicFontStyles.MusicFont, scoreService.CursorPositionX, notePositionY, element);
         scoreService.CursorPositionX += 6;
     }
 }
Пример #15
0
        public override void Render(Key element, ScoreRendererBase renderer)
        {
            scoreService.CurrentKey = element;
            double flatOrSharpPositionY = 0;
            bool   jumpFourth           = false;
            int    jumpDirection        = 1;
            int    octaveShiftSharp     = 0; //In G clef sharps (not flats) should be written an octave higher / W kluczu g krzyżyki (bemole nie) powinny być zapisywane o oktawę wyżej

            if (scoreService.CurrentClef.TypeOfClef == ClefType.GClef)
            {
                octaveShiftSharp = 1;
            }
            int octaveShiftFlat = 0;

            if (scoreService.CurrentClef.TypeOfClef == ClefType.FClef)
            {
                octaveShiftFlat = -1;
            }
            if (scoreService.CurrentKey.Fifths > 0)
            {
                flatOrSharpPositionY = scoreService.CurrentClef.TextBlockLocation.Y
                                       + Pitch.StepDistance(scoreService.CurrentClef,
                                                            Pitch.FromStep(Step.F, scoreService.CurrentClef.Pitch.Octave + octaveShiftSharp))
                                       * (renderer.Settings.LineSpacing / 2);
                jumpFourth    = true;
                jumpDirection = 1;
            }
            else if (scoreService.CurrentKey.Fifths < 0)
            {
                flatOrSharpPositionY = scoreService.CurrentClef.TextBlockLocation.Y +
                                       Pitch.StepDistance(scoreService.CurrentClef,
                                                          Pitch.FromStep(Step.B, scoreService.CurrentClef.Pitch.Octave + octaveShiftFlat))
                                       * (renderer.Settings.LineSpacing / 2);
                jumpFourth    = true;
                jumpDirection = -1;
            }
            for (int i = 0; i < Math.Abs(scoreService.CurrentKey.Fifths); i++)
            {
                renderer.DrawString(element.MusicalCharacter, MusicFontStyles.MusicFont, scoreService.CursorPositionX, flatOrSharpPositionY, element);
                if (jumpFourth)
                {
                    flatOrSharpPositionY += 3 * 3 * jumpDirection;
                }
                else
                {
                    flatOrSharpPositionY += 3 * 4 * jumpDirection;
                }
                jumpFourth     = !jumpFourth;
                jumpDirection *= -1;
                scoreService.CursorPositionX += 8;
            }
            scoreService.CursorPositionX += 10;
        }
        private void DrawRepeatSignSMuFL(ScoreRendererBase renderer, Barline element, double?measureWidth, FontProfile fontProfile)
        {
            var bounds = element.GetSMuFLBoundingBoxPx(fontProfile.SMuFLMetadata, renderer.Settings);
            var shiftX = element.RepeatSign == RepeatSignType.Forward ? bounds.BBoxSw[0] : bounds.BBoxNe[0];

            renderer.DrawCharacterInBounds(
                element.GetCharacter(fontProfile.MusicFont),
                MusicFontStyles.MusicFont,
                new Point(scoreService.CursorPositionX - shiftX, scoreService.CurrentLinePositions[0]),
                new Size(bounds.BBoxNe[0] - bounds.BBoxSw[0], bounds.BBoxNe[1] - bounds.BBoxSw[1]),
                element);
        }
Пример #17
0
        private void DrawFlagsAndTupletMarks(ScoreRendererBase renderer, Note element)
        {
            int beamOffset = 0;

            //Powiększ listę poprzednich pozycji stemów jeśli aktualna liczba belek jest większa
            //Extend the list of previous stem positions if current number of beams is greater than the list size
            if (beamingService.PreviousStemEndPositionsY.Count < element.BeamList.Count)
            {
                int tmpCount = beamingService.PreviousStemEndPositionsY.Count;
                for (int i = 0; i < element.BeamList.Count - tmpCount; i++)
                {
                    beamingService.PreviousStemEndPositionsY.Add(new int());
                }
            }
            if (beamingService.PreviousStemPositionsX.Count < element.BeamList.Count)
            {
                int tmpCount = beamingService.PreviousStemPositionsX.Count;
                for (int i = 0; i < element.BeamList.Count - tmpCount; i++)
                {
                    beamingService.PreviousStemPositionsX.Add(new int());
                }
            }
            int beamLoop = 0;

            foreach (NoteBeamType beam in element.BeamList)
            {
                var beamSpaceDirection = element.StemDirection == VerticalDirection.Up ? 1 : -1;
                if (beam == NoteBeamType.Start)
                {
                    if (beamLoop == 0)
                    {
                        beamingService.PreviousStemEndPositionsY[beamLoop] = beamingService.CurrentStemEndPositionY;
                    }
                    beamingService.PreviousStemPositionsX[beamLoop] = beamingService.CurrentStemPositionX;
                }
                else if (beam == NoteBeamType.End)
                {
                    //Draw tuplet mark / Rysuj oznaczenie trioli:
                    if (element.Tuplet == TupletType.Stop && measurementService.TupletState != null)
                    {
                        Beams.TupletMark(measurementService, scoreService, renderer, element, beamLoop);
                        measurementService.TupletState = null;
                    }
                }
                else if ((beam == NoteBeamType.Single) && (!element.IsUpperMemberOfChord))
                {
                    Beams.Flag(beamingService, measurementService, scoreService, renderer, element, beamSpaceDirection, beamLoop, beamOffset);
                }

                beamOffset += 4;
                beamLoop++;
            }
        }
Пример #18
0
 private void DrawDots(ScoreRendererBase renderer, Note element, double notePositionY)
 {
     if (element.NumberOfDots > 0)
     {
         scoreService.CursorPositionX += 16;
     }
     for (int i = 0; i < element.NumberOfDots; i++)
     {
         renderer.DrawString(renderer.Settings.CurrentFont.Dot, MusicFontStyles.MusicFont, scoreService.CursorPositionX, notePositionY, element);
         scoreService.CursorPositionX += 6;
     }
 }
Пример #19
0
 private void DrawOrnaments(ScoreRendererBase renderer, Note element, double notePositionY)
 {
     foreach (Ornament ornament in element.Ornaments)
     {
         double  yPositionShift = ornament.DefaultYPosition.HasValue ? renderer.TenthsToPixels(ornament.DefaultYPosition.Value) * -1 : (ornament.Placement == VerticalPlacement.Above ? -20 : 20);
         Mordent mordent        = ornament as Mordent;
         if (mordent != null)
         {
             renderer.DrawString(renderer.Settings.CurrentFont.MordentShort, MusicFontStyles.GraceNoteFont, scoreService.CursorPositionX - 2, notePositionY + yPositionShift, element);
             renderer.DrawString(renderer.Settings.CurrentFont.Mordent, MusicFontStyles.GraceNoteFont, scoreService.CursorPositionX + 3.5, notePositionY + yPositionShift, element);
         }
     }
 }
Пример #20
0
        private void DrawNote(ScoreRendererBase renderer, Note element, double notePositionY)
        {
            if (element.IsGraceNote || element.IsCueNote)
            {
                renderer.DrawString(element.MusicalCharacter, MusicFontStyles.GraceNoteFont, scoreService.CursorPositionX + 1, notePositionY + 7, element);
            }
            else
            {
                renderer.DrawString(element.MusicalCharacter, MusicFontStyles.MusicFont, scoreService.CursorPositionX, notePositionY, element);
            }

            measurementService.LastNotePositionX = scoreService.CursorPositionX;
            element.TextBlockLocation            = new Point(scoreService.CursorPositionX, notePositionY);
        }
        private double GetNotePositionForCalculatingStemEnd(ScoreRendererBase renderer, Note element, double notePositionY, Note[] chord)
        {
            if (chord.Length > 1)
            {
                if (element.StemDirection == VerticalDirection.Up)
                {
                    return(CalculateNotePositionY(chord.Last(), renderer));
                }
                else
                {
                    return(notePositionY);
                }
            }
            var notesUnderBeam = GetNotesUnderBeam(element, scoreService.CurrentStaff);

            if (notesUnderBeam.Length > 2)
            {
                var pitchDifferenceBetweenBounds = (notesUnderBeam.Last().MidiPitch - notesUnderBeam.First().MidiPitch);
                if (pitchDifferenceBetweenBounds > 12)
                {
                    pitchDifferenceBetweenBounds = 12;
                }
                if (pitchDifferenceBetweenBounds < -12)
                {
                    pitchDifferenceBetweenBounds = -12;
                }

                var isFirstNote = element == notesUnderBeam.First();
                if (element.StemDirection == VerticalDirection.Down)
                {
                    var lowestPitch = notesUnderBeam.Min(n => n.MidiPitch);
                    var lowerNote   = notesUnderBeam.FirstOrDefault(n => n.MidiPitch < element.MidiPitch && n.MidiPitch == lowestPitch);
                    if (lowerNote != null)
                    {
                        return(CalculateNotePositionY(lowerNote, renderer) + pitchDifferenceBetweenBounds * (isFirstNote ? 1 : -1));
                    }
                }
                if (element.StemDirection == VerticalDirection.Up)
                {
                    var highestPitch = notesUnderBeam.Max(n => n.MidiPitch);
                    var higherNote   = notesUnderBeam.FirstOrDefault(n => n.MidiPitch > element.MidiPitch && n.MidiPitch == highestPitch);
                    if (higherNote != null)
                    {
                        return(CalculateNotePositionY(higherNote, renderer) + pitchDifferenceBetweenBounds * (isFirstNote ? 1 : -1));
                    }
                }
            }
            return(notePositionY);
        }
 private double GetNotePositionForCalculatingStemStart(ScoreRendererBase renderer, Note element, double notePositionY, Note[] chord)
 {
     if (chord.Length == 1 && element == chord[0])
     {
         return(notePositionY);
     }
     if (element.StemDirection == VerticalDirection.Down)
     {
         return(CalculateNotePositionY(chord.Last(), renderer));
     }
     else
     {
         return(notePositionY);
     }
 }
        private void MakeSpaceForAccidentals(ScoreRendererBase renderer, Note element, Note[] chord)
        {
            if (element.DefaultXPosition.HasValue && !renderer.Settings.IgnoreCustomElementPositions)
            {
                return;
            }
            if (element.IsUpperMemberOfChord)
            {
                return;
            }

            var maxSpaceNeeded = chord.Max(n => CalculateSpaceForAccidentals(n, scoreService.CurrentKey));

            scoreService.CursorPositionX += maxSpaceNeeded;
        }
        public double?GetCursorPositionForCurrentBarline(ScoreRendererBase renderer)
        {
            Staff staff = scoreService.CurrentStaff;

            if (staff.Measures.Count < scoreService.CurrentMeasureNo)
            {
                return(null);
            }
            double?width = staff.Measures[scoreService.CurrentMeasureNo - 1].Width;

            if (!width.HasValue)
            {
                return(null);
            }
            return(measurementService.LastMeasurePositionX + width * renderer.Settings.CustomElementPositionRatio);
        }
Пример #25
0
        private void DrawSlurs(ScoreRendererBase renderer, Note element, double notePositionY)
        {
            if (element.Slur == null)
            {
                return;
            }
            VerticalPlacement slurPlacement;

            if (element.Slur.Placement.HasValue)
            {
                slurPlacement = element.Slur.Placement.Value;
            }
            else
            {
                slurPlacement = element.StemDirection == VerticalDirection.Up ? VerticalPlacement.Below : VerticalPlacement.Above;
            }

            if (element.Slur.Type == NoteSlurType.Start)
            {
                slurStartPlacement = slurPlacement;
                if (slurPlacement == VerticalPlacement.Above)
                {
                    measurementService.SlurStartPoint = new Point(scoreService.CursorPositionX, element.StemDirection == VerticalDirection.Down ? notePositionY : notePositionY + element.StemDefaultY);
                }
                else
                {
                    measurementService.SlurStartPoint = new Point(scoreService.CursorPositionX, notePositionY);
                }
            }
            else if (element.Slur.Type == NoteSlurType.Stop)
            {
                if (slurStartPlacement == VerticalPlacement.Above)
                {
                    renderer.DrawBezier(measurementService.SlurStartPoint.X + 10, measurementService.SlurStartPoint.Y + 18,
                                        measurementService.SlurStartPoint.X + 12, measurementService.SlurStartPoint.Y + 9,
                                        scoreService.CursorPositionX + 8, (element.StemDirection == VerticalDirection.Up ? element.StemDefaultY + scoreService.Systems.Take(scoreService.CurrentSystemNo - 1).Sum(s => s.Height) : notePositionY + 9),
                                        scoreService.CursorPositionX + 10, (element.StemDirection == VerticalDirection.Up ? element.StemDefaultY + scoreService.Systems.Take(scoreService.CurrentSystemNo - 1).Sum(s => s.Height) + 9 : notePositionY + 18), element);
                }
                else if (slurStartPlacement == VerticalPlacement.Below)
                {
                    renderer.DrawBezier(measurementService.SlurStartPoint.X + 10, measurementService.SlurStartPoint.Y + 30,
                                        measurementService.SlurStartPoint.X + 12, measurementService.SlurStartPoint.Y + 44,
                                        scoreService.CursorPositionX + 8, notePositionY + 44,
                                        scoreService.CursorPositionX + 10, notePositionY + 30, element);
                }
            }
        }
        private void DrawFermataSign(ScoreRendererBase renderer, Note element, double notePositionY, FontProfile fontProfile)
        {
            if (element.HasFermataSign)
            {
                double ferPosY = scoreService.CurrentLinePositions[0] - renderer.LinespacesToPixels(2.5);
                while (ferPosY > notePositionY || ferPosY > element.StemEndLocation.Y)
                {
                    ferPosY -= renderer.LinespacesToPixels(0.5);
                    if (ferPosY < scoreService.CurrentLinePositions[0] - renderer.LinespacesToPixels(4))
                    {
                        break;
                    }
                }
                char fermataVersion = fontProfile.MusicFont.FermataUp;

                renderer.DrawCharacter(fermataVersion, MusicFontStyles.MusicFont, scoreService.CursorPositionX, ferPosY, element);
            }
        }
        private void DrawTies(ScoreRendererBase renderer, Note element, double notePositionY)
        {
            if (element.TieType == NoteTieType.Start)
            {
                measurementService.TieStartSystem  = element.Measure?.System;
                measurementService.TieStartPoint   = new Point(scoreService.CursorPositionX + GetNoteheadWidthPx(element, renderer) / 2, notePositionY);
                measurementService.TieStartElement = element;
            }
            else if (element.TieType != NoteTieType.None) //Stop or StopAndStartAnother / Stop lub StopAndStartAnother
            {
                var tieEndpointThickness = renderer.GetEngravingDefault("tieEndpointThickness") ?? 1;
                var tieMidpointThickness = renderer.GetEngravingDefault("tieMidpointThickness") ?? 2;
                var tiePen = new Pen(element.CoalesceColor(renderer), tieEndpointThickness);

                double arcHeight = renderer.LinespacesToPixels(2);
                var    modifierY = element.StemDirection == VerticalDirection.Down ? -1 : 1;
                var    arcStartX = measurementService.TieStartPoint.X;// - element.GetNoteheadWidthPx(renderer) / 2;
                var    arcStartY = measurementService.TieStartPoint.Y + renderer.LinespacesToPixels(1) * modifierY;

                if (renderer.Settings.RenderingMode == ScoreRenderingModes.Panorama || element.Measure?.System == measurementService.TieStartSystem)
                {
                    double arcWidth = scoreService.CursorPositionX - measurementService.TieStartPoint.X + element.GetNoteheadWidthPx(renderer) / 2 - 2; //-2 to modyfikator, żeby łuki się nie krzyżowały
                    DrawTiesInternal(renderer, arcStartX, arcStartY, arcStartY, arcWidth, arcHeight, modifierY, element, tiePen, tieMidpointThickness);
                }
                else
                {
                    //Draw ties at system breaks
                    var firstHalfOfArcWidth = (measurementService.TieStartElement.Measure?.BarlineLocationX ?? measurementService.TieStartSystem.Width)
                                              - measurementService.TieStartElement.TextBlockLocation.X - measurementService.TieStartElement.GetNoteheadWidthPx(renderer) / 2;
                    DrawTiesInternal(renderer, arcStartX, arcStartY, arcStartY + arcHeight * modifierY, firstHalfOfArcWidth, arcHeight, modifierY, measurementService.TieStartElement, tiePen, tieMidpointThickness);

                    var secondHalfOfArcStartX = element.TextBlockLocation.X - 20;
                    var arcStartYSecondHalf   = element.TextBlockLocation.Y + renderer.LinespacesToPixels(1) * modifierY;
                    DrawTiesInternal(renderer, secondHalfOfArcStartX, arcStartYSecondHalf, arcStartYSecondHalf,
                                     element.TextBlockLocation.X - secondHalfOfArcStartX, arcHeight, modifierY, element, tiePen, tieMidpointThickness);
                }

                if (element.TieType == NoteTieType.StopAndStartAnother)
                {
                    measurementService.TieStartPoint = new Point(scoreService.CursorPositionX + 2, notePositionY);
                }
            }
        }
Пример #28
0
 private void DrawTrills(ScoreRendererBase renderer, Note element, double notePositionY)
 {
     if (element.TrillMark != NoteTrillMark.None)
     {
         double trillPos = notePositionY - 1;
         if (element.TrillMark == NoteTrillMark.Above)
         {
             trillPos = notePositionY - 1;
             if (trillPos > scoreService.CurrentLinePositions[0] - renderer.Settings.TextBlockHeight)
             {
                 trillPos = scoreService.CurrentLinePositions[0] - renderer.Settings.TextBlockHeight - 1.0f;
             }
         }
         else if (element.TrillMark == NoteTrillMark.Below)
         {
             trillPos = notePositionY + 10;
         }
         renderer.DrawString(renderer.Settings.CurrentFont.Trill, MusicFontStyles.MusicFont, scoreService.CursorPositionX + 6, trillPos, element);
     }
 }
Пример #29
0
        private void DrawTremolos(ScoreRendererBase renderer, Note element, double notePositionY)
        {
            double currentTremoloPos = notePositionY + 18;

            for (int j = 0; j < element.TremoloLevel; j++)
            {
                if (element.StemDirection == VerticalDirection.Up)
                {
                    currentTremoloPos -= 4;
                    renderer.DrawLine(scoreService.CursorPositionX + 9, currentTremoloPos + 1, scoreService.CursorPositionX + 16, currentTremoloPos - 1, element);
                    renderer.DrawLine(scoreService.CursorPositionX + 9, currentTremoloPos + 2, scoreService.CursorPositionX + 16, currentTremoloPos, element);
                }
                else
                {
                    currentTremoloPos += 4;
                    renderer.DrawLine(scoreService.CursorPositionX + 3, currentTremoloPos + 11 + 1, scoreService.CursorPositionX + 11, currentTremoloPos + 11 - 1, element);
                    renderer.DrawLine(scoreService.CursorPositionX + 3, currentTremoloPos + 11 + 2, scoreService.CursorPositionX + 11, currentTremoloPos + 11, element);
                }
            }
        }
        private void DrawAccidentals(ScoreRendererBase renderer, Note element, double notePositionY, FontProfile fontProfile)
        {
            int numberOfSingleAccidentals = Math.Abs(element.Alter) % 2;
            int numberOfDoubleAccidentals = Convert.ToInt32(Math.Floor((double)(Math.Abs(element.Alter) / 2)));

            if (element.Alter - scoreService.CurrentKey.StepToAlter(element.Step) - alterationService.Get(element.Step) > 0)
            {
                alterationService.Set(element.Step, element.Alter - scoreService.CurrentKey.StepToAlter(element.Step));
                double accPlacement = scoreService.CursorPositionX - 8 * numberOfSingleAccidentals - 6 * numberOfDoubleAccidentals;
                for (int i = 0; i < numberOfSingleAccidentals; i++)
                {
                    renderer.DrawCharacter(fontProfile.MusicFont.Sharp, MusicFontStyles.MusicFont, accPlacement, notePositionY, element);
                    accPlacement += 9;
                }
                for (int i = 0; i < numberOfDoubleAccidentals; i++)
                {
                    renderer.DrawCharacter(fontProfile.MusicFont.DoubleSharp, MusicFontStyles.MusicFont, accPlacement, notePositionY, element);
                    accPlacement += 9;
                }
            }
            else if (element.Alter - scoreService.CurrentKey.StepToAlter(element.Step) - alterationService.Get(element.Step) < 0)
            {
                alterationService.Set(element.Step, element.Alter - scoreService.CurrentKey.StepToAlter(element.Step));
                double accPlacement = scoreService.CursorPositionX - 8 * numberOfSingleAccidentals -
                                      6 * numberOfDoubleAccidentals;
                for (int i = 0; i < numberOfSingleAccidentals; i++)
                {
                    renderer.DrawCharacter(fontProfile.MusicFont.Flat, MusicFontStyles.MusicFont, accPlacement, notePositionY, element);
                    accPlacement += 9;
                }
                for (int i = 0; i < numberOfDoubleAccidentals; i++)
                {
                    renderer.DrawCharacter(fontProfile.MusicFont.DoubleFlat, MusicFontStyles.MusicFont, accPlacement, notePositionY, element);
                    accPlacement += 9;
                }
            }
            if (element.HasNatural == true)
            {
                renderer.DrawCharacter(fontProfile.MusicFont.Natural, MusicFontStyles.MusicFont, scoreService.CursorPositionX - 10, notePositionY, element);
            }
        }