MuseScore  3.4
Music composition and notation
chordlist.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 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 __CHORDLIST_H__
14 #define __CHORDLIST_H__
15 
16 namespace Ms {
17 
18 class XmlWriter;
19 class XmlReader;
20 class ChordList;
21 
22 //---------------------------------------------------------
23 // class HDegree
24 //---------------------------------------------------------
25 
26 enum class HDegreeType : char {
28  };
29 
30 class HDegree {
31  int _value;
32  int _alter; // -1, 0, 1 (b - - #)
34 
35  public:
36  HDegree() { _value = 0; _alter = 0; _type = HDegreeType::UNDEF; }
37  HDegree(int v, int a, HDegreeType t) { _value = v; _alter = a; _type = t; }
38  int value() const { return _value; }
39  int alter() const { return _alter; }
40  HDegreeType type() const { return _type; }
41  QString text() const;
42  };
43 
44 //---------------------------------------------------------
45 // HChord
46 //---------------------------------------------------------
47 
48 class HChord {
49  QString str;
50 
51  protected:
52  int keys;
53 
54  public:
55  HChord() { keys = 0; }
56  HChord(int k) { keys = k; }
57  HChord(int a, int b, int c=-1, int d=-1, int e=-1, int f=-1, int g=-1,
58  int h=-1, int i=-1, int k=-1, int l=-1);
59  HChord(const QString&);
60 
61  void rotate(int semiTones);
62 
63  bool contains(int key) const { // key in chord?
64  return (1 << (key % 12)) & keys;
65  }
66  HChord& operator+= (int key) {
67  keys |= (1 << (key % 12));
68  return *this;
69  }
70  HChord& operator-= (int key) {
71  keys &= ~(1 << (key % 12));
72  return *this;
73  }
74  bool operator==(const HChord& o) const { return (keys == o.keys); }
75  bool operator!=(const HChord& o) const { return (keys != o.keys); }
76 
77  int getKeys() const { return keys; }
78  void print() const;
79 
80  QString name(int tpc) const;
81  QString voicing() const;
82  void add(const QList<HDegree>& degreeList);
83  };
84 
85 //---------------------------------------------------------
86 // RenderAction
87 //---------------------------------------------------------
88 
89 struct RenderAction {
90  enum class RenderActionType : char {
91  SET, MOVE, PUSH, POP,
93  };
94 
96  qreal movex, movey; // MOVE
97  QString text; // SET
98 
101  void print() const;
102  };
103 
104 //---------------------------------------------------------
105 // ChordToken
106 //---------------------------------------------------------
107 
108 enum class ChordTokenClass : char {
110  };
111 
112 class ChordToken {
113  public:
115  QStringList names;
116  QList<RenderAction> renderList;
117  void read(XmlReader&);
118  void write(XmlWriter&) const;
119  };
120 
121 //---------------------------------------------------------
122 // ParsedChord
123 //---------------------------------------------------------
124 
125 class ParsedChord {
126  public:
127  bool parse(const QString&, const ChordList*, bool syntaxOnly = false, bool preferMinor = false);
128  QString fromXml(const QString&, const QString&, const QString&, const QString&, const QList<HDegree>&, const ChordList*);
129  const QList<RenderAction>& renderList(const ChordList*);
130  bool parseable() const { return _parseable; }
131  bool understandable() const { return _understandable; }
132  const QString& name() const { return _name; }
133  const QString& quality() const { return _quality; }
134  const QString& extension() const { return _extension; }
135  const QString& modifiers() const { return _modifiers; }
136  const QString& xmlKind() const { return _xmlKind; }
137  const QString& xmlText() const { return _xmlText; }
138  const QString& xmlSymbols() const { return _xmlSymbols; }
139  const QString& xmlParens() const { return _xmlParens; }
140  const QStringList& xmlDegrees() const { return _xmlDegrees; }
141  int keys() const { return chord.getKeys(); }
142  const QString& handle() const { return _handle; }
143  operator QString() const { return _handle; }
144  bool operator==(const ParsedChord& c) const { return (this->_handle == c._handle); }
145  bool operator!=(const ParsedChord& c) const { return !(*this == c); }
146  ParsedChord();
147  private:
148  QString _name;
149  QString _handle;
150  QString _quality;
151  QString _extension;
152  QString _modifiers;
153  QStringList _modifierList;
154  QList<ChordToken> _tokenList;
155  QList<RenderAction> _renderList;
156  QString _xmlKind;
157  QString _xmlText;
158  QString _xmlSymbols;
159  QString _xmlParens;
160  QStringList _xmlDegrees;
161  QStringList major, minor, diminished, augmented, lower, raise, mod1, mod2, symbols;
165  void configure(const ChordList*);
166  void correctXmlText(const QString& s = "");
167  void addToken(QString, ChordTokenClass);
168  };
169 
170 //---------------------------------------------------------
171 // ChordDescription
172 //---------------------------------------------------------
173 
175  int id; // Chord id number (Band In A Box Chord Number)
176  QStringList names; // list of alternative chord names
177  // that will by recognized from keyboard entry (without root/base)
178  QList<ParsedChord> parsedChords;
179  // parsed forms of primary name (optionally also include parsed forms of other names)
180  QString xmlKind; // MusicXml: kind
181  QString xmlText; // MusicXml: kind text=
182  QString xmlSymbols; // MusicXml: kind use-symbols=
183  QString xmlParens; // MusicXml: kind parentheses-degrees=
184  QStringList xmlDegrees; // MusicXml: list of degrees (if any)
185  HChord chord; // C based chord
186  QList<RenderAction> renderList;
187  bool generated;
189  bool exportOk;
190  QString _quality;
191 
192  public:
194  ChordDescription(int);
195  ChordDescription(const QString&);
196  QString quality() const { return _quality; }
197  void complete(ParsedChord* pc, const ChordList*);
198  void read(XmlReader&);
199  void write(XmlWriter&) const;
200  };
201 
202 //---------------------------------------------------------
203 // ChordSymbol
204 //---------------------------------------------------------
205 
206 struct ChordSymbol {
207  int fontIdx;
208  QString name;
209  QString value;
210  QChar code;
211 
212  ChordSymbol() { fontIdx = -1; }
213  bool isValid() const { return fontIdx != -1; }
214  };
215 
216 //---------------------------------------------------------
217 // ChordFont
218 //---------------------------------------------------------
219 
220 struct ChordFont {
221  QString family;
222  QString fontClass;
223  qreal mag;
224  };
225 
226 //---------------------------------------------------------
227 // ChordList
228 //---------------------------------------------------------
229 
230 class ChordList : public QMap<int, ChordDescription> {
231  QMap<QString, ChordSymbol> symbols;
232  bool _autoAdjust = false;
233  qreal _nmag = 1.0, _nadjust = 0.0;
234  qreal _emag = 1.0, _eadjust = 0.0;
235  qreal _mmag = 1.0, _madjust = 0.0;
236 
237  public:
238  QList<ChordFont> fonts;
239  QList<RenderAction> renderListRoot;
240  QList<RenderAction> renderListFunction;
241  QList<RenderAction> renderListBase;
242  QList<ChordToken> chordTokenList;
243  static int privateID;
244 
245  bool autoAdjust() const { return _autoAdjust; }
246  qreal nominalMag() const { return _nmag; }
247  qreal nominalAdjust() const { return _nadjust; }
248  void configureAutoAdjust(qreal emag = 1.0, qreal eadjust = 0.0, qreal mmag = 1.0, qreal madjust = 0.0);
249  qreal position(const QStringList& names, ChordTokenClass ctc) const;
250 
251  void write(XmlWriter& xml) const;
252  void read(XmlReader&);
253  bool read(const QString&);
254  bool write(const QString&) const;
255  bool loaded() const;
256  void unload();
257  ChordSymbol symbol(const QString& s) const { return symbols.value(s); }
258  };
259 
260 
261 } // namespace Ms
262 #endif
263 
QStringList xmlDegrees
Definition: chordlist.h:184
HChord chord
Definition: chordlist.h:185
RenderActionType type
Definition: chordlist.h:95
Definition: chordlist.h:174
RenderAction()
Definition: chordlist.h:99
QString xmlText
Definition: chordlist.h:181
bool operator==(const ParsedChord &c) const
Definition: chordlist.h:144
HDegree()
Definition: chordlist.h:36
QString fontClass
Definition: chordlist.h:222
int fontIdx
Definition: chordlist.h:207
Definition: xml.h:67
QString name
Definition: chordlist.h:208
HDegreeType type() const
Definition: chordlist.h:40
Definition: editdrumset.cpp:32
RenderActionType
Definition: chordlist.h:90
QStringList names
Definition: chordlist.h:176
Definition: chordlist.h:206
QString xmlKind
Definition: chordlist.h:180
int _alter
Definition: chordlist.h:32
Definition: chordlist.h:89
Definition: chordlist.h:112
QChar code
Definition: chordlist.h:210
Definition: chordlist.h:230
QString xmlSymbols
Definition: chordlist.h:182
QString xmlParens
Definition: chordlist.h:183
const QString & handle() const
Definition: chordlist.h:142
bool autoAdjust() const
Definition: chordlist.h:245
HDegreeType _type
Definition: chordlist.h:33
QList< ChordToken > chordTokenList
Definition: chordlist.h:242
QList< RenderAction > renderListRoot
Definition: chordlist.h:239
bool _parseable
Definition: chordlist.h:163
int _value
Definition: chordlist.h:31
QList< ChordToken > _tokenList
Definition: chordlist.h:154
QString _quality
Definition: chordlist.h:150
HChord chord
Definition: chordlist.h:162
Definition: chordlist.h:125
bool parseable() const
Definition: chordlist.h:130
QString _modifiers
Definition: chordlist.h:152
const QString & xmlKind() const
Definition: chordlist.h:136
const QString & xmlParens() const
Definition: chordlist.h:139
QString _xmlText
Definition: chordlist.h:157
bool contains(int key) const
Definition: chordlist.h:63
HChord(int k)
Definition: chordlist.h:56
bool renderListGenerated
Definition: chordlist.h:188
RenderAction(RenderActionType t)
Definition: chordlist.h:100
const QString & xmlSymbols() const
Definition: chordlist.h:138
QString text
Definition: chordlist.h:97
QString family
Definition: chordlist.h:221
QString _xmlKind
Definition: chordlist.h:156
QStringList _modifierList
Definition: chordlist.h:153
qreal nominalMag() const
Definition: chordlist.h:246
ChordSymbol symbol(const QString &s) const
Definition: chordlist.h:257
QMap< QString, ChordSymbol > symbols
Definition: chordlist.h:231
ChordTokenClass
Definition: chordlist.h:108
ChordSymbol()
Definition: chordlist.h:212
int alter() const
Definition: chordlist.h:39
const QString & xmlText() const
Definition: chordlist.h:137
qreal nominalAdjust() const
Definition: chordlist.h:247
const QString & quality() const
Definition: chordlist.h:133
QString _extension
Definition: chordlist.h:151
int keys() const
Definition: chordlist.h:141
QList< RenderAction > renderListBase
Definition: chordlist.h:241
QString value
Definition: chordlist.h:209
ChordTokenClass tokenClass
Definition: chordlist.h:114
Definition: aeolus.cpp:26
HDegreeType
Definition: chordlist.h:26
bool generated
Definition: chordlist.h:187
qreal mag
Definition: chordlist.h:223
bool _understandable
Definition: chordlist.h:164
int id
Definition: chordlist.h:175
const QString & modifiers() const
Definition: chordlist.h:135
QString _quality
Definition: chordlist.h:190
QList< RenderAction > renderListFunction
Definition: chordlist.h:240
const QString & extension() const
Definition: chordlist.h:134
bool operator==(const HChord &o) const
Definition: chordlist.h:74
Definition: xml.h:218
bool exportOk
Definition: chordlist.h:189
QString _name
Definition: chordlist.h:148
const QStringList & xmlDegrees() const
Definition: chordlist.h:140
Definition: xmlwriter.h:26
QList< ParsedChord > parsedChords
Definition: chordlist.h:178
QString _xmlParens
Definition: chordlist.h:159
static int privateID
Definition: chordlist.h:243
Definition: chordlist.h:30
int keys
Definition: chordlist.h:52
qreal movey
Definition: chordlist.h:96
Definition: chordlist.h:48
QString _xmlSymbols
Definition: chordlist.h:158
QList< ChordFont > fonts
Definition: chordlist.h:238
Definition: xmlreader.h:28
QList< RenderAction > renderList
Definition: chordlist.h:116
int tpc(int idx, int pitch, int opt)
Definition: pitchspelling.cpp:539
QStringList names
Definition: chordlist.h:115
const QString & name() const
Definition: chordlist.h:132
HChord()
Definition: chordlist.h:55
bool operator!=(const ParsedChord &c) const
Definition: chordlist.h:145
QStringList symbols
Definition: chordlist.h:161
Definition: chordlist.h:220
bool operator!=(const HChord &o) const
Definition: chordlist.h:75
QStringList _xmlDegrees
Definition: chordlist.h:160
ChordDescription()
Definition: chordlist.h:193
int getKeys() const
Definition: chordlist.h:77
QString quality() const
Definition: chordlist.h:196
QList< RenderAction > _renderList
Definition: chordlist.h:155
QList< RenderAction > renderList
Definition: chordlist.h:186
QString _handle
Definition: chordlist.h:149
HDegree(int v, int a, HDegreeType t)
Definition: chordlist.h:37
int value() const
Definition: chordlist.h:38
bool isValid() const
Definition: chordlist.h:213
QString str
Definition: chordlist.h:49
bool understandable() const
Definition: chordlist.h:131