/
harmony.h
190 lines (153 loc) · 7.51 KB
/
harmony.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2008-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#ifndef __HARMONY_H__
#define __HARMONY_H__
#include "text.h"
#include "pitchspelling.h"
namespace Ms {
struct ChordDescription;
class ParsedChord;
//---------------------------------------------------------
// TextSegment
//---------------------------------------------------------
struct TextSegment {
QFont font;
QString text;
qreal x, y;
bool select;
qreal width() const;
QRectF boundingRect() const;
QRectF tightBoundingRect() const;
TextSegment() { select = false; x = y = 0.0; }
TextSegment(const QFont& f, qreal _x, qreal _y) : font(f), x(_x), y(_y), select(false) {}
TextSegment(const QString&, const QFont&, qreal x, qreal y);
void set(const QString&, const QFont&, qreal x, qreal y);
void setText(const QString& t) { text = t; }
};
//---------------------------------------------------------
// @@ Harmony
/// root note and bass note are notated as
/// "tonal pitch class":
///
/// bb b - # ##
/// 0, 7, 14, 21, 28, // C
/// 2, 9, 16, 23, 30, // D
/// 4, 11, 18, 25, 32, // E
/// -1, 6, 13, 20, 27, // F
/// 1, 8, 15, 22, 29, // G
/// 3, 10, 17, 24, 31, // A
/// 5, 12, 19, 26, 33, // B
//
// @P id int harmony identifier
// @P rootTpc int root note as "tonal pitch class"
// @P baseTpc int bass note as "tonal pitch class"
//---------------------------------------------------------
struct RenderAction;
class HDegree;
class Harmony : public Text {
Q_OBJECT
Q_PROPERTY(int id READ id WRITE setId)
Q_PROPERTY(int rootTpc READ rootTpc WRITE setRootTpc)
Q_PROPERTY(int baseTpc READ baseTpc WRITE setBaseTpc)
int _rootTpc; // root note for chord
int _baseTpc; // bass note or chord base; used for "slash" chords
// or notation of base note in chord
int _id; // >0 = id of matched chord from chord list, if applicable
// -1 = invalid chord
// <-10000 = private id of generated chord or matched chord with no id
QString _userName; // name as typed by user if applicable
QString _textName; // name recognized from chord list, read from score file, or constructed from imported source
ParsedChord* _parsedForm; // parsed form of chord
QList<HDegree> _degreeList;
QList<QFont> fontList; // temp values used in render()
QList<TextSegment*> textList; // rendered chord
bool _leftParen, _rightParen; // include opening and/or closing parenthesis
mutable QRectF _tbbox;
NoteSpellingType _rootSpelling, _baseSpelling;
bool _rootLowerCase, _baseLowerCase;
void determineRootBaseSpelling();
virtual void draw(QPainter*) const;
void render(const QString&, qreal&, qreal&);
void render(const QList<RenderAction>& renderList, qreal&, qreal&, int tpc, NoteSpellingType spelling = NoteSpellingType::STANDARD, bool lowerCase = false);
virtual void styleChanged() override { render(); }
virtual void setTextStyle(const TextStyle& st) override;
public:
Harmony(Score* = 0);
Harmony(const Harmony&);
~Harmony();
virtual Harmony* clone() const { return new Harmony(*this); }
virtual Element::Type type() const { return Element::Type::HARMONY; }
virtual bool systemFlag() const override { return false; }
void setId(int d) { _id = d; }
int id() const { return _id; }
bool leftParen() const { return _leftParen; }
bool rightParen() const { return _rightParen; }
void setLeftParen(bool leftParen) { _leftParen = leftParen; }
void setRightParen(bool rightParen) { _rightParen = rightParen; }
const ChordDescription* descr() const;
const ChordDescription* descr(const QString&, const ParsedChord* pc = 0) const;
const ChordDescription* getDescription();
const ChordDescription* getDescription(const QString&, const ParsedChord* pc = 0);
const ChordDescription* generateDescription();
void determineRootBaseSpelling(NoteSpellingType& rootSpelling, bool& rootLowerCase, NoteSpellingType& baseSpelling, bool& baseLowerCase);
virtual void textChanged() override;
virtual void layout();
const QRectF& bboxtight() const { return _tbbox; }
QRectF& bboxtight() { return _tbbox; }
void setbboxtight(const QRectF& r) const { _tbbox = r; }
virtual bool isEditable() const { return true; }
virtual void startEdit(MuseScoreView*, const QPointF&);
virtual bool edit(MuseScoreView*, int grip, int key, Qt::KeyboardModifiers, const QString& s);
virtual void endEdit();
QString hUserName() const { return _userName; }
QString hTextName() const { return _textName; }
int baseTpc() const { return _baseTpc; }
void setBaseTpc(int val) { _baseTpc = val; }
int rootTpc() const { return _rootTpc; }
void setRootTpc(int val) { _rootTpc = val; }
void setTextName(const QString& s) { _textName = s; }
QString rootName();
QString baseName();
void addDegree(const HDegree& d);
int numberOfDegrees() const;
HDegree degree(int i) const;
void clearDegrees();
const QList<HDegree>& degreeList() const;
const ParsedChord* parsedForm();
virtual void write(Xml& xml) const;
virtual void read(XmlReader&);
QString harmonyName();
void render(const TextStyle* ts = 0);
const ChordDescription* parseHarmony(const QString& s, int* root, int* base, bool syntaxOnly = false);
const QString& extensionName() const;
QString xmlKind() const;
QString xmlText() const;
QString xmlSymbols() const;
QString xmlParens() const;
QStringList xmlDegrees() const;
void resolveDegreeList();
virtual bool isEmpty() const;
virtual qreal baseLine() const;
const ChordDescription* fromXml(const QString&, const QString&, const QString&, const QString&, const QList<HDegree>&);
const ChordDescription* fromXml(const QString& s, const QList<HDegree>&);
const ChordDescription* fromXml(const QString& s);
virtual void spatiumChanged(qreal oldValue, qreal newValue);
virtual void textStyleChanged();
virtual QLineF dragAnchor() const;
void setHarmony(const QString& s);
virtual QPainterPath shape() const;
void calculateBoundingRect();
virtual QString accessibleInfo() override;
virtual QString screenReaderInfo() override;
};
} // namespace Ms
#endif