LCOV - code coverage report
Current view: top level - src/engraving/dom - lyrics.h Coverage Total Hit
Test: filtered_coverage.info Lines: 84.5 % 71 60
Test Date: 2026-11-19 04:14:36

            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) 2021 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              : 
      23              : #pragma once
      24              : 
      25              : #include "../types/types.h"
      26              : #include "line.h"
      27              : #include "textbase.h"
      28              : 
      29              : namespace mu::engraving {
      30              : class Transaction;
      31              : 
      32              : //---------------------------------------------------------
      33              : //   Lyrics
      34              : //---------------------------------------------------------
      35              : 
      36              : class LyricsLine;
      37              : 
      38              : class Lyrics final : public TextBase
      39              : {
      40         6532 :     OBJECT_ALLOCATOR(engraving, Lyrics)
      41         1525 :     DECLARE_CLASSOF(ElementType::LYRICS)
      42              : 
      43              : public:
      44              : 
      45              :     // MELISMA FIRST UNDERSCORE:
      46              :     // used as_ticks value to mark a melisma for which only the first chord has been spanned so far
      47              :     // and to give the user a visible feedback that the underscore has been actually entered;
      48              :     // it should be cleared to 0 at some point, so that it will not be carried over
      49              :     // if the melisma is not extended beyond a single chord, but no suitable place to do this
      50              :     // has been identified yet.
      51              :     static constexpr Fraction TEMP_MELISMA_TICKS = Fraction::eps(); // THIS WAS A HORRIBLE HACK. At some point we must remove it and replace it with a proper solution. (M.S.)
      52              : 
      53              :     ~Lyrics();
      54              : 
      55         1411 :     Lyrics* clone() const override { return new Lyrics(*this); }
      56            2 :     void setOwnershipParent(DummyParentOr<ChordRest> parent) { EngravingItem::setOwnershipParent(parent); }
      57              :     bool acceptDrop(EditData&) const override;
      58              :     EngravingItem* drop(Transaction& tx, EditData&) override;
      59              : 
      60          912 :     Segment* segment() const { return toSegment(ownershipParent()->ownershipParent()); }
      61           19 :     Measure* measure() const { return toMeasure(ownershipParent()->ownershipParent()->ownershipParent()); }
      62        12300 :     ChordRest* chordRest() const { return toChordRest(ownershipParent()); }
      63              : 
      64         1306 :     int subtype() const override { return m_verse; }
      65              :     TranslatableString subtypeUserName() const override;
      66          537 :     void setVerse(int n) { m_verse = n; }
      67        26959 :     int verse() const { return m_verse; }
      68         1266 :     bool isEven() const { return m_verse % 2; }
      69          580 :     void setSyllabic(LyricsSyllabic s) { m_syllabic = s; }
      70        21510 :     LyricsSyllabic syllabic() const { return m_syllabic; }
      71              :     void add(EngravingItem*) override;
      72              :     void remove(EngravingItem*) override;
      73              :     bool isEditAllowed(EditData&) const override;
      74              :     void endEdit(EditData&) override;
      75              : 
      76         5146 :     bool positionRelativeToNoteheadRest() const override { return true; }
      77              : 
      78        14895 :     const Fraction& ticks() const { return m_ticks; }
      79           64 :     void setTicks(const Fraction& tick) { m_ticks = tick; }
      80              :     Fraction endTick() const;
      81              :     void removeFromScore();
      82              : 
      83              :     void adjustPrevious();
      84              : 
      85         2374 :     bool needRemoveInvalidSegments() const { return m_needRemoveInvalidSegments; }
      86              :     void setNeedRemoveInvalidSegments();
      87              :     void removeInvalidSegments();
      88              : 
      89        33368 :     LyricsLine* separator() const { return m_separator; }
      90          255 :     void setSeparator(LyricsLine* s) { m_separator = s; }
      91              : 
      92              :     bool isMelisma() const;
      93              : 
      94            0 :     bool allowTimeAnchor() const override { return false; }
      95              : 
      96              :     using EngravingObject::undoChangeProperty;
      97              :     void paste(const String& txt) override;
      98              : 
      99              :     PropertyValue getProperty(Pid propertyId) const override;
     100              :     bool setProperty(Pid propertyId, const PropertyValue&) override;
     101              :     PropertyValue propertyDefault(Pid id) const override;
     102              :     void undoChangeProperty(Pid id, const PropertyValue&, PropertyFlags ps) override;
     103              :     void reset() override;
     104              :     void triggerLayout() const override;
     105              : 
     106              :     double yRelativeToStaff() const;
     107              :     void setYRelativeToStaff(double y);
     108              : 
     109         4780 :     bool avoidBarlines() const { return m_avoidBarlines; }
     110              :     void setAvoidBarlines(bool v) { m_avoidBarlines = v; }
     111              : 
     112              : private:
     113              : 
     114              :     friend class Factory;
     115              :     Lyrics(DummyParentOr<ChordRest> parent);
     116              :     Lyrics(const Lyrics&);
     117              : 
     118              :     int m_verse = 0;              // row index
     119              :     Fraction m_ticks;          // if > 0 then draw an underline to tick() + _ticks (melisma)
     120              :     LyricsSyllabic m_syllabic = LyricsSyllabic::SINGLE;
     121              :     LyricsLine* m_separator = nullptr;
     122              :     bool m_needRemoveInvalidSegments = false;
     123              :     bool m_avoidBarlines = true;
     124              : };
     125              : 
     126              : //---------------------------------------------------------
     127              : //   LyricsLine
     128              : ///   \cond PLUGIN_API \private \endcond
     129              : //---------------------------------------------------------
     130              : 
     131              : class LyricsLine : public SLine
     132              : {
     133          503 :     OBJECT_ALLOCATOR(engraving, LyricsLine)
     134         2693 :     DECLARE_CLASSOF(ElementType::LYRICSLINE)
     135              : 
     136              : public:
     137              :     LyricsLine(DummyParentOr<Lyrics> parent);
     138              :     LyricsLine(const LyricsLine&);
     139              : 
     140            0 :     LyricsLine* clone() const override { return new LyricsLine(*this); }
     141          341 :     void setOwnershipParent(DummyParentOr<Lyrics> parent) { EngravingItem::setOwnershipParent(parent); }
     142              : 
     143          802 :     Anchor anchor() const override { return Anchor::SEGMENT; }
     144              : 
     145              :     LineSegment* createLineSegment() override;
     146              :     void removeUnmanaged() override;
     147              : 
     148        20448 :     virtual Lyrics* lyrics() const { return toLyrics(ownershipParent()); }
     149          940 :     Lyrics* nextLyrics() const { return m_nextLyrics; }
     150          234 :     void setNextLyrics(Lyrics* l) { m_nextLyrics = l; }
     151         7416 :     virtual bool isEndMelisma() const { return lyrics() && lyrics()->ticks().isNotZero(); }
     152          341 :     bool isDash() const { return !isEndMelisma(); }
     153              : 
     154              :     bool setProperty(Pid propertyId, const PropertyValue& v) override;
     155              :     PropertyValue propertyDefault(Pid id) const override;
     156              :     Sid getPropertyStyle(Pid) const override;
     157              : 
     158              : protected:
     159           13 :     LyricsLine(const ElementType& type, DummyParentOr<Lyrics> parent, ElementFlags = ElementFlag::NOTHING);
     160              : 
     161          794 :     bool isInSpannerMap() const override { return false; }
     162              : 
     163              :     Lyrics* m_nextLyrics = nullptr;
     164              : 
     165              :     void doComputeEndElement() override;
     166              : };
     167              : 
     168              : //---------------------------------------------------------
     169              : //   LyricsLineSegment
     170              : ///   \cond PLUGIN_API \private \endcond
     171              : //---------------------------------------------------------
     172              : 
     173              : class LyricsLineSegment : public LineSegment
     174              : {
     175          509 :     OBJECT_ALLOCATOR(engraving, LyricsLineSegment)
     176              :     DECLARE_CLASSOF(ElementType::LYRICSLINE_SEGMENT)
     177              : 
     178              : public:
     179              :     LyricsLineSegment(LyricsLine*);
     180              : 
     181            0 :     LyricsLineSegment* clone() const override { return new LyricsLineSegment(*this); }
     182              : 
     183         5095 :     LyricsLine* lyricsLine() const { return toLyricsLine(spanner()); }
     184         2915 :     virtual Lyrics* lyrics() const { return lyricsLine()->lyrics(); }
     185              : 
     186              :     virtual double baseLineShift() const;
     187              : 
     188          684 :     virtual int verse() const { return lyrics()->verse(); }
     189          537 :     virtual bool lyricsPlaceAbove() const { return lyrics()->placeAbove(); }
     190          704 :     virtual bool lyricsAddToSkyline() const { return lyrics()->addToSkyline(); }
     191          352 :     virtual double lineSpacing() const { return lyrics()->lineSpacing(); }
     192            0 :     Color color() const override { return lyrics()->color(); }
     193              : 
     194              :     PropertyValue getProperty(Pid propertyId) const override;
     195              :     bool setProperty(Pid propertyId, const PropertyValue&) override;
     196              :     PropertyValue propertyDefault(Pid propertyId) const override;
     197              :     PropertyDelegate resolvePropertyDelegate(Pid propertyId) const override;
     198              : 
     199            0 :     bool allowTimeAnchor() const override { return false; }
     200              : 
     201            0 :     virtual bool isEditAllowed(EditData&) const override { return false; }
     202              : 
     203              :     struct LayoutData : public LineSegment::LayoutData {
     204              :     public:
     205            0 :         const std::vector<LineF>& dashes() const { return m_dashes; }
     206          364 :         void clearDashes() { m_dashes.clear(); }
     207          381 :         void addDash(const LineF& dash) { m_dashes.push_back(dash); }
     208              : 
     209              :         // The lyrics this segment's position was calculated from (if any), so it moves with them
     210              :         const Lyrics* startXLyrics = nullptr;
     211              :         const Lyrics* endXLyrics = nullptr;
     212              :         const Lyrics* yLyrics = nullptr;
     213          364 :         void clearReferenceLyrics()
     214              :         {
     215          364 :             startXLyrics = nullptr;
     216          364 :             endXLyrics = nullptr;
     217          364 :             yLyrics = nullptr;
     218          364 :         }
     219              : 
     220              :     private:
     221              :         std::vector<LineF> m_dashes;
     222              :     };
     223         2328 :     DECLARE_LAYOUTDATA_METHODS(LyricsLineSegment)
     224              : 
     225              : protected:
     226              :     LyricsLineSegment(const ElementType& type, LyricsLine* sp, ElementFlags f = ElementFlag::NOTHING);
     227              :     void rebaseAnchors(EditData&, Grip) override;
     228              : };
     229              : 
     230              : class PartialLyricsLine final : public LyricsLine
     231              : {
     232           24 :     OBJECT_ALLOCATOR(engraving, PartialLyricsLine)
     233              :     DECLARE_CLASSOF(ElementType::PARTIAL_LYRICSLINE)
     234              : 
     235              : public:
     236              :     PartialLyricsLine(DummyParent* parent);
     237              :     PartialLyricsLine(const PartialLyricsLine&);
     238            0 :     PartialLyricsLine* clone() const override { return new PartialLyricsLine(*this); }
     239              :     void setOwnershipParent(EngravingObject*) = delete;
     240              :     LineSegment* createLineSegment() override;
     241              : 
     242           23 :     Lyrics* lyrics() const override { return nullptr; }
     243              : 
     244            7 :     void setIsEndMelisma(bool val) { m_isEndMelisma = val; }
     245           86 :     bool isEndMelisma() const override { return m_isEndMelisma; }
     246              : 
     247            4 :     void setVerse(int val) { m_verse = val; }
     248           45 :     int verse() const { return m_verse; }
     249              : 
     250            6 :     void setCenterBetweenStaves(AutoOnOff v) { m_centerBetweenStaves = v; }
     251            9 :     AutoOnOff centerBetweenStaves() const { return m_centerBetweenStaves; }
     252              : 
     253              :     PropertyValue getProperty(Pid propertyId) const override;
     254              :     bool setProperty(Pid propertyId, const PropertyValue&) override;
     255              :     PropertyValue propertyDefault(Pid propertyId) const override;
     256              :     Sid getPropertyStyle(Pid propertyId) const override;
     257              :     void undoChangeProperty(Pid id, const PropertyValue&, PropertyFlags ps) override;
     258              :     void reset() override;
     259              : 
     260              :     Lyrics* findLyricsInPreviousRepeatSeg() const;
     261              :     Lyrics* findAdjacentLyricsOrDefault() const;
     262              : 
     263              : protected:
     264              :     void doComputeEndElement() override;
     265            7 :     bool isInSpannerMap() const override { return true; }
     266              : 
     267              : private:
     268              :     bool m_isEndMelisma = false;
     269              :     int m_verse = 0;
     270              :     AutoOnOff m_centerBetweenStaves = AutoOnOff::AUTO;
     271              : };
     272              : 
     273              : class PartialLyricsLineSegment final : public LyricsLineSegment
     274              : {
     275            8 :     OBJECT_ALLOCATOR(engraving, PartialLyricsLineSegment)
     276              :     DECLARE_CLASSOF(ElementType::PARTIAL_LYRICSLINE_SEGMENT)
     277              : 
     278              : public:
     279              :     PartialLyricsLineSegment(PartialLyricsLine*);
     280              : 
     281            0 :     LyricsLineSegment* clone() const override { return new PartialLyricsLineSegment(*this); }
     282              : 
     283           74 :     PartialLyricsLine* lyricsLine() const { return toPartialLyricsLine(spanner()); }
     284            0 :     Lyrics* lyrics() const override { return nullptr; }
     285              : 
     286           22 :     int verse() const override { return lyricsLine()->verse(); }
     287              :     double lineSpacing() const override;
     288            9 :     bool lyricsPlaceAbove() const override { return lyricsLine()->placeAbove(); }// Delegate?
     289           18 :     bool lyricsAddToSkyline() const override { return lyricsLine()->addToSkyline(); }
     290            0 :     Color color() const override { return lyricsLine()->color(); }
     291              :     double baseLineShift() const override;
     292              : 
     293              :     PropertyDelegate resolvePropertyDelegate(Pid) const override;
     294              : };
     295              : } // namespace mu::engraving
        

Generated by: LCOV version 2.0-1