From f4df20188c4dde47918c59090a9b8dfcf0235ba9 Mon Sep 17 00:00:00 2001 From: Amras Date: Wed, 13 May 2026 11:06:54 +0200 Subject: [PATCH] [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. --- woodwind_tab_generator/Fingering.js | 4 +- .../woodwind_tab_generator.qml | 55 ++++++++++++++++--- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/woodwind_tab_generator/Fingering.js b/woodwind_tab_generator/Fingering.js index 7882bec..0911135 100644 --- a/woodwind_tab_generator/Fingering.js +++ b/woodwind_tab_generator/Fingering.js @@ -100,8 +100,8 @@ $8` }, { - "name": "Alto Recorder", - "fingering": { + name: "Alto Recorder", + fingering: { "F4": "11111111", "F#4":"1111111|", "G4": "11111110", diff --git a/woodwind_tab_generator/woodwind_tab_generator.qml b/woodwind_tab_generator/woodwind_tab_generator.qml index c17aeef..526f7e1 100644 --- a/woodwind_tab_generator/woodwind_tab_generator.qml +++ b/woodwind_tab_generator/woodwind_tab_generator.qml @@ -323,7 +323,7 @@ MuseScore { //--------------------------------------------------------- // MIDI -> Note Name - //--------------------------------------------------------- + //--------------C------------------------------------------- function pitchToName(midiPitch) { var names = ["C","C#","D","D#","E","F", @@ -335,6 +335,46 @@ MuseScore { 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 //--------------------------------------------------------- @@ -573,22 +613,23 @@ MuseScore { if (userTransposed) midi += 12 - var noteName = pitchToName(midi) + var noteId = pitchToName(midi) + var noteName = noteToName(chord.notes[0]) var text = newElement(Element.STAFF_TEXT) - if (!dict[noteName]) { + if (!dict[noteId]) { diagram = noteName + "\n☒" - console.log("Note not in dictionary:", noteName) + console.log("Note not in dictionary:", noteId) } else { - var diagram = buildFingeringText(dict[noteName], userFormatString, noteName) - console.log("Note:", noteName, "Diagram:", diagram.replace(/\n/g, "\\n")) + var diagram = buildFingeringText(dict[noteId], userFormatString, noteName) + console.log("Note:", noteId, "Diagram:", diagram.replace(/\n/g, "\\n")) } text.text = "" + diagram + ""; cursor.add(text) formatText(text) - const note = noteName.slice(0, -1) + const note = noteId.slice(0, -1) text.color = Fingering.getColor(note) // Verify the text object has the properties set