MuseScore  3.4
Music composition and notation
lyrics.h
Go to the documentation of this file.
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:
53 
54  bool isMelisma() const;
55  virtual 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  virtual Lyrics* clone() const override { return new Lyrics(*this); }
66  virtual ElementType type() const override { return ElementType::LYRICS; }
67  virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
68  virtual bool acceptDrop(EditData&) const override;
69  virtual Element* drop(EditData&) override;
70 
71  Segment* segment() const { return toSegment(parent()->parent()); }
72  Measure* measure() const { return toMeasure(parent()->parent()->parent()); }
73  ChordRest* chordRest() const { return toChordRest(parent()); }
74 
75  virtual void layout() override;
76  void layout2(int);
77 
78  virtual void write(XmlWriter& xml) const override;
79  virtual void read(XmlReader&) override;
80  virtual bool readProperties(XmlReader&);
81  virtual int subtype() const override { return _no; }
82  virtual QString subtypeName() const override { return QObject::tr("Verse %1").arg(_no + 1); }
83  void setNo(int n) { _no = n; }
84  int no() const { return _no; }
85  bool isEven() const { return _no % 1; }
86  void setSyllabic(Syllabic s) { _syllabic = s; }
87  Syllabic syllabic() const { return _syllabic; }
88  virtual void add(Element*) override;
89  virtual void remove(Element*) override;
90  virtual void endEdit(EditData&) override;
91 
92  Fraction ticks() const { return _ticks; }
93  void setTicks(const Fraction& tick) { _ticks = tick; }
94  Fraction endTick() const;
95  void removeFromScore();
96 
98  virtual void paste(EditData&) override;
99 
100  virtual QVariant getProperty(Pid propertyId) const override;
101  virtual bool setProperty(Pid propertyId, const QVariant&) override;
102  virtual QVariant propertyDefault(Pid id) const override;
103  virtual Sid getPropertyStyle(Pid) const override;
104  };
105 
106 //---------------------------------------------------------
107 // LyricsLine
109 //---------------------------------------------------------
110 
111 class LyricsLine final : public SLine {
112  protected:
114 
115  public:
116  LyricsLine(Score*);
117  LyricsLine(const LyricsLine&);
118 
119  virtual LyricsLine* clone() const override { return new LyricsLine(*this); }
120  virtual ElementType type() const override { return ElementType::LYRICSLINE; }
121  virtual void layout() override;
122  virtual LineSegment* createLineSegment() override;
123  virtual void removeUnmanaged() override;
124  virtual 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  virtual bool setProperty(Pid propertyId, const QVariant& v) override;
131  virtual 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:
146 
147  virtual LyricsLineSegment* clone() const override { return new LyricsLineSegment(*this); }
148  virtual ElementType type() const override { return ElementType::LYRICSLINE_SEGMENT; }
149  virtual void draw(QPainter*) const override;
150  virtual 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
virtual bool readProperties(XmlReader &)
Definition: lyrics.cpp:128
bool isMelisma() const
Definition: lyrics.cpp:198
virtual Element * drop(EditData &) override
Handle a dropped element at canvas relative pos of given element type and subtype.
Definition: lyrics.cpp:464
virtual Sid getPropertyStyle(Pid) const override
Definition: lyrics.cpp:581
Definition: lyrics.h:111
virtual QVariant getProperty(Pid propertyId) const override
Definition: lyrics.cpp:509
void layout2(int)
Definition: lyrics.cpp:355
Pid
Definition: property.h:62
Fraction _ticks
if > 0 then draw an underline to tick() + _ticks (melisma)
Definition: lyrics.h:49
virtual bool setProperty(Pid propertyId, const QVariant &) override
Definition: lyrics.cpp:527
LyricsLine * lyricsLine() const
Definition: lyrics.h:152
Definition: xml.h:67
virtual void undoChangeProperty(Pid id, const QVariant &, PropertyFlags ps)
Definition: scoreElement.cpp:291
parent: System
Definition: spanner.h:50
Virtual base class for slurs, ties, lines etc.
Definition: spanner.h:136
one measure in a system
Definition: measure.h:65
virtual int subtype() const override
Definition: lyrics.h:81
virtual void endEdit(EditData &) override
Definition: lyrics.cpp:486
Definition: lyrics.h:139
Base class of score layout elements.
Definition: element.h:158
Segment * segment() const
Definition: lyrics.h:71
bool isEndMelisma() const
Definition: lyrics.h:128
virtual void layout() override
Definition: lyrics.cpp:226
virtual void add(Element *) override
Definition: lyrics.cpp:162
~Lyrics()
Definition: lyrics.cpp:61
virtual bool acceptDrop(EditData &) const override
Return true if this element accepts a drop at canvas relative pos of given element type and subtype...
Definition: lyrics.cpp:455
Fraction endTick() const
Definition: lyrics.cpp:446
Element * parent() const
Definition: element.h:192
Virtual base class for segmented lines segments (OttavaSegment, HairpinSegment, TrillSegment...)
Definition: line.h:34
Definition: score.h:391
static constexpr int TEMP_MELISMA_TICKS
Definition: lyrics.h:43
virtual ElementType type() const override
Definition: lyrics.h:120
bool _even
Definition: lyrics.h:59
virtual LyricsLineSegment * clone() const override
Definition: lyrics.h:147
PropertyFlags
Definition: property.h:54
virtual void scanElements(void *data, void(*func)(void *, Element *), bool all=true) override
Definition: lyrics.cpp:71
Lyrics(Score *=0)
Definition: lyrics.cpp:40
Syllabic syllabic() const
Definition: lyrics.h:87
virtual ElementType type() const override
Definition: lyrics.h:66
void removeFromScore()
Definition: lyrics.cpp:496
LyricsLine * _separator
Definition: lyrics.h:52
virtual Lyrics * clone() const override
Definition: lyrics.h:65
virtual ElementType type() const override
Definition: lyrics.h:148
virtual void draw(QPainter *) const override
Definition: textbase.cpp:2615
Measure * measure() const
Definition: lyrics.h:72
ChordRest * chordRest() const
Definition: lyrics.h:73
virtual Fraction tick() const
Definition: element.cpp:287
virtual LyricsLine * clone() const override
Definition: lyrics.h:119
virtual base class for Hairpin, Trill and TextLine
Definition: line.h:70
Lyrics * nextLyrics() const
Definition: lyrics.h:127
void setSyllabic(Syllabic s)
Definition: lyrics.h:86
virtual QString subtypeName() const override
Definition: lyrics.h:82
virtual void undoChangeProperty(Pid id, const QVariant &, PropertyFlags ps) override
Definition: lyrics.cpp:609
bool isEven() const
Definition: lyrics.h:85
Definition: textbase.h:217
Definition: segment.h:50
Syllabic _syllabic
Definition: lyrics.h:51
void setNo(int n)
Definition: lyrics.h:83
void setTicks(const Fraction &tick)
Definition: lyrics.h:93
Definition: aeolus.cpp:26
Sid
Definition: style.h:33
Lyrics * lyrics() const
Definition: lyrics.h:153
Definition: xml.h:218
virtual void paste(EditData &) override
Definition: lyrics.cpp:374
int no() const
Definition: lyrics.h:84
virtual Pid propertyId(const QStringRef &xmlName) const override
Definition: textbase.cpp:1808
Lyrics * _nextLyrics
Definition: lyrics.h:113
Fraction ticks() const
Definition: lyrics.h:92
Definition: chordrest.h:48
virtual void styleChanged()
Definition: textbase.cpp:2500
Definition: element.h:111
virtual void write(XmlWriter &xml) const override
Definition: lyrics.cpp:84
One row of measures for all instruments; a complete piece of the timeline.
Definition: system.h:79
Syllabic
Definition: lyrics.h:30
Definition: fraction.h:46
ElementType
Definition: types.h:34
virtual void read(XmlReader &) override
Definition: lyrics.cpp:107
virtual QVariant propertyDefault(Pid id) const override
Definition: lyrics.cpp:555
Definition: lyrics.h:27
Lyrics * lyrics() const
Definition: lyrics.h:126
bool isDash() const
Definition: lyrics.h:129
int _no
row index
Definition: lyrics.h:58