Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2023 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #ifndef MU_ENGRAVING_LYRICSLAYOUT_DEV_H
23 : #define MU_ENGRAVING_LYRICSLAYOUT_DEV_H
24 :
25 : #include "layoutcontext.h"
26 :
27 : #include <optional>
28 :
29 : namespace mu::engraving {
30 : class Score;
31 : class System;
32 : class Lyrics;
33 : class LyricsLine;
34 : class LyricsLineSegment;
35 : class SkylineLine;
36 : }
37 :
38 : namespace mu::engraving::rendering::score {
39 : class LyricsLayout
40 : {
41 : struct LyricsVerse {
42 : private:
43 : std::vector<Lyrics*> m_lyrics;
44 : std::vector<LyricsLineSegment*> m_lines;
45 : public:
46 2180 : void addLyrics(Lyrics* l) { m_lyrics.push_back(l); }
47 345 : void addLine(LyricsLineSegment* lls) { m_lines.push_back(lls); }
48 :
49 2020 : const std::vector<Lyrics*>& lyrics() const { return m_lyrics; }
50 2020 : const std::vector<LyricsLineSegment*>& lines() const { return m_lines; }
51 : };
52 :
53 : using LyricsVersesMap = std::map<int, LyricsVerse>;
54 :
55 : public:
56 : LyricsLayout() = default;
57 :
58 : static void layout(Lyrics* item, LayoutContext& ctx);
59 : static void layout(LyricsLine* item);
60 : static void layout(LyricsLineSegment* item, LayoutContext& ctx);
61 :
62 : static void computeVerticalPositions(System* system, LayoutContext& ctx);
63 :
64 : private:
65 : static void createOrRemoveLyricsLine(Lyrics* item, LayoutContext& ctx);
66 :
67 : static void layoutMelismaLine(LyricsLineSegment* item);
68 : static void layoutDashes(LyricsLineSegment* item);
69 :
70 14 : static Lyrics* findNextLyrics(const ChordRest* endChordRest, int verseNumber, std::optional<PlacementV> placement = std::nullopt);
71 :
72 : static void computeVerticalPositions(staff_idx_t staffIdx, System* system, LayoutContext& ctx);
73 : static void collectLyricsVerses(staff_idx_t staffIdx, System* system, LyricsVersesMap& lyricsVersesAbove,
74 : LyricsVersesMap& lyricsVersesBelow);
75 :
76 : static void setDefaultPositions(staff_idx_t staffIdx, const LyricsVersesMap& lyricsVersesAbove,
77 : const LyricsVersesMap& lyricsVersesBelow, LayoutContext& ctx);
78 :
79 : static void checkCollisionsWithStaffElements(System* system, staff_idx_t staffIdx, LayoutContext& ctx,
80 : const LyricsVersesMap& lyricsVersesAbove, const LyricsVersesMap& lyricsVersesBelow);
81 : static SkylineLine createSkylineForVerse(int verse, bool north, const LyricsVersesMap& lyricsVerses, System* system);
82 : static void moveThisVerseAndOuterOnes(int verse, int lastVerse, bool above, double diff, const LyricsVersesMap& lyricsVerses);
83 :
84 : static void addToSkyline(System* system, staff_idx_t staffIdx, LayoutContext& ctx, const LyricsVersesMap& lyricsVersesAbove,
85 : const LyricsVersesMap& lyricsVersesBelow);
86 :
87 : static double lyricsLineStartX(const LyricsLineSegment* item);
88 : static double lyricsLineEndX(const LyricsLineSegment* item, const Lyrics* endLyrics = nullptr);
89 : static void adjustLyricsLineYOffset(LyricsLineSegment* item, const Lyrics* endLyrics = nullptr);
90 : };
91 : }
92 : #endif // MU_ENGRAVING_LYRICSLAYOUT_DEV_H
|