[fix] detect key signature correctly

need to look at cursor.keySignature to properly name the notes

Also, fixed soprano recorder octaves
This commit is contained in:
2026-05-13 12:14:08 +02:00
parent f4df20188c
commit b40a7f4ad2
2 changed files with 103 additions and 60 deletions

View File

@ -55,34 +55,34 @@ const woodwinds = [
{
name: "Soprano Recorder",
fingering: {
"C4": "11111111",
"C#4": "1111111|",
"D4": "11111110",
"D#4": "111111|o",
"E4": "111111oo",
"F4": "11110011",
"F#4": "1111011o",
"G4": "111100oo",
"G#4": "111011|o",
"A4": "111000oo",
"A#4": "110110oo",
"B4": "110000oo",
"C5": "101000oo",
"C#5": "011000oo",
"D5": "001000oo",
"D#5": "0011111o",
"E5": "-11111oo",
"F5": "-111101o",
"F#5": "-11101oo",
"G5": "-11100oo",
"G#5": "-11010oo",
"A5": "-11000oo",
"A#5": "-110011|",
"B5": "-11011oo",
"C6": "-10011oo",
"C#6": "-1011011",
"D6": "-1011011",
"D#6": "-011011o",
"C5": "11111111",
"C#5": "1111111|",
"D5": "11111110",
"D#5": "111111|o",
"E5": "111111oo",
"F5": "11110011",
"F#5": "1111011o",
"G5": "111100oo",
"G#5": "111011|o",
"A5": "111000oo",
"A#5": "110110oo",
"B5": "110000oo",
"C6": "101000oo",
"C#6": "011000oo",
"D6": "001000oo",
"D#6": "0011111o",
"E6": "-11111oo",
"F6": "-111101o",
"F#6": "-11101oo",
"G6": "-11100oo",
"G#6": "-11010oo",
"A6": "-11000oo",
"A#6": "-110011|",
"B6": "-11011oo",
"C7": "-10011oo",
"C#7": "-1011011",
"D7": "-1011011",
"D#7": "-011011o",
},
format:
`$note

View File

@ -339,40 +339,82 @@ MuseScore {
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"
function noteToPitchName(accidental, pitchClass, defaultValue) {
switch (accidental) {
case Accidental.FLAT:
case Accidental.NATURAL_FLAT:
switch (pitchClass) {
case 1: return "D♭"
case 3: return "E♭"
case 4: return "F♭"
case 6: return "G♭"
case 8: return "A♭"
case 10: return "B♭"
case 11: return "C♭"
default: return defaultValue
}
case Accidental.SHARP:
case Accidental.NATURAL_SHARP:
switch (pitchClass) {
case 0: return "B♯"
case 1: return "C♯"
case 3: return "D♯"
case 5: return "E♯"
case 6: return "F♯"
case 8: return "G♯"
case 10: return "A♯"
default: return defaultValue
}
case Accidental.NONE:
case Accidental.NATURAL:
switch (pitchClass) {
case 0: return "C"
case 2: return "D"
case 4: return "E"
case 5: return "F"
case 7: return "G"
case 9: return "A"
case 11: return "B"
default: return defaultValue
}
default: return "!" + defaultValue
}
}
function isSharp(pitch, keySig) {
var p = 6
for (var i = 0; i < keySig; ++i) {
if (pitch == p) {
return true
}
p = (p + 7) % 12
}
return false
}
function isFlat(pitch, keySig) {
var p = 10
for (var i = 0; i > keySig; --i) {
if (pitch == p) {
return true
}
p = (p + 5) % 12
}
return false
}
function noteToName(note, keySig, defaultValue) {
var accidental = note.accidentalType
var pitchClass = note.pitch % 12
if (accidental == Accidental.NONE && isSharp(pitchClass, keySig)) {
accidental = Accidental.SHARP
}
if (accidental == Accidental.NONE && isFlat(pitchClass, keySig)) {
accidental = Accidental.FLAT
}
var octave = Math.floor(note.pitch / 12) - 1
var name = (mapping[note.accidentalType] || {}) [pitchClass] || "?"
return name + subscriptDigit(octave)
var pitchName = noteToPitchName(accidental, pitchClass, defaultValue)
return pitchName + subscriptDigit(octave)
}
//---------------------------------------------------------
@ -609,12 +651,13 @@ MuseScore {
while (cursor.segment) {
if (cursor.element && cursor.element.type === Element.CHORD) {
var chord = cursor.element
var keySignature = cursor.keySignature
var midi = chord.notes[0].pitch
if (userTransposed) midi += 12
var noteId = pitchToName(midi)
var noteName = noteToName(chord.notes[0])
var noteName = noteToName(chord.notes[0], keySignature, "?")
var text = newElement(Element.STAFF_TEXT)