[fix] correct rendering of flat notes

To date, all $name would be displayed as sharps
Now, we correctly render flats,
and use subscript notation for octaves.
This commit is contained in:
2026-05-13 11:06:54 +02:00
parent 8dc9b87035
commit f4df20188c
2 changed files with 50 additions and 9 deletions

View File

@ -100,8 +100,8 @@ $8`
}, },
{ {
"name": "Alto Recorder", name: "Alto Recorder",
"fingering": { fingering: {
"F4": "11111111", "F4": "11111111",
"F#4":"1111111|", "F#4":"1111111|",
"G4": "11111110", "G4": "11111110",

View File

@ -323,7 +323,7 @@ MuseScore {
//--------------------------------------------------------- //---------------------------------------------------------
// MIDI -> Note Name // MIDI -> Note Name
//--------------------------------------------------------- //--------------C-------------------------------------------
function pitchToName(midiPitch) { function pitchToName(midiPitch) {
var names = ["C","C#","D","D#","E","F", var names = ["C","C#","D","D#","E","F",
@ -335,6 +335,46 @@ MuseScore {
return names[pitchClass] + octave return names[pitchClass] + octave
} }
function subscriptDigit(n) {
return String.fromCharCode(0x2080 + n)
}
function noteToName(note) {
var mapping = {
[Accidental.FLAT]: {
1: "D♭",
3: "E♭",
4: "F♭",
6: "G♭",
8: "A♭",
10: "B♭",
11: "C♭"
},
[Accidental.SHARP]: {
0: "B♯",
1: "C♯",
3: "D♯",
5: "E♯",
6: "F♯",
8: "G♯",
10: "A♯"
},
[Accidental.NONE]: {
0: "C",
2: "D",
4: "E",
5: "F",
7: "G",
9: "A",
11: "B"
}
}
var pitchClass = note.pitch % 12
var octave = Math.floor(note.pitch / 12) - 1
var name = (mapping[note.accidentalType] || {}) [pitchClass] || "?"
return name + subscriptDigit(octave)
}
//--------------------------------------------------------- //---------------------------------------------------------
// BUILD UTF-8 DIAGRAM // BUILD UTF-8 DIAGRAM
//--------------------------------------------------------- //---------------------------------------------------------
@ -573,22 +613,23 @@ MuseScore {
if (userTransposed) midi += 12 if (userTransposed) midi += 12
var noteName = pitchToName(midi) var noteId = pitchToName(midi)
var noteName = noteToName(chord.notes[0])
var text = newElement(Element.STAFF_TEXT) var text = newElement(Element.STAFF_TEXT)
if (!dict[noteName]) { if (!dict[noteId]) {
diagram = noteName + "\n☒" diagram = noteName + "\n☒"
console.log("Note not in dictionary:", noteName) console.log("Note not in dictionary:", noteId)
} else { } else {
var diagram = buildFingeringText(dict[noteName], userFormatString, noteName) var diagram = buildFingeringText(dict[noteId], userFormatString, noteName)
console.log("Note:", noteName, "Diagram:", diagram.replace(/\n/g, "\\n")) console.log("Note:", noteId, "Diagram:", diagram.replace(/\n/g, "\\n"))
} }
text.text = "<font face=\"" + getFontStack() + "\">" + diagram + "</font>"; text.text = "<font face=\"" + getFontStack() + "\">" + diagram + "</font>";
cursor.add(text) cursor.add(text)
formatText(text) formatText(text)
const note = noteName.slice(0, -1) const note = noteId.slice(0, -1)
text.color = Fingering.getColor(note) text.color = Fingering.getColor(note)
// Verify the text object has the properties set // Verify the text object has the properties set