Skip to content

Commit 05bd2ad

Browse files
author
Aayushdev18
committed
Fix 'Ti' pitch capitalization issue causing undefined behavior
- Fix pie menu selection logic to handle case-insensitive pitch lookups - Fix i18nSolfege function to normalize input/output to lowercase - Fix pie menu label processing to ensure consistent case handling - Resolves issue where 'Ti' pitch showed as 'undefined' when collapsed - Fixes Japanese localization issue (TiNaN -> ti) - Addresses GitHub issue #4779
1 parent 74ca451 commit 05bd2ad

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

js/block.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3433,9 +3433,11 @@ class Block {
34333433
// solfnotes_ is used in the interface for internationalization.
34343434
//.TRANS: the note names must be separated by single spaces
34353435
const solfnotes_ = _("ti la sol fa mi re do").split(" ");
3436+
// Ensure all solfege notes are lowercase for consistent processing
3437+
const normalizedSolfnotes_ = solfnotes_.map(note => note.toLowerCase());
34363438

34373439
if (this.piemenuOKtoLaunch()) {
3438-
piemenuPitches(this, solfnotes_, SOLFNOTES, SOLFATTRS, obj[0], obj[1]);
3440+
piemenuPitches(this, normalizedSolfnotes_, SOLFNOTES, SOLFATTRS, obj[0], obj[1]);
34393441
}
34403442
} else if (this.name === "scaledegree2") {
34413443
obj = splitScaleDegree(this.value);

js/piemenus.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ const piemenuPitches = (
399399
}
400400

401401
const label = that._pitchWheel.navItems[that._pitchWheel.selectedNavItemIndex].title;
402-
const i = noteLabels.indexOf(label);
402+
// Ensure consistent case for lookup - convert to lowercase for comparison
403+
const normalizedLabel = label.toLowerCase();
404+
const i = noteLabels.indexOf(normalizedLabel);
403405

404406
// Are we wrapping across C? We need to compare with the previous pitch
405407
if (prevPitch === null) {
@@ -541,7 +543,9 @@ const piemenuPitches = (
541543

542544
const __selectionChangedSolfege = () => {
543545
selection["note"] = that._pitchWheel.navItems[that._pitchWheel.selectedNavItemIndex].title;
544-
const i = noteLabels.indexOf(selection["note"]);
546+
// Ensure consistent case for lookup - convert to lowercase for comparison
547+
const normalizedNote = selection["note"].toLowerCase();
548+
const i = noteLabels.indexOf(normalizedNote);
545549
that.value = noteValues[i];
546550

547551
// Auto-selection of sharps and flats in fixed solfege handles
@@ -558,21 +562,23 @@ const piemenuPitches = (
558562
)
559563
: true))
560564
) {
561-
let i = scale.indexOf(selection["note"]);
565+
// Use normalized note for scale lookup
566+
const normalizedSelectionNote = selection["note"].toLowerCase();
567+
let i = scale.indexOf(normalizedSelectionNote);
562568
if (i === -1) {
563569
i = scale.indexOf(that.value);
564570
}
565571
if (i === -1) {
566-
i = NOTENAMES.indexOf(FIXEDSOLFEGE[selection["note"]]);
572+
i = NOTENAMES.indexOf(FIXEDSOLFEGE[normalizedSelectionNote]);
567573
}
568574
if (i === -1) {
569575
i = NOTENAMES.indexOf(FIXEDSOLFEGE[that.value]);
570576
}
571577
if (
572578
NOTENAMES.includes(selection["note"]) ||
573-
scale[i][0] === FIXEDSOLFEGE[selection["note"]] ||
579+
scale[i][0] === FIXEDSOLFEGE[normalizedSelectionNote] ||
574580
scale[i][0] === FIXEDSOLFEGE[that.value] ||
575-
scale[i][0] === selection["note"]
581+
scale[i][0] === normalizedSelectionNote
576582
) {
577583
selection["attr"] = scale[i].substr(1);
578584
} else {

js/utils/musicutils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5787,9 +5787,12 @@ const i18nSolfege = (note) => {
57875787
const solfnotes_ = _("ti la sol fa mi re do").split(" ");
57885788
const obj = splitSolfege(note);
57895789

5790-
const i = SOLFNOTES.indexOf(obj[0]);
5790+
// Normalize the note part to lowercase for lookup
5791+
const normalizedNote = obj[0].toLowerCase();
5792+
const i = SOLFNOTES.indexOf(normalizedNote);
57915793
if (i !== -1) {
5792-
return solfnotes_[i] + obj[1];
5794+
// Ensure the internationalized solfege note is always lowercase
5795+
return solfnotes_[i].toLowerCase() + obj[1];
57935796
} else {
57945797
// Wasn't solfege so it doesn't need translation.
57955798
return note;

0 commit comments

Comments
 (0)