Beispiel #1
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;
        }
Beispiel #2
0
 public void SetFontFromPath(string fontPath, FontProfile musicFontProfile)
 {
     rendererSettings.MusicFontProfile = musicFontProfile;
     foreach (var size in musicFontProfile.FontSizes)
     {
         rendererSettings.SetFontFromPath(size.Key, fontPath, (float)size.Value);
     }
 }
 public void SetMusicFont(FontProfile musicFontProfile, string fontName, params string[] fontPaths)
 {
     SetMusicFontProfile(musicFontProfile);
     foreach (var fontSize in musicFontProfile.FontSizes)
     {
         SetFont(fontSize.Key, fontName, fontSize.Value, fontPaths);
     }
 }
Beispiel #4
0
 public void SetFont(FontFamily family, FontProfile musicFontProfile)
 {
     rendererSettings.MusicFontProfile = musicFontProfile;
     foreach (var size in musicFontProfile.FontSizes)
     {
         rendererSettings.SetFont(size.Key, family, size.Value);
     }
 }
        /// <summary>
        /// Renders a Direction using specific score renderer.
        /// </summary>
        /// <param name="element">Direction</param>
        /// <param name="renderer">Score renderer</param>
        public override void Render(Direction element, ScoreRendererBase renderer, FontProfile fontProfile)
        {
            //Performance directions / Wskazówki wykonawcze:
            double dirPositionY = 0;

            if (element.Placement == DirectionPlacementType.Custom)
            {
                dirPositionY = scoreService.CurrentStaffTop - renderer.TenthsToPixels(element.DefaultYPosition.Value);
            }
            else if (element.Placement == DirectionPlacementType.Above)
            {
                dirPositionY = 0;
            }
            else if (element.Placement == DirectionPlacementType.Below)
            {
                dirPositionY = 50;
            }

            var metronomeDirection = element as MetronomeDirection;

            if (metronomeDirection != null)
            {
                var note = new Note(metronomeDirection.Tempo.BeatUnit);
                renderer.DrawCharacter(note.GetCharacter(fontProfile.MusicFont), MusicFontStyles.GraceNoteFont, scoreService.CursorPositionX, dirPositionY - 8, element);
                if (metronomeDirection.Tempo.BeatUnit.Denominator > 1)
                {
                    renderer.DrawLine(scoreService.CursorPositionX + 10, dirPositionY + 9, scoreService.CursorPositionX + 10, dirPositionY - 2, metronomeDirection);
                    if (metronomeDirection.Tempo.BeatUnit.Denominator > 4)
                    {
                        renderer.DrawCharacter(note.GetNoteFlagCharacter(fontProfile.MusicFont, false), MusicFontStyles.GraceNoteFont, new Point(scoreService.CursorPositionX + 6, dirPositionY - 24), element);
                    }
                }
                renderer.DrawString($" = {metronomeDirection.Tempo.BeatsPerMinute}", MusicFontStyles.DirectionFont, scoreService.CursorPositionX + 12, dirPositionY, element);
                return;
            }


            renderer.DrawString(element.Text, MusicFontStyles.DirectionFont, scoreService.CursorPositionX, dirPositionY, element);
        }
        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);
        }
        public override void Render(Barline element, ScoreRendererBase renderer, FontProfile fontProfile)
        {
            var partGroup = element.Staff?.Part?.Group;
            var doNotDraw = partGroup != null && partGroup.GroupBarline == GroupBarlineType.Mensurstrich;

            var lightPen   = new Pen(element.CoalesceColor(renderer), 1);
            var thickPen   = new Pen(element.CoalesceColor(renderer), 3);
            var barlinePen = renderer.CreatePenFromDefaults(element, "thinBarlineThickness", s => s.DefaultBarlineThickness);

            if (measurementService.LastNoteInMeasureEndXPosition > scoreService.CursorPositionX)
            {
                scoreService.CursorPositionX = measurementService.LastNoteInMeasureEndXPosition;
            }

            double?measureWidth = GetCursorPositionForCurrentBarline(renderer);

            if (!renderer.Settings.IgnoreCustomElementPositions && measureWidth.HasValue && element.Location == HorizontalPlacement.Right)
            {
                scoreService.CursorPositionX = measureWidth.Value;
            }
            else if (element.RepeatSign == RepeatSignType.None)
            {
                //If measure width is not set, get barline location from the first staff:
                if (scoreService.CurrentStaff != scoreService.CurrentScore.FirstStaff)
                {
                    var correspondingMeasure = scoreService.GetCorrespondingMeasure(scoreService.CurrentMeasure, scoreService.CurrentScore.FirstStaff);
                    if (correspondingMeasure != null)
                    {
                        scoreService.CursorPositionX = correspondingMeasure.BarlineLocationX - 16;
                    }
                }
            }

            if (element.RepeatSign == RepeatSignType.None)
            {
                if (renderer.Settings.IgnoreCustomElementPositions || !measureWidth.HasValue)
                {
                    scoreService.CursorPositionX += 16;
                }
                if (element.Location == HorizontalPlacement.Right)
                {
                    measurementService.LastMeasurePositionX = scoreService.CursorPositionX;
                }
                if (!doNotDraw)
                {
                    if (element.Style == BarlineStyle.LightHeavy)
                    {
                        renderer.DrawLine(new Point(scoreService.CursorPositionX - 6, scoreService.CurrentLinePositions[4]),
                                          new Point(scoreService.CursorPositionX - 6, scoreService.CurrentLinePositions[0]), lightPen, element);
                        renderer.DrawLine(new Point(scoreService.CursorPositionX - 1.5, scoreService.CurrentLinePositions[4]),
                                          new Point(scoreService.CursorPositionX - 1.5, scoreService.CurrentLinePositions[0]), thickPen, element);
                    }
                    else if (element.Style == BarlineStyle.Dashed)
                    {
                        var barlineHeight    = Math.Abs(scoreService.CurrentLinePositions[4] - scoreService.CurrentLinePositions[0]);
                        var currentPositionY = scoreService.CurrentLinePositions[0];
                        var numberOfSegments = 6;
                        var dy = barlineHeight / numberOfSegments;
                        for (int i = 0; i < numberOfSegments; i++)
                        {
                            if (i % 2 == 0)
                            {
                                renderer.DrawLine(new Point(scoreService.CursorPositionX, currentPositionY),
                                                  new Point(scoreService.CursorPositionX, currentPositionY + dy), barlinePen, element);
                            }
                            currentPositionY += dy;
                        }
                    }
                    else if (element.Style != BarlineStyle.None)
                    {
                        renderer.DrawLine(new Point(scoreService.CursorPositionX, scoreService.CurrentLinePositions[4]),
                                          new Point(scoreService.CursorPositionX, scoreService.CurrentLinePositions[0]), lightPen, element);
                    }

                    element.ActualRenderedBounds = new Quadrangle(
                        new Point(scoreService.CursorPositionX, scoreService.CurrentLinePositions[0]),
                        new Point(scoreService.CursorPositionX, scoreService.CurrentLinePositions[0]),
                        new Point(scoreService.CursorPositionX, scoreService.CurrentLinePositions[4]),
                        new Point(scoreService.CursorPositionX, scoreService.CurrentLinePositions[4]));
                }
                scoreService.CurrentMeasure.BarlineLocationX = scoreService.CursorPositionX;
                scoreService.CurrentMeasure.Barline          = element;
                if (!IsLastBarline(element) && (renderer.Settings.IgnoreCustomElementPositions || !measureWidth.HasValue))
                {
                    scoreService.CursorPositionX += 6;
                }
            }
            else if (element.RepeatSign == RepeatSignType.Forward)
            {
                BeforeDrawRepeatSign(renderer, element, measureWidth);

                //TODO: Usunąć warunek na HtmlScoreRendererSettings jak zaimplementuję w SVG DrawCharacterInBounds
                if (renderer.IsSMuFLFont && fontProfile.SMuFLMetadata != null && renderer.CanDrawCharacterInBounds)
                {
                    DrawRepeatSignSMuFL(renderer, element, measureWidth, fontProfile);
                }
                else
                {
                    DrawRepeatSignAsText(renderer, element, measureWidth, 4, fontProfile);
                }

                AfterDrawRepeatSign(renderer, element, measureWidth, 20);
            }
            else if (element.RepeatSign == RepeatSignType.Backward)
            {
                BeforeDrawRepeatSign(renderer, element, measureWidth);

                //TODO: Usunąć warunek na HtmlScoreRendererSettings jak zaimplementuję w SVG DrawCharacterInBounds
                if (renderer.IsSMuFLFont && fontProfile.SMuFLMetadata != null && renderer.CanDrawCharacterInBounds)
                {
                    DrawRepeatSignSMuFL(renderer, element, measureWidth, fontProfile);
                }
                else
                {
                    DrawRepeatSignAsText(renderer, element, measureWidth, -14.5, fontProfile);
                }

                AfterDrawRepeatSign(renderer, element, measureWidth, 6);
            }

            if (element.Location == HorizontalPlacement.Right)   //Start new measure only if it's right barline
            {
                alterationService.Reset();
                scoreService.BeginNewMeasure();
            }
        }
        /// <summary>
        /// Renders print suggestion with specific score renderer
        /// </summary>
        /// <param name="element"></param>
        /// <param name="renderer"></param>
        public override void Render(PrintSuggestion element, ScoreRendererBase renderer, FontProfile fontProfile)
        {
            if (element.IsSystemBreak && renderer.Settings.RenderingMode != ScoreRenderingModes.Panorama)
            {
                renderer.BreakSystem(renderer.TenthsToPixels(element.SystemDistance ?? scoreService.CurrentScore.DefaultPageSettings.DefaultSystemDistance ?? 0), element.IsPageBreak);

                var clefRenderStrategy = new ClefRenderStrategy(scoreService)
                {
                    WasSystemChanged = true
                };
                clefRenderStrategy.Render(scoreService.CurrentClef, renderer);

                var keyRenderStrategy = new KeyRenderStrategy(scoreService)
                {
                    IsVirtualKey = true
                };
                keyRenderStrategy.Render(scoreService.CurrentKey, renderer);

                //Time signature is not rendered in new line.

                //Render measure number:
                if (scoreService.CurrentStaff == scoreService.CurrentScore.FirstStaff)
                {
                    renderer.DrawString((scoreService.CurrentMeasureNo).ToString(), MusicFontStyles.LyricsFont,
                                        new Primitives.Point(0, scoreService.CurrentLinePositions[0] - renderer.LinespacesToPixels(2)), scoreService.CurrentStaff);
                }
            }

            //Issue #44: Jeśli jesteśmy w trybie panoramy, to trzeba uzupełnić line positions dla pozostałych systemów:
            if (renderer.Settings.RenderingMode == ScoreRenderingModes.Panorama)
            {
                var firstSystem = scoreService.Systems.First();
                foreach (var system in scoreService.Systems)
                {
                    system.BuildStaffFragments(firstSystem.LinePositions.ToDictionary(p => scoreService.CurrentScore.Staves[p.Key - 1], p => p.Value));
                }
            }
        }
        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);
        }
 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;
     }
 }
        public override void Render(Key element, ScoreRendererBase renderer, FontProfile fontProfile)
        {
            if (element.Fifths != 0 && element.Measure.Elements.FirstOrDefault() == element)
            {
                scoreService.CursorPositionX += renderer.LinespacesToPixels(1); //Żeby był lekki margines między kreską taktową a symbolem. Być może ta linijka będzie do usunięcia
            }
            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 (!IsVirtualKey)
            {
                element.TextBlockLocation = new Primitives.Point(scoreService.CursorPositionX, scoreService.CurrentLinePositions[0]);
            }

            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.DrawCharacter(element.GetCharacter(fontProfile.MusicFont), 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;
        }
 /// <summary>
 /// Draw musical symbol
 /// </summary>
 /// <param name="element">Element to draw</param>
 /// <param name="renderer">Renderer</param>
 public abstract void Render(TElement element, ScoreRendererBase renderer, FontProfile fontProfile);
 public void SetFont(string fontName, FontFamily family, FontProfile fontProfile, double cellAscent = 24.8)
 {
     rendererSettings.Value.MusicFontProfile = fontProfile;
     rendererSettings.Value.SetFont(fontName, family, fontProfile.FontSizes[MusicFontStyles.MusicFont], fontProfile.FontSizes[MusicFontStyles.GraceNoteFont], fontProfile.FontSizes[MusicFontStyles.StaffFont], cellAscent);
 }
        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 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 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 DrawNote(ScoreRendererBase renderer, Note element, double notePositionY, FontProfile fontProfile)
        {
            if (element.IsGraceNote || element.IsCueNote)
            {
                renderer.DrawCharacter(element.GetCharacter(fontProfile.MusicFont), MusicFontStyles.GraceNoteFont, scoreService.CursorPositionX + 1, notePositionY, element);
            }
            else
            {
                renderer.DrawCharacter(element.GetCharacter(fontProfile.MusicFont), MusicFontStyles.MusicFont, scoreService.CursorPositionX, notePositionY, element);
            }

            measurementService.LastNotePositionX = scoreService.CursorPositionX;
            element.TextBlockLocation            = new Point(scoreService.CursorPositionX, notePositionY);
        }
        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);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Renders a rest with specific score renderer
        /// </summary>
        /// <param name="element"></param>
        /// <param name="renderer"></param>
        public override void Render(Rest element, ScoreRendererBase renderer, FontProfile fontProfile)
        {
            var isOnlyElementInMeasure = element.Measure?.Elements?.OfType <NoteOrRest>().Count() == 1;

            if (!renderer.Settings.IgnoreCustomElementPositions && element.DefaultXPosition.HasValue) //Jeśli ustalono default-x, to pozycjonuj wg default-x, a nie automatycznie
            {
                scoreService.CursorPositionX = measurementService.LastMeasurePositionX +
                                               element.DefaultXPosition.Value * renderer.Settings.CustomElementPositionRatio;
            }
            else if (isOnlyElementInMeasure && (element.Measure?.Width.HasValue ?? false))
            {
                scoreService.CursorPositionX = measurementService.LastMeasurePositionX + (element.Measure.Width.Value / 2) * renderer.Settings.CustomElementPositionRatio;
            }

            if (scoreService.CurrentMeasure.FirstNoteInMeasureXPosition == 0)
            {
                scoreService.CurrentMeasure.FirstNoteInMeasureXPosition = scoreService.CursorPositionX;
            }

            //If it's second voice, rewind position to the beginning of measure (but only if default-x is not set or is ignored):
            if (element.Voice > scoreService.CurrentVoice && (renderer.Settings.IgnoreCustomElementPositions || !element.DefaultXPosition.HasValue))
            {
                scoreService.CursorPositionX = scoreService.CurrentMeasure.FirstNoteInMeasureXPosition;
                measurementService.LastNoteInMeasureEndXPosition = measurementService.LastNoteEndXPosition;
            }
            scoreService.CurrentVoice = element.Voice;

            double restPositionY = scoreService.CurrentLinePositions[0] +
                                   (element.DefaultYPosition.HasValue ? renderer.TenthsToPixels(element.DefaultYPosition.Value) : renderer.LinespacesToPixels(2));

            renderer.DrawCharacter(element.GetCharacter(fontProfile.MusicFont), MusicFontStyles.MusicFont, scoreService.CursorPositionX, restPositionY, element);
            measurementService.LastNotePositionX = scoreService.CursorPositionX;
            element.TextBlockLocation            = new Point(scoreService.CursorPositionX, restPositionY);

            //Draw number of measures for multimeasure rests / Rysuj ilość taktów dla pauz wielotaktowych:
            if (element.MultiMeasure > 1)
            {
                renderer.DrawString(Convert.ToString(element.MultiMeasure), MusicFontStyles.DirectionFont, scoreService.CursorPositionX + 6, restPositionY, element);
            }

            //Draw dots / Rysuj kropki:
            if (element.NumberOfDots > 0)
            {
                scoreService.CursorPositionX += 16;
            }
            for (int i = 0; i < element.NumberOfDots; i++)
            {
                renderer.DrawCharacter(fontProfile.MusicFont.AugmentationDot, MusicFontStyles.MusicFont, scoreService.CursorPositionX, restPositionY, element);
                scoreService.CursorPositionX += 6;
            }

            if (renderer.Settings.IgnoreCustomElementPositions || !element.DefaultXPosition.HasValue) //Pozycjonowanie automatyczne tylko, gdy nie określono default-x
            {
                if (element.Duration == RhythmicDuration.Whole)
                {
                    scoreService.CursorPositionX += 48;
                }
                else if (element.Duration == RhythmicDuration.Half)
                {
                    scoreService.CursorPositionX += 28;
                }
                else if (element.Duration == RhythmicDuration.Quarter)
                {
                    scoreService.CursorPositionX += 17;
                }
                else if (element.Duration == RhythmicDuration.Eighth)
                {
                    scoreService.CursorPositionX += 15;
                }
                else
                {
                    scoreService.CursorPositionX += 14;
                }
            }

            measurementService.LastNoteEndXPosition = scoreService.CursorPositionX;
        }
        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);
            }
        }
Beispiel #21
0
        /// <summary>
        /// Renders time signature symbol with specific score renderer
        /// </summary>
        /// <param name="element"></param>
        /// <param name="renderer"></param>
        public override void Render(TimeSignature element, ScoreRendererBase renderer, FontProfile fontProfile)
        {
            var topLinePosition = scoreService.CurrentLinePositions[0];

            if (element.Measure.Elements.FirstOrDefault() == element)
            {
                scoreService.CursorPositionX += renderer.LinespacesToPixels(1); //Żeby był lekki margines między kreską taktową a symbolem. Być może ta linijka będzie do usunięcia
            }
            if (element.SignatureType != TimeSignatureType.Numbers)
            {
                renderer.DrawCharacter(element.GetCharacter(fontProfile.MusicFont), MusicFontStyles.MusicFont,
                                       scoreService.CursorPositionX, topLinePosition + renderer.LinespacesToPixels(2), element);
                element.TextBlockLocation = new Primitives.Point(scoreService.CursorPositionX, topLinePosition + renderer.LinespacesToPixels(2));
            }
            else
            {
                if (renderer.IsSMuFLFont)
                {
                    renderer.DrawString(fontProfile.MusicFont.BuildTimeSignature(element.NumberOfBeats),
                                        MusicFontStyles.MusicFont, scoreService.CursorPositionX, topLinePosition + renderer.LinespacesToPixels(1), element);
                    renderer.DrawString(fontProfile.MusicFont.BuildTimeSignature(element.TypeOfBeats),
                                        MusicFontStyles.MusicFont, scoreService.CursorPositionX, topLinePosition + renderer.LinespacesToPixels(3), element);

                    element.TextBlockLocation = new Primitives.Point(scoreService.CursorPositionX, topLinePosition + renderer.LinespacesToPixels(3));
                }
                else
                {
                    renderer.DrawString(Convert.ToString(element.NumberOfBeats),
                                        MusicFontStyles.TimeSignatureFont, scoreService.CursorPositionX, topLinePosition + renderer.LinespacesToPixels(2), element);
                    renderer.DrawString(Convert.ToString(element.TypeOfBeats),
                                        MusicFontStyles.TimeSignatureFont, scoreService.CursorPositionX, topLinePosition + renderer.LinespacesToPixels(4), element);

                    element.TextBlockLocation = new Primitives.Point(scoreService.CursorPositionX, topLinePosition + renderer.LinespacesToPixels(4));
                }
            }
            scoreService.CursorPositionX += 20;
        }
 public void SetMusicFontProfile(FontProfile profile)
 {
     MusicFontProfile = profile;
 }
        /// <summary>
        /// Renders a note with a specific score renderer
        /// </summary>
        /// <param name="element"></param>
        /// <param name="renderer"></param>
        public override void Render(Note element, ScoreRendererBase renderer, FontProfile fontProfile)
        {
            if (slurRenderStrategies == null)
            {
                slurRenderStrategies = renderer.Resolver.ResolveAll <SlurRenderStrategy>().ToArray();
            }

            //Jeśli ustalono default-x, to pozycjonuj wg default-x, a nie automatycznie
            if (!renderer.Settings.IgnoreCustomElementPositions && element.DefaultXPosition.HasValue)
            {
                scoreService.CursorPositionX = measurementService.LastMeasurePositionX + element.DefaultXPosition.Value * renderer.Settings.CustomElementPositionRatio;
            }

            if (scoreService.CurrentMeasure.FirstNoteInMeasureXPosition == 0)
            {
                scoreService.CurrentMeasure.FirstNoteInMeasureXPosition = scoreService.CursorPositionX;
            }

            //If it's second voice, rewind position to the beginning of measure (but only if default-x is not set or is ignored):
            if (element.Voice > scoreService.CurrentVoice && (renderer.Settings.IgnoreCustomElementPositions || !element.DefaultXPosition.HasValue))
            {
                scoreService.CursorPositionX = scoreService.CurrentMeasure.FirstNoteInMeasureXPosition;
                measurementService.LastNoteInMeasureEndXPosition = measurementService.LastNoteEndXPosition;
            }
            scoreService.CurrentVoice = element.Voice;

            if (element.Tuplet == TupletType.Start)
            {
                Tuplet tuplet = new Tuplet();
                measurementService.TupletState  = tuplet;
                tuplet.NumberOfNotesUnderTuplet = 0;
                tuplet.TupletPlacement          = element.TupletPlacement.HasValue ? element.TupletPlacement.Value :
                                                  (element.StemDirection == VerticalDirection.Down ? VerticalPlacement.Below : VerticalPlacement.Above);
            }
            if (measurementService.TupletState != null && !element.IsUpperMemberOfChord)
            {
                measurementService.TupletState.NumberOfNotesUnderTuplet++;
            }

            if (element.IsUpperMemberOfChord)
            {
                scoreService.CursorPositionX = measurementService.LastNotePositionX;
            }

            double noteTextBlockPositionY = CalculateNotePositionY(element, renderer);
            var    chord = GetChord(element, scoreService.CurrentStaff);                              //Chord or single note

            MakeSpaceForAccidentals(renderer, element, chord);                                        //Move the element a bit to the right if it has accidentals / Przesuń nutę trochę w prawo, jeśli nuta ma znaki przygodne
            DrawNote(renderer, element, noteTextBlockPositionY, fontProfile);                         //Draw an element / Rysuj nutę
            DrawLedgerLines(renderer, element, noteTextBlockPositionY);                               //Ledger lines / Linie dodane
            DrawStems(renderer, element, noteTextBlockPositionY, chord);                              //Stems are vertical lines, beams are horizontal lines / Rysuj ogonki (ogonki to są te w pionie - poziome są belki)
            DrawFlagsAndTupletMarks(renderer, element);                                               //Draw beams / Rysuj belki
            DrawTies(renderer, element, noteTextBlockPositionY);                                      //Draw ties / Rysuj łuki
            DrawSlurs(renderer, element, noteTextBlockPositionY, fontProfile);                        //Draw slurs / Rysuj łuki legatowe
            DrawLyrics(renderer, element);                                                            //Draw lyrics / Rysuj tekst
            DrawArticulation(renderer, element, noteTextBlockPositionY, fontProfile);                 //Draw articulation / Rysuj artykulację:
            DrawTrills(renderer, element, noteTextBlockPositionY, fontProfile);                       //Draw trills / Rysuj tryle //TODO: REFAKTOR - Przenieść do DrawOrnaments
            DrawOrnaments(renderer, element, noteTextBlockPositionY, fontProfile);                    //Draw ornaments / Rysuj ornamenty
            DrawTremolos(renderer, element, noteTextBlockPositionY);                                  //Draw tremolos / Rysuj tremola
            DrawFermataSign(renderer, element, noteTextBlockPositionY, fontProfile);                  //Draw fermata sign / Rysuj symbol fermaty
            DrawAccidentals(renderer, element, noteTextBlockPositionY, fontProfile);                  //Draw accidentals / Rysuj znaki przygodne:
            DrawDots(renderer, element, noteTextBlockPositionY, fontProfile);                         //Draw dots / Rysuj kropki

            if (renderer.Settings.IgnoreCustomElementPositions || !element.DefaultXPosition.HasValue) //Pozycjonowanie automatyczne tylko, gdy nie określono default-x
            {
                if (element.Duration == RhythmicDuration.Whole)
                {
                    scoreService.CursorPositionX += 50;
                }
                else if (element.Duration == RhythmicDuration.Half)
                {
                    scoreService.CursorPositionX += 30;
                }
                else if (element.Duration == RhythmicDuration.Quarter)
                {
                    scoreService.CursorPositionX += 18;
                }
                else if (element.Duration == RhythmicDuration.Eighth)
                {
                    scoreService.CursorPositionX += 15;
                }
                else
                {
                    scoreService.CursorPositionX += 14;
                }

                //Przesuń trochę w prawo, jeśli nuta ma tekst, żeby litery nie wchodziły na siebie
                //Move a bit right if the element has a lyric to prevent letters from hiding each other
                if (element.Lyrics.Count > 0)
                {
                    scoreService.CursorPositionX += element.Lyrics[0].Text.Length * 2;
                }
            }
            measurementService.LastNoteEndXPosition = scoreService.CursorPositionX;

            element.ActualRenderedBounds = element.GetBounds(renderer);
        }
        private void DrawArticulation(ScoreRendererBase renderer, Note element, double notePositionY, FontProfile fontProfile)
        {
            if (element.Articulation != ArticulationType.None)
            {
                double articulationPosition = notePositionY + 10;
                if (element.ArticulationPlacement == VerticalPlacement.Above)
                {
                    articulationPosition = notePositionY - 10;
                }
                else if (element.ArticulationPlacement == VerticalPlacement.Below)
                {
                    articulationPosition = notePositionY + 10;
                }

                if (element.Articulation == ArticulationType.Staccato)
                {
                    renderer.DrawCharacter(fontProfile.MusicFont.AugmentationDot, MusicFontStyles.MusicFont, scoreService.CursorPositionX - 1, articulationPosition, element);
                }
                else if (element.Articulation == ArticulationType.Accent)
                {
                    renderer.DrawString(">", MusicFontStyles.DirectionFont, scoreService.CursorPositionX - 1, articulationPosition + 16, element);
                }
            }
        }