Skip to content

Commit 48beed8

Browse files
committed
Added proofreading via notehead colours
1 parent e040ebf commit 48beed8

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

src/engraving/libmscore/harppedaldiagram.cpp

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ static const ElementStyle harpPedalTextDiagramStyle {
6666
};
6767

6868
// HarpPedalDiagram
69+
void HarpPedalDiagram::setPlayablePitches()
70+
{
71+
std::vector<int> playablePitches;
72+
const std::map<HarpStringType, int> string2pitch = {
73+
{ HarpStringType::C, 0 },
74+
{ HarpStringType::D, 2 },
75+
{ HarpStringType::E, 4 },
76+
{ HarpStringType::F, 5 },
77+
{ HarpStringType::G, 7 },
78+
{ HarpStringType::A, 9 },
79+
{ HarpStringType::B, 11 }
80+
};
81+
const std::map<PedalPosition, int> position2delta = {
82+
{ PedalPosition::FLAT, -1 },
83+
{ PedalPosition::NATURAL, 0 },
84+
{ PedalPosition::SHARP, 1 }
85+
};
86+
87+
for (int i = 0; i < _pedalState.size(); i++) {
88+
int stringPitch = string2pitch.at(HarpStringType(i));
89+
int delta = position2delta.at(_pedalState[i]);
90+
int resPitch = (((stringPitch + delta)) % 12 + 12) % 12;
91+
playablePitches.push_back(resPitch);
92+
}
93+
94+
_playablePitches = playablePitches;
95+
}
96+
6997
HarpPedalDiagram::HarpPedalDiagram(Segment* parent)
7098
: TextBase(ElementType::HARP_DIAGRAM, parent, TextStyleType::HARP_PEDAL_DIAGRAM, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
7199
{
@@ -91,6 +119,7 @@ void HarpPedalDiagram::layout()
91119
void HarpPedalDiagram::setPedalState(std::vector<PedalPosition> state)
92120
{
93121
_pedalState = state;
122+
setPlayablePitches();
94123
}
95124

96125
void HarpPedalDiagram::setIsDiagram(bool diagram)
@@ -110,6 +139,7 @@ void HarpPedalDiagram::setIsDiagram(bool diagram)
110139
void HarpPedalDiagram::setPedal(HarpStringType harpString, PedalPosition pedal)
111140
{
112141
_pedalState.at(harpString) = pedal;
142+
setPlayablePitches();
113143
}
114144

115145
String HarpPedalDiagram::createDiagramText()
@@ -143,7 +173,7 @@ String HarpPedalDiagram::createDiagramText()
143173
= { PedalPosition::UNSET, PedalPosition::UNSET, PedalPosition::UNSET, PedalPosition::UNSET, PedalPosition::UNSET,
144174
PedalPosition::UNSET, PedalPosition::UNSET };
145175
std::vector<PedalPosition> prevState;
146-
HarpPedalDiagram* prevDiagram = searchPrevDiagram();
176+
HarpPedalDiagram* prevDiagram = searchPrevDiagram(segment());
147177

148178
if (prevDiagram != nullptr) {
149179
// If states are the same work backwards until we find the first difference then calculate from there
@@ -156,7 +186,7 @@ String HarpPedalDiagram::createDiagramText()
156186
break;
157187
}
158188
// Check if there's a diagram before. If not, start of score and use init state
159-
prevDiagram = prevDiagram->searchPrevDiagram();
189+
prevDiagram = prevDiagram->searchPrevDiagram(segment());
160190
if (prevDiagram != nullptr) {
161191
prevState = prevDiagram->getPedalState();
162192
} else {
@@ -210,7 +240,7 @@ void HarpPedalDiagram::updateDiagramText()
210240
undoChangeProperty(Pid::TEXT, createDiagramText(), PropertyFlags::STYLED);
211241

212242
// Check if next diagrams are text and update if neccessary
213-
HarpPedalDiagram* nextDiagram = searchNextDiagram();
243+
HarpPedalDiagram* nextDiagram = searchNextDiagram(segment());
214244
if (!nextDiagram || nextDiagram->isDiagram()) {
215245
return;
216246
}
@@ -219,10 +249,10 @@ void HarpPedalDiagram::updateDiagramText()
219249
}
220250

221251
// Goes through all previous segments until one with a harp pedal diagram is found
222-
HarpPedalDiagram* HarpPedalDiagram::searchPrevDiagram()
252+
HarpPedalDiagram* HarpPedalDiagram::searchPrevDiagram(Segment* seg)
223253
{
224-
if (segment() != nullptr) {
225-
Segment* prevSeg = segment()->prev1();
254+
if (seg != nullptr) {
255+
Segment* prevSeg = seg->prev1();
226256

227257
while (prevSeg != nullptr) {
228258
for (EngravingItem* e : prevSeg->annotations()) {
@@ -238,10 +268,10 @@ HarpPedalDiagram* HarpPedalDiagram::searchPrevDiagram()
238268
}
239269

240270
// Goes through all next segments until one with a harp pedal diagram is found
241-
HarpPedalDiagram* HarpPedalDiagram::searchNextDiagram()
271+
HarpPedalDiagram* HarpPedalDiagram::searchNextDiagram(Segment* seg)
242272
{
243-
if (segment() != nullptr) {
244-
Segment* nextSeg = segment()->next1();
273+
if (seg != nullptr) {
274+
Segment* nextSeg = seg->next1();
245275

246276
while (nextSeg != nullptr) {
247277
for (EngravingItem* e : nextSeg->annotations()) {
@@ -256,6 +286,16 @@ HarpPedalDiagram* HarpPedalDiagram::searchNextDiagram()
256286
return nullptr;
257287
}
258288

289+
bool HarpPedalDiagram::isPitchPlayable(int pitch)
290+
{
291+
pitch = pitch % 12;
292+
293+
if (std::find(_playablePitches.begin(), _playablePitches.end(), pitch) != _playablePitches.end()) {
294+
return true;
295+
}
296+
return false;
297+
}
298+
259299
void HarpPedalDiagram::read(XmlReader& xml)
260300
{
261301
while (xml.readNextStartElement()) {

src/engraving/libmscore/harppedaldiagram.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define __HARPPEDALDIAGRAM_H__
2525

2626
#include "textbase.h"
27+
#include "pitchspelling.h"
2728

2829
using namespace mu;
2930
//using namespace mu::engraving;
@@ -46,8 +47,12 @@ class HarpPedalDiagram final : public TextBase
4647
{
4748
std::vector<PedalPosition> _pedalState;
4849

50+
std::vector<int> _playablePitches;
51+
4952
bool _isDiagram = true;
5053

54+
void setPlayablePitches();
55+
5156
public:
5257
HarpPedalDiagram(Segment* parent);
5358
HarpPedalDiagram(const HarpPedalDiagram& h);
@@ -83,10 +88,10 @@ class HarpPedalDiagram final : public TextBase
8388

8489
void updateDiagramText();
8590

86-
private:
91+
static HarpPedalDiagram* searchPrevDiagram(Segment* seg);
92+
static HarpPedalDiagram* searchNextDiagram(Segment* seg);
8793

88-
HarpPedalDiagram* searchPrevDiagram();
89-
HarpPedalDiagram* searchNextDiagram();
94+
bool isPitchPlayable(int pitch);
9095
};
9196
} // namespace mu::engraving
9297

src/engraving/libmscore/note.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,13 @@ void Note::draw(mu::draw::Painter* painter) const
14361436
painter->setPen(selected() ? engravingConfiguration()->warningSelectedColor() : engravingConfiguration()->warningColor());
14371437
}
14381438
}
1439+
// Warn if notes are unplayable based on previous harp diagram setting
1440+
if (chord() && chord()->segment() && staff() && !score()->printing() && !staff()->isDrumStaff(chord()->tick())) {
1441+
HarpPedalDiagram* prevDiagram = HarpPedalDiagram::searchPrevDiagram(chord()->segment()->next1());
1442+
if (prevDiagram && !prevDiagram->isPitchPlayable(ppitch())) {
1443+
painter->setPen(selected() ? engravingConfiguration()->warningSelectedColor() : engravingConfiguration()->warningColor());
1444+
}
1445+
}
14391446
// draw blank notehead to avoid staff and ledger lines
14401447
if (_cachedSymNull != SymId::noSym) {
14411448
painter->save();

0 commit comments

Comments
 (0)