MuseScore  3.4
Music composition and notation
harmony.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2008-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 __HARMONY_H__
14 #define __HARMONY_H__
15 
16 #include "text.h"
17 #include "pitchspelling.h"
18 
19 namespace Ms {
20 
21 struct ChordDescription;
22 class ParsedChord;
23 
24 //---------------------------------------------------------
25 // TextSegment
26 //---------------------------------------------------------
27 
28 struct TextSegment {
29  QFont font;
30  QString text;
31  qreal x, y;
32  bool select;
33 
34  qreal width() const;
35  QRectF boundingRect() const;
36  QRectF tightBoundingRect() const;
37 
38  TextSegment() { select = false; x = y = 0.0; }
39  TextSegment(const QFont& f, qreal _x, qreal _y) : font(f), x(_x), y(_y), select(false) {}
40  TextSegment(const QString&, const QFont&, qreal x, qreal y);
41  void set(const QString&, const QFont&, qreal x, qreal y);
42  void setText(const QString& t) { text = t; }
43  };
44 
45 //---------------------------------------------------------
46 // @@ Harmony
57 //
58 // @P baseTpc int bass note as "tonal pitch class"
59 // @P id int harmony identifier
60 // @P rootTpc int root note as "tonal pitch class"
61 //---------------------------------------------------------
62 
63 struct RenderAction;
64 class HDegree;
65 
66 enum class HarmonyType {
67  STANDARD,
68  ROMAN,
69  NASHVILLE
70  };
71 
72 class Harmony final : public TextBase {
73  int _rootTpc; // root note for chord
74  int _baseTpc; // bass note or chord base; used for "slash" chords
75  // or notation of base note in chord
76  int _id; // >0 = id of matched chord from chord list, if applicable
77  // -1 = invalid chord
78  // <-10000 = private id of generated chord or matched chord with no id
79  QString _function; // numeric representation of root for RNA or Nashville
80  QString _userName; // name as typed by user if applicable
81  QString _textName; // name recognized from chord list, read from score file, or constructed from imported source
82  ParsedChord* _parsedForm; // parsed form of chord
83  bool showSpell = false; // show spell check warning
84  HarmonyType _harmonyType; // used to control rendering, transposition, export, etc.
85 
86  QList<HDegree> _degreeList;
87  QList<QFont> fontList; // temp values used in render()
88  QList<TextSegment*> textList; // rendered chord
89 
90  bool _leftParen, _rightParen; // include opening and/or closing parenthesis
91 
92  mutable QRectF _tbbox;
93 
95  NoteCaseType _rootCase, _baseCase; // case as typed
96  NoteCaseType _rootRenderCase, _baseRenderCase; // case to render
97 
98  void determineRootBaseSpelling();
99  virtual void draw(QPainter*) const override;
100  virtual void drawEditMode(QPainter* p, EditData& ed) override;
101  void render(const QString&, qreal&, qreal&);
102  void render(const QList<RenderAction>& renderList, qreal&, qreal&, int tpc, NoteSpellingType noteSpelling = NoteSpellingType::STANDARD, NoteCaseType noteCase = NoteCaseType::AUTO);
103  virtual Sid getPropertyStyle(Pid) const override;
104 
105  public:
106  Harmony(Score* = 0);
107  Harmony(const Harmony&);
108  ~Harmony();
109  virtual Harmony* clone() const override { return new Harmony(*this); }
110  virtual ElementType type() const override { return ElementType::HARMONY; }
111 
112  void setId(int d) { _id = d; }
113  int id() const { return _id; }
114 
115  void setBaseCase(NoteCaseType c) { _baseCase = c; }
116  void setRootCase(NoteCaseType c) { _rootCase = c; }
117 
118  bool leftParen() const { return _leftParen; }
119  bool rightParen() const { return _rightParen; }
120  void setLeftParen(bool leftParen) { _leftParen = leftParen; }
121  void setRightParen(bool rightParen) { _rightParen = rightParen; }
122 
123  const ChordDescription* descr() const;
124  const ChordDescription* descr(const QString&, const ParsedChord* pc = 0) const;
125  const ChordDescription* getDescription();
126  const ChordDescription* getDescription(const QString&, const ParsedChord* pc = 0);
127  const ChordDescription* generateDescription();
128 
129  void determineRootBaseSpelling(NoteSpellingType& rootSpelling, NoteCaseType& rootCase,
130  NoteSpellingType& baseSpelling, NoteCaseType& baseCase);
131 
132  void textChanged();
133  virtual void layout() override;
134  virtual void layout1() override;
135 
136  virtual bool isEditable() const override { return true; }
137  virtual void startEdit(EditData&) override;
138  virtual bool edit(EditData&) override;
139  virtual void endEdit(EditData&) override;
140 
141  QString hFunction() const { return _function; }
142  QString hUserName() const { return _userName; }
143  QString hTextName() const { return _textName; }
144  int baseTpc() const { return _baseTpc; }
145  void setBaseTpc(int val) { _baseTpc = val; }
146  int rootTpc() const { return _rootTpc; }
147  void setRootTpc(int val) { _rootTpc = val; }
148  void setTextName(const QString& s) { _textName = s; }
149  void setFunction(const QString& s) { _function = s; }
150  QString rootName();
151  QString baseName();
152  void addDegree(const HDegree& d);
153  int numberOfDegrees() const;
154  HDegree degree(int i) const;
155  void clearDegrees();
156  const QList<HDegree>& degreeList() const;
157  const ParsedChord* parsedForm();
158  HarmonyType harmonyType() const { return _harmonyType; }
159  void setHarmonyType(HarmonyType val);
160 
161  virtual void write(XmlWriter& xml) const override;
162  virtual void read(XmlReader&) override;
163  QString harmonyName() const;
164  void render();
165 
166  const ChordDescription* parseHarmony(const QString& s, int* root, int* base, bool syntaxOnly = false);
167 
168  const QString& extensionName() const;
169 
170  QString xmlKind() const;
171  QString musicXmlText() const;
172  QString xmlSymbols() const;
173  QString xmlParens() const;
174  QStringList xmlDegrees() const;
175 
176  void resolveDegreeList();
177 
178  virtual qreal baseLine() const override;
179 
180  const ChordDescription* fromXml(const QString&, const QString&, const QString&, const QString&, const QList<HDegree>&);
181  const ChordDescription* fromXml(const QString& s, const QList<HDegree>&);
182  const ChordDescription* fromXml(const QString& s);
183  virtual void spatiumChanged(qreal oldValue, qreal newValue) override;
184  virtual void localSpatiumChanged(qreal oldValue, qreal newValue) override;
185  void setHarmony(const QString& s);
186  void calculateBoundingRect();
187 
188  virtual QString userName() const override;
189  virtual QString accessibleInfo() const override;
190  virtual QString screenReaderInfo() const override;
191 
192  virtual bool acceptDrop(EditData&) const override;
193  virtual Element* drop(EditData&) override;
194 
195  virtual QVariant getProperty(Pid propertyId) const override;
196  virtual bool setProperty(Pid propertyId, const QVariant& v) override;
197  virtual QVariant propertyDefault(Pid id) const override;
198  };
199 
200 } // namespace Ms
201 #endif
202 
Definition: chordlist.h:174
Definition: harmony.h:28
QString _function
Definition: harmony.h:79
HarmonyType harmonyType() const
Definition: harmony.h:158
int _id
Definition: harmony.h:76
Pid
Definition: property.h:62
Definition: xml.h:67
TextSegment()
Definition: harmony.h:38
qreal width() const
Definition: harmony.cpp:1275
int id() const
Definition: harmony.h:113
QFont font
Definition: harmony.h:29
Definition: chordlist.h:89
virtual bool isEditable() const override
Definition: harmony.h:136
void setRootTpc(int val)
Definition: harmony.h:147
int _baseTpc
Definition: harmony.h:74
bool _rightParen
Definition: harmony.h:90
Base class of score layout elements.
Definition: element.h:158
Definition: chordlist.h:125
void setText(const QString &t)
Definition: harmony.h:42
NoteCaseType _rootCase
Definition: harmony.h:95
QList< HDegree > _degreeList
Definition: harmony.h:86
int baseTpc() const
Definition: harmony.h:144
TextSegment(const QFont &f, qreal _x, qreal _y)
Definition: harmony.h:39
NoteCaseType
Definition: pitchspelling.h:68
virtual Harmony * clone() const override
Definition: harmony.h:109
int rootTpc() const
Definition: harmony.h:146
void setBaseTpc(int val)
Definition: harmony.h:145
Definition: score.h:391
void setId(int d)
Definition: harmony.h:112
bool select
Definition: harmony.h:32
void setBaseCase(NoteCaseType c)
Definition: harmony.h:115
HarmonyType
Definition: harmony.h:66
NoteSpellingType
Definition: pitchspelling.h:67
void setTextName(const QString &s)
Definition: harmony.h:148
bool rightParen() const
Definition: harmony.h:119
QString text
Definition: harmony.h:30
QList< QFont > fontList
Definition: harmony.h:87
QRectF _tbbox
Definition: harmony.h:92
QRectF boundingRect() const
Definition: harmony.cpp:1296
QString _textName
Definition: harmony.h:81
Definition: textbase.h:217
Definition: aeolus.cpp:26
Sid
Definition: style.h:33
void setRootCase(NoteCaseType c)
Definition: harmony.h:116
Definition: xml.h:218
void setLeftParen(bool leftParen)
Definition: harmony.h:120
void setFunction(const QString &s)
Definition: harmony.h:149
QString hUserName() const
Definition: harmony.h:142
QList< TextSegment * > textList
Definition: harmony.h:88
Definition: harmony.h:72
NoteSpellingType _rootSpelling
Definition: harmony.h:94
Definition: chordlist.h:30
Definition: element.h:111
int _rootTpc
Definition: harmony.h:73
QString hFunction() const
Definition: harmony.h:141
void setRightParen(bool rightParen)
Definition: harmony.h:121
virtual ElementType type() const override
Definition: harmony.h:110
qreal y
Definition: harmony.h:31
int tpc(int idx, int pitch, int opt)
Definition: pitchspelling.cpp:539
ParsedChord * _parsedForm
Definition: harmony.h:82
QRectF tightBoundingRect() const
Definition: harmony.cpp:1306
ElementType
Definition: types.h:34
bool leftParen() const
Definition: harmony.h:118
QString hTextName() const
Definition: harmony.h:143
qreal x
Definition: harmony.h:31
HarmonyType _harmonyType
Definition: harmony.h:84
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
NoteCaseType _rootRenderCase
Definition: harmony.h:96
QString _userName
Definition: harmony.h:80