Skip to content

Commit aa145fe

Browse files
committed
Support key signature
1 parent 0841424 commit aa145fe

File tree

64 files changed

+2502
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2502
-83
lines changed

src/libs/application/dspxmodel/src/BasicModelStrategyEntity_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace dspx {
6464
switch (type) {
6565
case ModelStrategy::EI_AudioClip:
6666
case ModelStrategy::EI_Global:
67+
case ModelStrategy::EI_KeySignature:
6768
case ModelStrategy::EI_Label:
6869
case ModelStrategy::EI_Note:
6970
case ModelStrategy::EI_Param:
@@ -81,6 +82,7 @@ namespace dspx {
8182
obj->type = type;
8283
break;
8384
case ModelStrategy::ES_Clips:
85+
case ModelStrategy::ES_KeySignatures:
8486
case ModelStrategy::ES_Labels:
8587
case ModelStrategy::ES_Notes:
8688
case ModelStrategy::ES_ParamCurveAnchorNodes:

src/libs/application/dspxmodel/src/Global.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ namespace dspx {
5050
Q_ASSERT(centShift >= -50 && centShift <= 50);
5151
d->pModel->strategy->setEntityProperty(d->handle, ModelStrategy::P_CentShift, centShift);
5252
}
53-
Global::AccidentalType Global::accidentalType() const {
54-
Q_D(const Global);
55-
return static_cast<AccidentalType>(d->pModel->accidentalType);
56-
}
57-
void Global::setAccidentalType(AccidentalType accidentalType) {
58-
Q_D(Global);
59-
Q_ASSERT(accidentalType == Flat || accidentalType == Sharp);
60-
d->pModel->strategy->setEntityProperty(d->handle, ModelStrategy::P_AccidentalType, accidentalType);
61-
}
6253
QString Global::editorId() const {
6354
Q_D(const Global);
6455
return d->pModel->editorId;

src/libs/application/dspxmodel/src/Global.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ namespace dspx {
2727
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
2828
Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
2929
Q_PROPERTY(int centShift READ centShift WRITE setCentShift NOTIFY centShiftChanged)
30-
Q_PROPERTY(AccidentalType accidentalType READ accidentalType WRITE setAccidentalType NOTIFY accidentalTypeChanged)
3130
Q_PROPERTY(QString editorId READ editorId WRITE setEditorId NOTIFY editorIdChanged)
3231
Q_PROPERTY(QString editorName READ editorName WRITE setEditorName NOTIFY editorNameChanged)
3332

@@ -43,14 +42,6 @@ namespace dspx {
4342
int centShift() const;
4443
void setCentShift(int centShift);
4544

46-
enum AccidentalType {
47-
Flat,
48-
Sharp,
49-
};
50-
Q_ENUM(AccidentalType)
51-
AccidentalType accidentalType() const;
52-
void setAccidentalType(AccidentalType accidentalType);
53-
5445
QString editorId() const;
5546
void setEditorId(const QString &editorId);
5647

@@ -64,7 +55,6 @@ namespace dspx {
6455
void nameChanged(const QString &name);
6556
void authorChanged(const QString &author);
6657
void centShiftChanged(int centShift);
67-
void accidentalTypeChanged(AccidentalType accidentalType);
6858
void editorIdChanged(const QString &editorId);
6959
void editorNameChanged(const QString &editorName);
7060

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#include "KeySignature.h"
2+
#include "KeySignature_p.h"
3+
4+
#include <QVariant>
5+
#include <QJsonObject>
6+
7+
#include <dspxmodel/Model.h>
8+
#include <dspxmodel/ModelStrategy.h>
9+
#include <dspxmodel/KeySignatureSequence.h>
10+
11+
namespace dspx {
12+
13+
void KeySignaturePrivate::setKeySignatureSequence(KeySignature *item, KeySignatureSequence *keySignatureSequence) {
14+
auto d = item->d_func();
15+
if (d->keySignatureSequence != keySignatureSequence) {
16+
d->keySignatureSequence = keySignatureSequence;
17+
Q_EMIT item->keySignatureSequenceChanged();
18+
}
19+
}
20+
21+
void KeySignaturePrivate::setPreviousItem(KeySignature *item, KeySignature *previousItem) {
22+
auto d = item->d_func();
23+
if (d->previousItem != previousItem) {
24+
d->previousItem = previousItem;
25+
Q_EMIT item->previousItemChanged();
26+
}
27+
}
28+
29+
void KeySignaturePrivate::setNextItem(KeySignature *item, KeySignature *nextItem) {
30+
auto d = item->d_func();
31+
if (d->nextItem != nextItem) {
32+
d->nextItem = nextItem;
33+
Q_EMIT item->nextItemChanged();
34+
}
35+
}
36+
37+
KeySignature::KeySignature(Handle handle, Model *model) : EntityObject(handle, model), d_ptr(new KeySignaturePrivate) {
38+
Q_D(KeySignature);
39+
Q_ASSERT(model->strategy()->getEntityType(handle) == ModelStrategy::EI_KeySignature);
40+
d->q_ptr = this;
41+
d->pos = model->strategy()->getEntityProperty(handle, ModelStrategy::P_Position).toInt();
42+
d->mode = model->strategy()->getEntityProperty(handle, ModelStrategy::P_Mode).toInt();
43+
d->tonality = model->strategy()->getEntityProperty(handle, ModelStrategy::P_Tonality).toInt();
44+
d->accidentalType = static_cast<AccidentalType>(model->strategy()->getEntityProperty(handle, ModelStrategy::P_AccidentalType).toInt());
45+
}
46+
47+
KeySignature::~KeySignature() = default;
48+
49+
int KeySignature::pos() const {
50+
Q_D(const KeySignature);
51+
return d->pos;
52+
}
53+
54+
void KeySignature::setPos(int pos) {
55+
Q_D(KeySignature);
56+
Q_ASSERT(pos >= 0);
57+
model()->strategy()->setEntityProperty(handle(), ModelStrategy::P_Position, pos);
58+
}
59+
60+
int KeySignature::mode() const {
61+
Q_D(const KeySignature);
62+
return d->mode;
63+
}
64+
65+
void KeySignature::setMode(int mode) {
66+
Q_D(KeySignature);
67+
Q_ASSERT(mode >= 0 && mode <= 4095);
68+
model()->strategy()->setEntityProperty(handle(), ModelStrategy::P_Mode, mode);
69+
}
70+
71+
int KeySignature::tonality() const {
72+
Q_D(const KeySignature);
73+
return d->tonality;
74+
}
75+
76+
void KeySignature::setTonality(int tonality) {
77+
Q_D(KeySignature);
78+
Q_ASSERT(tonality >= 0 && tonality <= 11);
79+
model()->strategy()->setEntityProperty(handle(), ModelStrategy::P_Tonality, tonality);
80+
}
81+
82+
KeySignature::AccidentalType KeySignature::accidentalType() const {
83+
Q_D(const KeySignature);
84+
return d->accidentalType;
85+
}
86+
87+
void KeySignature::setAccidentalType(AccidentalType accidentalType) {
88+
Q_D(KeySignature);
89+
Q_ASSERT(accidentalType == Flat || accidentalType == Sharp);
90+
model()->strategy()->setEntityProperty(handle(), ModelStrategy::P_AccidentalType, static_cast<int>(accidentalType));
91+
}
92+
93+
KeySignatureSequence *KeySignature::keySignatureSequence() const {
94+
Q_D(const KeySignature);
95+
return d->keySignatureSequence;
96+
}
97+
98+
KeySignature *KeySignature::previousItem() const {
99+
Q_D(const KeySignature);
100+
return d->previousItem;
101+
}
102+
103+
KeySignature *KeySignature::nextItem() const {
104+
Q_D(const KeySignature);
105+
return d->nextItem;
106+
}
107+
108+
QJsonObject KeySignature::toQDspx() const {
109+
return {
110+
{"pos", pos()},
111+
{"mode", mode()},
112+
{"tonality", tonality()},
113+
{"accidentalType", accidentalType()}
114+
};
115+
}
116+
117+
void KeySignature::fromQDspx(const QJsonObject &keySignature) {
118+
auto pos = keySignature.value("pos").toInt();
119+
pos = qMax(0, pos);
120+
setPos(pos);
121+
auto mode = keySignature.value("mode").toInt();
122+
if (mode < 0 || mode > 4095) {
123+
mode = 0;
124+
}
125+
setMode(mode);
126+
auto tonality = keySignature.value("tonality").toInt();
127+
if (tonality < 0 || tonality > 11) {
128+
tonality = 0;
129+
}
130+
setTonality(tonality);
131+
auto accidentalType = keySignature.value("accidentalType").toInt();
132+
if (accidentalType != Flat && accidentalType != Sharp) {
133+
accidentalType = Flat;
134+
}
135+
setAccidentalType(static_cast<AccidentalType>(accidentalType));
136+
}
137+
138+
void KeySignature::handleSetEntityProperty(int property, const QVariant &value) {
139+
Q_D(KeySignature);
140+
switch (property) {
141+
case ModelStrategy::P_Position: {
142+
d->pos = value.toInt();
143+
Q_EMIT posChanged(d->pos);
144+
break;
145+
}
146+
case ModelStrategy::P_Mode: {
147+
d->mode = value.toInt();
148+
Q_EMIT modeChanged(d->mode);
149+
break;
150+
}
151+
case ModelStrategy::P_Tonality: {
152+
d->tonality = value.toInt();
153+
Q_EMIT tonalityChanged(d->tonality);
154+
break;
155+
}
156+
case ModelStrategy::P_AccidentalType: {
157+
d->accidentalType = static_cast<AccidentalType>(value.toInt());
158+
Q_EMIT accidentalTypeChanged(d->accidentalType);
159+
break;
160+
}
161+
default:
162+
Q_UNREACHABLE();
163+
}
164+
}
165+
166+
}
167+
168+
#include "moc_KeySignature.cpp"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#ifndef DIFFSCOPE_DSPX_MODEL_KEYSIGNATURE_H
2+
#define DIFFSCOPE_DSPX_MODEL_KEYSIGNATURE_H
3+
4+
#include <qqmlintegration.h>
5+
6+
#include <dspxmodel/EntityObject.h>
7+
8+
namespace QDspx {
9+
struct KeySignature;
10+
}
11+
12+
namespace dspx {
13+
14+
class KeySignatureSequence;
15+
class KeySignaturePrivate;
16+
17+
class DSPX_MODEL_EXPORT KeySignature : public EntityObject {
18+
Q_OBJECT
19+
QML_ELEMENT
20+
QML_UNCREATABLE("")
21+
Q_DECLARE_PRIVATE(KeySignature);
22+
Q_PROPERTY(int pos READ pos WRITE setPos NOTIFY posChanged)
23+
Q_PROPERTY(int mode READ mode WRITE setMode NOTIFY modeChanged)
24+
Q_PROPERTY(int tonality READ tonality WRITE setTonality NOTIFY tonalityChanged)
25+
Q_PROPERTY(AccidentalType accidentalType READ accidentalType WRITE setAccidentalType NOTIFY accidentalTypeChanged)
26+
public:
27+
enum AccidentalType {
28+
Flat = 0,
29+
Sharp = 1
30+
};
31+
Q_ENUM(AccidentalType)
32+
33+
~KeySignature() override;
34+
35+
int pos() const;
36+
void setPos(int pos);
37+
38+
int mode() const;
39+
void setMode(int mode);
40+
41+
int tonality() const;
42+
void setTonality(int tonality);
43+
44+
AccidentalType accidentalType() const;
45+
void setAccidentalType(AccidentalType accidentalType);
46+
47+
KeySignatureSequence *keySignatureSequence() const;
48+
49+
KeySignature *previousItem() const;
50+
KeySignature *nextItem() const;
51+
52+
QJsonObject toQDspx() const;
53+
void fromQDspx(const QJsonObject &keySignature);
54+
55+
Q_SIGNALS:
56+
void posChanged(int pos);
57+
void modeChanged(int mode);
58+
void tonalityChanged(int tonality);
59+
void accidentalTypeChanged(AccidentalType accidentalType);
60+
void keySignatureSequenceChanged();
61+
void previousItemChanged();
62+
void nextItemChanged();
63+
64+
protected:
65+
void handleSetEntityProperty(int property, const QVariant &value) override;
66+
67+
private:
68+
friend class ModelPrivate;
69+
explicit KeySignature(Handle handle, Model *model);
70+
QScopedPointer<KeySignaturePrivate> d_ptr;
71+
};
72+
73+
}
74+
75+
#endif //DIFFSCOPE_DSPX_MODEL_KEYSIGNATURE_H

0 commit comments

Comments
 (0)