Skip to content

Commit f8830d2

Browse files
authored
FIXES #4070 The Pitch piemenu do not remember the last selected accidental value (#4071)
* Update piemenus.js * Update piemenus.js * Update piemenus.js * Update piemenus.js by this commit the note name get displayed coreectly even after no selection after the piemenu is opened * Update piemenus.js * Update piemenus.js
1 parent ec80db5 commit f8830d2

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

js/piemenus.js

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const piemenuPitches = (
9494
custom
9595
) => {
9696
let prevPitch = null;
97-
97+
let prevAccidental = block.prevAccidental || null; // to remember the previous accidental value
9898
// wheelNav pie menu for pitch selection
9999
if (block.blocks.stageClick) {
100100
return;
@@ -334,30 +334,21 @@ const piemenuPitches = (
334334

335335
if (!custom) {
336336
// Navigate to a the current accidental value.
337-
if (accidental === "") {
338-
block._accidentalsWheel.navigateWheel(2);
339-
} else {
340-
switch (accidental) {
341-
case DOUBLEFLAT:
342-
block._accidentalsWheel.navigateWheel(4);
343-
break;
344-
case FLAT:
345-
block._accidentalsWheel.navigateWheel(3);
346-
break;
347-
case NATURAL:
348-
block._accidentalsWheel.navigateWheel(2);
349-
break;
350-
case SHARP:
351-
block._accidentalsWheel.navigateWheel(1);
352-
break;
353-
case DOUBLESHARP:
354-
block._accidentalsWheel.navigateWheel(0);
355-
break;
356-
default:
357-
block._accidentalsWheel.navigateWheel(2);
358-
break;
359-
}
360-
}
337+
let accidentalIndex = 2; // Default to "natural" if none is set.
338+
if (prevAccidental !== null) {
339+
accidentalIndex = accidentals.indexOf(prevAccidental);
340+
} else if (accidental === DOUBLEFLAT) {
341+
accidentalIndex = 4;
342+
} else if (accidental === FLAT) {
343+
accidentalIndex = 3;
344+
} else if (accidental === NATURAL) {
345+
accidentalIndex = 2;
346+
} else if (accidental === SHARP) {
347+
accidentalIndex = 1;
348+
} else if (accidental === DOUBLESHARP) {
349+
accidentalIndex = 0;
350+
}
351+
block._accidentalsWheel.navigateWheel(accidentalIndex);
361352
}
362353

363354
if (hasOctaveWheel) {
@@ -605,7 +596,10 @@ const piemenuPitches = (
605596
that.value += selection["attr"];
606597
that.text.text = selection["note"] + selection["attr"];
607598
}
608-
599+
// Store the selected accidental in the block for later use.
600+
prevAccidental = selection["attr"];
601+
block.prevAccidental = prevAccidental;
602+
609603
that.container.setChildIndex(that.text, that.container.children.length - 1);
610604
that.updateCache();
611605
__pitchPreview();
@@ -631,6 +625,28 @@ const piemenuPitches = (
631625
// Hide the widget when the exit button is clicked.
632626
block._exitWheel.navItems[0].navigateFunction = () => {
633627
that._piemenuExitTime = new Date().getTime();
628+
const selectedNote =
629+
that._pitchWheel.navItems[that._pitchWheel.selectedNavItemIndex].title;
630+
const selectedAccidental =
631+
!custom && that._accidentalsWheel
632+
? that._accidentalsWheel.navItems[that._accidentalsWheel.selectedNavItemIndex].title
633+
: "";
634+
635+
// Update the block's displayed text with the note and accidental
636+
if (selectedAccidental === "♮" || selectedAccidental === "") {
637+
// Natural or no accidental: display only the note
638+
that.text.text = selectedNote;
639+
} else {
640+
// Combine note and accidental for display
641+
that.text.text = selectedNote + selectedAccidental;
642+
}
643+
// Update the block value and refresh the cache
644+
that.value = selectedNote + (selectedAccidental === "♮" ? "" : selectedAccidental);
645+
// Ensure proper layering of the text element
646+
that.container.setChildIndex(that.text, that.container.children.length - 1);
647+
// Refresh the block's cache
648+
that.updateCache();
649+
// Hide the pie menu and remove the wheels
634650
docById("wheelDiv").style.display = "none";
635651
that._pitchWheel.removeWheel();
636652
if (!custom) {

0 commit comments

Comments
 (0)