MuseScore  3.4
Music composition and notation
figuredbass.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 __FIGUREDBASS_H__
14 #define __FIGUREDBASS_H__
15 
16 #include "text.h"
17 
18 namespace Ms {
19 
20 class Segment;
21 
22 /*---------------------------------------------------------
23 NOTE ON ARCHITECTURE
24 
25 FiguredBass elements are stored in the annotations of a Segment (like for instance Harmony)
26 
27 FiguredBass is rather simple: it contains only _ticks, telling the duration of the element,
28 and a list of FiguredBassItem elements which do most of the job. It also maintains a text with the
29 normalized (made uniform) version of the text, which is used during editing.
30 
31 Normally, a FiguredBass element is assumed to be styled with an internally maintained text style
32 (based on the parameters of the general style "Figured Bass") FIGURED_BASS style and it is set
33 in this way upon creation and upon layout().
34 - - - -
35 FiguredBassItem contains the actually f.b. info; it is made of 4 parts (in this order):
36 1) prefix: one of [nothing, doubleflat, flat, natural, sharp, doublesharp, cross]
37 2) digit: one digit from 1 to 9
38 3) suffix: one of [nothing, doubleflat, flat, natural, sharp, doublesharp, cross, backslash, slash]
39 4) contLine: true if the item has a continuation line (whose length is determined by parent's _ticks)
40 and 5 parenthesis flags, one for each position before, between and after the four parts above:
41 each of them may contain one of [nothing, roundOpen, roundClosed, squaredOpen, squaredClosed].
42 
43 There is a number of restrictions, implemented at the end of FiguredBassItem::parse().
44 Currently, no attempt is made to ensure that, if multiple parentheses are present, they are consistent
45 (matching open and closed parentheses is left to the user).
46 
47 If an item cannot be parsed, the whole FiguredBass element is kept as entered, possibly un-styled.
48 If all items can be parsed, each item generates a display text from its properties,
49 lays it out so that it properly aligns under the chord, draws it at its proper location
50 and provides its FiguredBass parent with a normalized text for future editing.
51 
52 FiguredBassItem has not use for formats (italics, bold, ...) and it is never edited directly;
53 more generally, it is never accessed directly, only via its FiguredBass parent;
54 so it is directly derived from Element and returns INVALID as type.
55 
56 FiguredBass might require formatting (discouraged, but might be necessary for very uncommon cases)
57 and it is edited (via the normalized text); so it is derived from Text.
58 ---------------------------------------------------------*/
59 
60 #define FBIDigitNone -1
61 
62 //---------------------------------------------------------
63 // @@ FiguredBassItem
65 //
66 // @P continuationLine enum (FiguredBassItem.NONE, .SIMPLE, .EXTENDED) whether item has continuation line or not, and of which type
67 // @P digit int main digit(s) (0 - 9)
68 // @P displayText string text displayed (depends on configured fonts) (read only)
69 // @P normalizedText string conventional textual representation of item properties (= text used during input) (read only)
70 // @P parenthesis1 enum (FiguredBassItem.NONE, .ROUNDOPEN, .ROUNDCLOSED, .SQUAREDOPEN, .SQUAREDCLOSED) parenthesis before the prefix
71 // @P parenthesis2 enum (FiguredBassItem.NONE, .ROUNDOPEN, .ROUNDCLOSED, .SQUAREDOPEN, .SQUAREDCLOSED) parenthesis after the prefix / before the digit
72 // @P parenthesis3 enum (FiguredBassItem.NONE, .ROUNDOPEN, .ROUNDCLOSED, .SQUAREDOPEN, .SQUAREDCLOSED) parenthesis after the digit / before the suffix
73 // @P parenthesis4 enum (FiguredBassItem.NONE, .ROUNDOPEN, .ROUNDCLOSED, .SQUAREDOPEN, .SQUAREDCLOSED) parenthesis after the suffix / before the cont. line
74 // @P parenthesis5 enum (FiguredBassItem.NONE, .ROUNDOPEN, .ROUNDCLOSED, .SQUAREDOPEN, .SQUAREDCLOSED) parenthesis after the cont. line
75 // @P prefix enum (FiguredBassItem.NONE, .DOUBLEFLAT, .FLAT, .NATURAL, .SHARP, .DOUBLESHARP, .PLUS, .BACKSLASH, .SLASH) accidental before the digit
76 // @P suffix enum (FiguredBassItem.NONE, .DOUBLEFLAT, .FLAT, .NATURAL, .SHARP, .DOUBLESHARP, .PLUS, .BACKSLASH, .SLASH) accidental/diacritic after the digit
77 //---------------------------------------------------------
78 
79 class FiguredBass;
80 
81 class FiguredBassItem final : public Element {
82  public:
83  enum class Modifier : char {
84  NONE = 0,
85  DOUBLEFLAT,
86  FLAT,
87  NATURAL,
88  SHARP,
90  CROSS,
91  BACKSLASH,
92  SLASH,
93  NUMOF
94  };
95  enum class Parenthesis : char {
96  NONE = 0,
97  ROUNDOPEN,
98  ROUNDCLOSED,
99  SQUAREDOPEN,
100  SQUAREDCLOSED,
101  NUMOF
102  };
103  enum class ContLine : char {
104  NONE = 0,
105  SIMPLE, // cont. line stops at f.b. element end
106  EXTENDED // cont. line joins with next element, if possible
107  };
108 
109  enum class Style : char {
110  MODERN = 0,
111  HISTORIC,
112  NUMOF
113  };
114  enum class Combination : char {
115  SIMPLE = 0,
116  CROSSED,
117  BACKSLASHED,
118  SLASHED,
119  NUMOF
120  };
121 
122  private:
123 
124  static const QChar normParenthToChar[int(Parenthesis::NUMOF)];
125 
126  QString _displayText; // the constructed display text (read-only)
127  int ord; // the line ordinal of this element in the FB stack
128  // the parts making a FiguredBassItem up
129  Modifier _prefix; // the accidental coming before the body
130  int _digit; // the main digit (if present)
131  Modifier _suffix; // the accidental coming after the body
132  ContLine _contLine; // whether the item has continuation line or not
133  Parenthesis parenth[5]; // each of the parenthesis: before, between and after parts
134  qreal textWidth; // the text width (in raster units), set during layout()
135  // used by draw()
136  // part parsing
137  int parseDigit(QString& str);
138  int parseParenthesis(QString& str, int parenthIdx);
139  int parsePrefixSuffix(QString& str, bool bPrefix);
140 
141  void setDisplayText(const QString& s) { _displayText = s; }
142  // read / write MusicXML support
144 
145  public:
146  FiguredBassItem(Score * s = 0, int line = 0);
149 
150  FiguredBassItem &operator=(const FiguredBassItem&) = delete;
151 
152  FiguredBassItem::Modifier MusicXML2Modifier(const QString prefix) const;
153 
154  // standard re-implemented virtual functions
155  virtual FiguredBassItem* clone() const override { return new FiguredBassItem(*this); }
156  virtual ElementType type() const override { return ElementType::INVALID; }
157  virtual void draw(QPainter* painter) const override;
158  virtual void layout() override;
159  virtual void read(XmlReader&) override;
160  virtual void write(XmlWriter& xml) const override;
161 
162  // read / write MusicXML
163  void writeMusicXML(XmlWriter& xml, bool isOriginalFigure, int crEndTick, int fbEndTick) const;
164  bool startsWithParenthesis() const;
165 
166  // specific API
167  const FiguredBass * figuredBass() const { return (FiguredBass*)(parent()); }
168  bool parse(QString& text);
169 
170  // getters / setters
171  Modifier prefix() const { return _prefix; }
172  void setPrefix(const Modifier& v) { _prefix = v; }
173  void undoSetPrefix(Modifier pref);
174  int digit() const { return _digit; }
175  void setDigit(int val) { _digit = val; }
176  void undoSetDigit(int digit);
177  Modifier suffix() const { return _suffix; }
178  void setSuffix(const Modifier& v) { _suffix = v; }
179  void undoSetSuffix(Modifier suff);
180  ContLine contLine() const { return _contLine; }
181  void setContLine(const ContLine& v){ _contLine = v; }
182  void undoSetContLine(ContLine val);
183  Parenthesis parenth1() { return parenth[0]; }
184  Parenthesis parenth2() { return parenth[1]; }
185  Parenthesis parenth3() { return parenth[2]; }
186  Parenthesis parenth4() { return parenth[3]; }
187  Parenthesis parenth5() { return parenth[4]; }
188 
189  void setParenth1(Parenthesis v) { parenth[0] = v; }
190  void setParenth2(Parenthesis v) { parenth[1] = v; }
191  void setParenth3(Parenthesis v) { parenth[2] = v; }
192  void setParenth4(Parenthesis v) { parenth[3] = v; }
193  void setParenth5(Parenthesis v) { parenth[4] = v; }
194 
195  void undoSetParenth1(Parenthesis par);
196  void undoSetParenth2(Parenthesis par);
197  void undoSetParenth3(Parenthesis par);
198  void undoSetParenth4(Parenthesis par);
199  void undoSetParenth5(Parenthesis par);
200  QString normalizedText() const;
201  QString displayText() const { return _displayText; }
202 
203  virtual QVariant getProperty(Pid propertyId) const override;
204  virtual bool setProperty(Pid propertyId, const QVariant&) override;
205  virtual QVariant propertyDefault(Pid) const override;
206  };
207 
208 //---------------------------------------------------------
209 // FiguredBassFont
210 //---------------------------------------------------------
211 
213  QString family;
214  QString displayName;
215  qreal defPitch;
217  QChar displayAccidental[int(FiguredBassItem::Modifier::NUMOF)];
218  QChar displayParenthesis[int(FiguredBassItem::Parenthesis::NUMOF)];
220 
221  bool read(XmlReader&);
222  };
223 
224 //---------------------------------------------------------
225 // @@ FiguredBass
227 //
228 // @P onNote bool whether it is placed on a note beginning or between notes (read only)
229 // @P ticks int duration in ticks
230 //---------------------------------------------------------
231 
232 class FiguredBass final : public TextBase {
233  std::vector<FiguredBassItem*> items; // the individual lines of the F.B.
234  QVector<qreal> _lineLengths; // lengths of duration indicator lines (in raster units)
235  bool _onNote; // true if this element is on a staff note | false if it is betweee notes
236  Fraction _ticks; // the duration (used for cont. lines and for multiple F.B.
237  // under the same note)
238  qreal _printedLineLength; // the length of lines actually printed (i.e. continuation lines)
239  void layoutLines();
240  bool hasParentheses() const; // read / write MusicXML support
241 
242  virtual Sid getPropertyStyle(Pid) const override;
243 
244  public:
245  FiguredBass(Score* s = 0);
246  FiguredBass(const FiguredBass&);
247  ~FiguredBass();
248 
249  // a convenience static function to create/retrieve a new FiguredBass into/from its intended parent
250  static FiguredBass* addFiguredBassToSegment(Segment* seg, int track, const Fraction& extTicks, bool *pNew);
251 
252  // static functions for font config files
253  static bool readConfigFile(const QString& fileName);
254  static QList<QString> fontNames();
255  static bool fontData(int nIdx, QString *pFamily, QString *pDisplayName,
256  qreal * pSize, qreal * pLineHeight);
257 
258  // standard re-implemented virtual functions
259  virtual FiguredBass* clone() const override { return new FiguredBass(*this); }
260  virtual ElementType type() const override { return ElementType::FIGURED_BASS; }
261  virtual void draw(QPainter* painter) const override;
262  virtual void endEdit(EditData&) override;
263  virtual void layout() override;
264  virtual void read(XmlReader&) override;
265  virtual void setSelected(bool f) override;
266  virtual void setVisible(bool f) override;
267  virtual void startEdit(EditData&) override;
268  virtual void write(XmlWriter& xml) const override;
269 
270  // read / write MusicXML
271  void writeMusicXML(XmlWriter& xml, bool isOriginalFigure, int crEndTick, int fbEndTick, bool writeDuration, int divisions) const;
272 
273 //DEBUG
274 //Q_INVOKABLE Ms::FiguredBassItem* addItem();
275 
276  // getters / setters / properties
277 // void qmlItemsAppend(QDeclarativeListProperty<FiguredBassItem> *list, FiguredBassItem * pItem)
278 // { list->append(pItem);
279 // items.append(&pItem);
280 // }
281 // QDeclarativeListProperty<FiguredBassItem> qmlItems()
282 // { QList<FiguredBassItem*> list;
283 // foreach(FiguredBassItem item, items)
284 // list.append(&item);
285 // return QDeclarativeListProperty<FiguredBassItem>(this, &items, qmlItemsAppend);
286 // }
287  qreal lineLength(int idx) const { if(_lineLengths.size() > idx)
288  return _lineLengths.at(idx);
289  return 0; }
290  qreal printedLineLength() const { return _printedLineLength; }
291  bool onNote() const { return _onNote; }
292  size_t numOfItems() const { return items.size(); }
293  void setOnNote(bool val) { _onNote = val; }
294  Segment * segment() const { return (Segment*)(parent()); }
295  Fraction ticks() const { return _ticks; }
296  void setTicks(const Fraction& v) { _ticks = v; }
297 
298  qreal additionalContLineX(qreal pagePosY) const;// returns the X coord (in page coord) of cont. line at pagePosY, if any
299  FiguredBass * nextFiguredBass() const; // returns next *adjacent* f.b. item, if any
300 
301  virtual QVariant getProperty(Pid propertyId) const override;
302  virtual bool setProperty(Pid propertyId, const QVariant&) override;
303  virtual QVariant propertyDefault(Pid) const override;
304 
305  void appendItem(FiguredBassItem* item) { items.push_back(item); }
306  };
307 
308 
309 } // namespace Ms
310 
311 Q_DECLARE_METATYPE(Ms::FiguredBassItem::Modifier);
312 Q_DECLARE_METATYPE(Ms::FiguredBassItem::Parenthesis);
313 Q_DECLARE_METATYPE(Ms::FiguredBassItem::ContLine);
314 
315 #endif
316 
bool startsWithParenthesis() const
Definition: figuredbass.cpp:961
virtual QVariant propertyDefault(Pid) const override
Definition: figuredbass.cpp:718
Style
Definition: figuredbass.h:109
Segment * segment() const
Definition: figuredbass.h:294
virtual bool setProperty(Pid propertyId, const QVariant &) override
Definition: figuredbass.cpp:663
Pid
Definition: property.h:62
Modifier
Definition: figuredbass.h:83
Definition: xml.h:67
QVector< qreal > _lineLengths
Definition: figuredbass.h:234
Modifier _suffix
Definition: figuredbass.h:131
ContLine _contLine
Definition: figuredbass.h:132
bool parse(QString &text)
Definition: figuredbass.cpp:104
int _digit
Definition: figuredbass.h:130
~FiguredBassItem()
Definition: figuredbass.cpp:93
void setContLine(const ContLine &v)
Definition: figuredbass.h:181
Fraction ticks() const
Definition: figuredbass.h:295
int ord
Definition: figuredbass.h:127
bool _onNote
Definition: figuredbass.h:235
int digit() const
Definition: figuredbass.h:174
qreal defPitch
Definition: figuredbass.h:215
virtual void write(XmlWriter &xml) const override
Definition: figuredbass.cpp:412
Base class of score layout elements.
Definition: element.h:158
std::vector< FiguredBassItem * > items
Definition: figuredbass.h:233
qreal textWidth
Definition: figuredbass.h:134
int track() const
Definition: element.h:316
void setParenth2(Parenthesis v)
Definition: figuredbass.h:190
void setPrefix(const Modifier &v)
Definition: figuredbass.h:172
FiguredBassItem & operator=(const FiguredBassItem &)=delete
Element * parent() const
Definition: element.h:192
A complete figured bass indication.
Definition: figuredbass.h:232
virtual ElementType type() const override
Definition: figuredbass.h:156
virtual void setSelected(bool f)
Definition: element.h:208
Definition: score.h:391
ContLine
Definition: figuredbass.h:103
virtual FiguredBass * clone() const override
Definition: figuredbass.h:259
virtual void endEdit(EditData &)
Definition: element.cpp:2086
void undoSetPrefix(Modifier pref)
Definition: figuredbass.cpp:737
virtual Sid getPropertyStyle(Pid) const
Definition: scoreElement.cpp:761
Definition: figuredbass.h:81
Parenthesis parenth1()
Definition: figuredbass.h:183
Parenthesis parenth5()
Definition: figuredbass.h:187
void setSuffix(const Modifier &v)
Definition: figuredbass.h:178
FiguredBassItem::Modifier MusicXML2Modifier(const QString prefix) const
Definition: figuredbass.cpp:807
virtual ElementType type() const override
Definition: figuredbass.h:260
void undoSetParenth5(Parenthesis par)
Definition: figuredbass.cpp:791
virtual Pid propertyId(const QStringRef &xmlName) const override
Definition: element.cpp:1326
virtual QVariant getProperty(Pid propertyId) const override
Definition: figuredbass.cpp:637
Modifier prefix() const
Definition: figuredbass.h:171
Parenthesis parenth4()
Definition: figuredbass.h:186
void undoSetDigit(int digit)
Definition: figuredbass.cpp:748
QString Modifier2MusicXML(FiguredBassItem::Modifier prefix) const
Definition: figuredbass.cpp:835
void setParenth5(Parenthesis v)
Definition: figuredbass.h:193
Modifier _prefix
Definition: figuredbass.h:129
Definition: textbase.h:217
Definition: segment.h:50
void undoSetParenth3(Parenthesis par)
Definition: figuredbass.cpp:781
Definition: aeolus.cpp:26
QString family
Definition: figuredbass.h:213
void undoSetParenth4(Parenthesis par)
Definition: figuredbass.cpp:786
Sid
Definition: style.h:33
FiguredBassItem(Score *s=0, int line=0)
Definition: figuredbass.cpp:67
Definition: xml.h:218
QString displayText() const
Definition: figuredbass.h:201
void setDisplayText(const QString &s)
Definition: figuredbass.h:141
void setParenth3(Parenthesis v)
Definition: figuredbass.h:191
Parenthesis parenth3()
Definition: figuredbass.h:185
void setOnNote(bool val)
Definition: figuredbass.h:293
void setTicks(const Fraction &v)
Definition: figuredbass.h:296
virtual void draw(QPainter *painter) const override
Definition: figuredbass.cpp:572
qreal defLineHeight
Definition: figuredbass.h:216
ContLine contLine() const
Definition: figuredbass.h:180
Definition: element.h:111
QString normalizedText() const
Definition: figuredbass.cpp:320
qreal printedLineLength() const
Definition: figuredbass.h:290
void writeMusicXML(XmlWriter &xml, bool isOriginalFigure, int crEndTick, int fbEndTick) const
Definition: figuredbass.cpp:914
void undoSetSuffix(Modifier suff)
Definition: figuredbass.cpp:756
virtual void read(XmlReader &) override
Definition: figuredbass.cpp:432
QString displayName
Definition: figuredbass.h:214
QString _displayText
Definition: figuredbass.h:126
void setParenth1(Parenthesis v)
Definition: figuredbass.h:189
void setDigit(int val)
Definition: figuredbass.h:175
void undoSetParenth1(Parenthesis par)
Definition: figuredbass.cpp:771
Definition: figuredbass.h:212
Fraction _ticks
Definition: figuredbass.h:236
static const QChar normParenthToChar[int(Parenthesis::NUMOF)]
Definition: figuredbass.h:124
virtual void startEdit(EditData &)
Definition: element.cpp:2010
virtual void setVisible(bool f)
Definition: element.h:211
Modifier suffix() const
Definition: figuredbass.h:177
void undoSetParenth2(Parenthesis par)
Definition: figuredbass.cpp:776
Parenthesis
Definition: figuredbass.h:95
size_t numOfItems() const
Definition: figuredbass.h:292
Definition: fraction.h:46
ElementType
Definition: types.h:34
const FiguredBass * figuredBass() const
Definition: figuredbass.h:167
void appendItem(FiguredBassItem *item)
Definition: figuredbass.h:305
int parseDigit(QString &str)
Definition: figuredbass.cpp:252
int parsePrefixSuffix(QString &str, bool bPrefix)
Definition: figuredbass.cpp:176
void undoSetContLine(ContLine val)
Definition: figuredbass.cpp:765
Parenthesis parenth2()
Definition: figuredbass.h:184
virtual FiguredBassItem * clone() const override
Definition: figuredbass.h:155
int parseParenthesis(QString &str, int parenthIdx)
Definition: figuredbass.cpp:284
qreal lineLength(int idx) const
Definition: figuredbass.h:287
qreal _printedLineLength
Definition: figuredbass.h:238
void setParenth4(Parenthesis v)
Definition: figuredbass.h:192
bool onNote() const
Definition: figuredbass.h:291
Parenthesis parenth[5]
Definition: figuredbass.h:133
virtual void layout() override
Definition: figuredbass.cpp:464
Combination
Definition: figuredbass.h:114