@@ -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+
6997HarpPedalDiagram::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()
91119void HarpPedalDiagram::setPedalState (std::vector<PedalPosition> state)
92120{
93121 _pedalState = state;
122+ setPlayablePitches ();
94123}
95124
96125void HarpPedalDiagram::setIsDiagram (bool diagram)
@@ -110,6 +139,7 @@ void HarpPedalDiagram::setIsDiagram(bool diagram)
110139void HarpPedalDiagram::setPedal (HarpStringType harpString, PedalPosition pedal)
111140{
112141 _pedalState.at (harpString) = pedal;
142+ setPlayablePitches ();
113143}
114144
115145String 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+
259299void HarpPedalDiagram::read (XmlReader& xml)
260300{
261301 while (xml.readNextStartElement ()) {
0 commit comments