MuseScore Plugins  3.5
Plugins API for MuseScore
lyrics.h
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2011 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __LYRICS_H__
14 #define __LYRICS_H__
15 
16 #include "line.h"
17 #include "text.h"
18 
19 namespace Ms {
20 
21 //---------------------------------------------------------
22 // Lyrics
23 //---------------------------------------------------------
24 
25 class LyricsLine;
26 
27 class Lyrics final : public TextBase {
28  Q_GADGET
29  public:
30  enum class Syllabic : char {
34  };
35  Q_ENUM(Syllabic);
36 
37  // MELISMA FIRST UNDERSCORE:
38  // used as_ticks value to mark a melisma for which only the first chord has been spanned so far
39  // and to give the user a visible feedback that the undercore has been actually entered;
40  // it should be cleared to 0 at some point, so that it will not be carried over
41  // if the melisma is not extended beyond a single chord, but no suitable place to do this
42  // has been identified yet.
43  static constexpr int TEMP_MELISMA_TICKS = 1;
44 
45  // WORD_MIN_DISTANCE has never been implemented
46  // static constexpr qreal LYRICS_WORD_MIN_DISTANCE = 0.33; // min. distance between lyrics from different words
47 
48  private:
49  Fraction _ticks;
50  Syllabic _syllabic;
52  LyricsLine* _separator;
53 
54  bool isMelisma() const;
55  void undoChangeProperty(Pid id, const QVariant&, PropertyFlags ps) override;
56 
57  protected:
58  int _no;
59  bool _even;
60 
61  public:
62  Lyrics(Score* = 0);
63  Lyrics(const Lyrics&);
64  ~Lyrics();
65 
66  Lyrics* clone() const override { return new Lyrics(*this); }
67  ElementType type() const override { return ElementType::LYRICS; }
68  void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
69  bool acceptDrop(EditData&) const override;
70  Element* drop(EditData&) override;
71 
72  Segment* segment() const { return toSegment(parent()->parent()); }
73  Measure* measure() const { return toMeasure(parent()->parent()->parent()); }
74  ChordRest* chordRest() const { return toChordRest(parent()); }
75 
76  void layout() override;
77  void layout2(int);
78 
79  void write(XmlWriter& xml) const override;
80  void read(XmlReader&) override;
81  bool readProperties(XmlReader&) override;
82  int subtype() const override { return _no; }
83  QString subtypeName() const override { return QObject::tr("Verse %1").arg(_no + 1); }
84  void setNo(int n) { _no = n; }
85  int no() const { return _no; }
86  bool isEven() const { return _no % 1; }
87  void setSyllabic(Syllabic s) { _syllabic = s; }
88  Syllabic syllabic() const { return _syllabic; }
89  void add(Element*) override;
90  void remove(Element*) override;
91  void endEdit(EditData&) override;
92 
93  Fraction ticks() const { return _ticks; }
94  void setTicks(const Fraction& tick) { _ticks = tick; }
95  Fraction endTick() const;
96  void removeFromScore();
97 
98  using ScoreElement::undoChangeProperty;
99  void paste(EditData&) override;
100 
101  QVariant getProperty(Pid propertyId) const override;
102  bool setProperty(Pid propertyId, const QVariant&) override;
103  QVariant propertyDefault(Pid id) const override;
104  };
105 
106 //---------------------------------------------------------
107 // LyricsLine
109 //---------------------------------------------------------
110 
111 class LyricsLine final : public SLine {
112  protected:
113  Lyrics* _nextLyrics;
114 
115  public:
116  LyricsLine(Score*);
117  LyricsLine(const LyricsLine&);
118 
119  LyricsLine* clone() const override { return new LyricsLine(*this); }
120  ElementType type() const override { return ElementType::LYRICSLINE; }
121  void layout() override;
122  LineSegment* createLineSegment() override;
123  void removeUnmanaged() override;
124  void styleChanged() override;
125 
126  Lyrics* lyrics() const { return toLyrics(parent()); }
127  Lyrics* nextLyrics() const { return _nextLyrics; }
128  bool isEndMelisma() const { return lyrics()->ticks().isNotZero(); }
129  bool isDash() const { return !isEndMelisma(); }
130  bool setProperty(Pid propertyId, const QVariant& v) override;
131  SpannerSegment* layoutSystem(System*) override;
132  };
133 
134 //---------------------------------------------------------
135 // LyricsLineSegment
137 //---------------------------------------------------------
138 
139 class LyricsLineSegment final : public LineSegment {
140  protected:
141  int _numOfDashes = 0;
142  qreal _dashLength = 0;
143 
144  public:
145  LyricsLineSegment(Spanner*, Score*);
146 
147  LyricsLineSegment* clone() const override { return new LyricsLineSegment(*this); }
148  ElementType type() const override { return ElementType::LYRICSLINE_SEGMENT; }
149  void draw(QPainter*) const override;
150  void layout() override;
151  // helper functions
152  LyricsLine* lyricsLine() const { return toLyricsLine(spanner()); }
153  Lyrics* lyrics() const { return lyricsLine()->lyrics(); }
154  };
155 
156 } // namespace Ms
157 #endif
ElementType
Definition: types.h:34
int _no
row index
Definition: lyrics.h:58
Definition: cursor.cpp:30
Syllabic
Definition: lyrics.h:30
Definition: lyrics.h:27