[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:
@ -100,8 +100,8 @@ $8`
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Alto Recorder",
|
||||
"fingering": {
|
||||
name: "Alto Recorder",
|
||||
fingering: {
|
||||
"F4": "11111111",
|
||||
"F#4":"1111111|",
|
||||
"G4": "11111110",
|
||||
|
||||
@ -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 = "<font face=\"" + getFontStack() + "\">" + diagram + "</font>";
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user