Retrieving the note "type" or "name"

• Jan 6, 2021 - 22:16

In my plugin I would like to retrieve the type/name of a note which is selected ("A" ... "G") .
I can very well get to the Note object, gets its accidental. But not its name.
I tried "note.text", "note.label", ... I even tried console.log('-->Note: '+ JSON.stringify(note)); (but it crashes MuseScore 8-O )
"note.pitch" gives the pitch of note, so there is no difference between a B and Cb.
Any other ideas ?
Thanks


Comments

Look at the documentation of note and "Properties inherited from …"

https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…

I don't think that it provides the note name. I solved it with an (incomplete) mapping table. I added this property to my plugin code:

readonly property var midiPitchMap: [["C_",36],["Cis_",37],["Des_",37],["D_",38],["Dis_",39],["Es_",39],["E_",40],["F_",41],["Fis_",42],["Ges_",42],["G_",43],["Gis_",44],["As_",44],["A_",45],["Ais_",46],["Bes_",46],["B_",47],["C",48],["Cis",49],["Des",49],["D",50],["Dis",51],["Es",51],["E",52],["F",53],["Fis",54],["Ges",54],["G",55],["Gis",56],["As",56],["A",57],["Ais",58],["Bes",58],["B",59],["C'",60],["Cis'",61],["Des'",61],["D'",62],["Dis'",63],["Es'",63],["E'",64],["F'",65],["Fis'",66],["Ges'",66],["G'",67],["Gis'",68],["As'",68],["A'",69],["Ais'",70],["Bes'",70],["B'",71],["C''",72],["Cis''",73],["Des''",73],["D''",74],["Dis''",75],["Es''",75],["E''",76],["F''",77],["Fis''",78],["Ges''",78],["G''",79],["Gis''",80],["As''",80],["A''",81],["Ais''",82],["Bes''",82],["B''",83],["C'''",84],["Cis'''",85],["Des'''",85],["D'''",86],["Dis'''",87],["Es'''",87],["E'''",88],["F'''",89],["Fis'''",90],["Ges'''",90],["G'''",91],["Gis'''",92],["As'''",92],["A'''",93],["Ais'''",94],["Bes'''",94],["B'''",95],["C''''",96],["Cis''''",97],["Des''''",97],["D''''",98],["Dis''''",99],["Es''''",99],["E''''",100],["F''''",101],["Fis''''",102],["Ges''''",102],["G''''",103],["Gis''''",104],["As''''",104],["A''''",105],["Ais''''",106],["Bes''''",106],["B''''",107]]

I generated this by my backend code. You can es well transform or generate it in the JavaScript console to make the note names suit your need.

Then you can look-up a note name by scanning the table using Array.prototype.find() https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_O…

In reply to by Marc Sabatella

Thanks. This is working fine.

I wrote a short function to "enrich" the note.

function enrichNote(note) {
	// accidental
	var id = note.accidentalType;
	note.accidentalName = "NONE";
	if (id != 0) {
		for (var i = 0; i < accidentals.length; i++) {
			var acc = accidentals[i];
			if (id == eval("Accidental." + acc.name)) {
				note.accidentalName = acc.name;
				break;
			}
		}
	}
	
	// note name and octave
	var tpc={'tpc' : 0, 'name' : '?', 'raw' : '?'};
	var pitch=note.pitch;
	var pitchnote=pitchnotes[pitch % 12];
	var noteOctave=Math.floor(pitch/12)-1;

	for (var i = 0; i < tpcs.length; i++) {
		var t = tpcs[i];
		if (note.tpc==t.tpc) {
			tpc=t;
			break;
		}
	}			

	if (pitchnote == "B" && tpc.raw == "C") {
		noteOctave++;
	} else if (pitchnote == "C" && tpc.raw == "B") {
		noteOctave--;
	}
	
	note.extname={"fullname": tpc.name+noteOctave, "name": tpc.raw+noteOctave, "raw": tpc.raw, "octave": noteOctave};
	return;

}
		
readonly property var pitchnotes : [ 'C', 'C', 'D', 'D', 'E', 'F', 'F', 'G', 'G', 'A', 'A', 'B']

readonly property var tpcs : [{
		'tpc' : -1,
		'name' : 'F♭♭',
		'raw' : 'F'
	}, {
		'tpc' : 0,
		'name' : 'C♭♭',
		'raw' : 'C'
	}, {
		'tpc' : 1,
		'name' : 'G♭♭',
		'raw' : 'G'
	}, {
		'tpc' : 2,
		'name' : 'D♭♭',
		'raw' : 'D'
	}, {
		'tpc' : 3,
		'name' : 'A♭♭',
		'raw' : 'A'
	}, {
		'tpc' : 4,
		'name' : 'E♭♭',
		'raw' : 'E'
	}, {
		'tpc' : 5,
		'name' : 'B♭♭',
		'raw' : 'B'
	}, {
		'tpc' : 6,
		'name' : 'F♭',
		'raw' : 'F'
	}, {
		'tpc' : 7,
		'name' : 'C♭',
		'raw' : 'C'
	}, {
		'tpc' : 8,
		'name' : 'G♭',
		'raw' : 'G'
	}, {
		'tpc' : 9,
		'name' : 'D♭',
		'raw' : 'D'
	}, {
		'tpc' : 10,
		'name' : 'A♭',
		'raw' : 'A'
	}, {
		'tpc' : 11,
		'name' : 'E♭',
		'raw' : 'E'
	}, {
		'tpc' : 12,
		'name' : 'B♭',
		'raw' : 'B'
	}, {
		'tpc' : 13,
		'name' : 'F',
		'raw' : 'F'
	}, {
		'tpc' : 14,
		'name' : 'C',
		'raw' : 'C'
	}, {
		'tpc' : 15,
		'name' : 'G',
		'raw' : 'G'
	}, {
		'tpc' : 16,
		'name' : 'D',
		'raw' : 'D'
	}, {
		'tpc' : 17,
		'name' : 'A',
		'raw' : 'A'
	}, {
		'tpc' : 18,
		'name' : 'E',
		'raw' : 'E'
	}, {
		'tpc' : 19,
		'name' : 'B',
		'raw' : 'B'
	}, {
		'tpc' : 20,
		'name' : 'F♯',
		'raw' : 'F'
	}, {
		'tpc' : 21,
		'name' : 'C♯',
		'raw' : 'C'
	}, {
		'tpc' : 22,
		'name' : 'G♯',
		'raw' : 'G'
	}, {
		'tpc' : 23,
		'name' : 'D♯',
		'raw' : 'D'
	}, {
		'tpc' : 24,
		'name' : 'A♯',
		'raw' : 'A'
	}, {
		'tpc' : 25,
		'name' : 'E♯',
		'raw' : 'E'
	}, {
		'tpc' : 26,
		'name' : 'B♯',
		'raw' : 'B'
	}, {
		'tpc' : 27,
		'name' : 'F♯♯',
		'raw' : 'F'
	}, {
		'tpc' : 28,
		'name' : 'C♯♯',
		'raw' : 'C'
	}, {
		'tpc' : 29,
		'name' : 'G♯♯',
		'raw' : 'G'
	}, {
		'tpc' : 30,
		'name' : 'D♯♯',
		'raw' : 'D'
	}, {
		'tpc' : 31,
		'name' : 'A♯♯',
		'raw' : 'A'
	}, {
		'tpc' : 32,
		'name' : 'E♯♯',
		'raw' : 'E'
	}, {
		'tpc' : 33,
		'name' : 'B♯♯',
		'raw' : 'B'
	}
]

readonly property var accidentals : [
	{ 'name': 'NONE' },
	{ 'name': 'FLAT' },
	{ 'name': 'NATURAL' },
	{ 'name': 'SHARP' },
	{ 'name': 'SHARP2' },
	{ 'name': 'FLAT2' },
	{ 'name': 'SHARP3' },
	{ 'name': 'FLAT3' },
	{ 'name': 'NATURAL_FLAT' },
	{ 'name': 'NATURAL_SHARP' },
	{ 'name': 'SHARP_SHARP' },
	{ 'name': 'FLAT_ARROW_UP' },
	{ 'name': 'FLAT_ARROW_DOWN' },
	{ 'name': 'NATURAL_ARROW_UP' },
	{ 'name': 'NATURAL_ARROW_DOWN' },
	{ 'name': 'SHARP_ARROW_UP' },
	{ 'name': 'SHARP_ARROW_DOWN' },
	{ 'name': 'SHARP2_ARROW_UP' },
	{ 'name': 'SHARP2_ARROW_DOWN' },
	{ 'name': 'FLAT2_ARROW_UP' },
	{ 'name': 'FLAT2_ARROW_DOWN' },
	{ 'name': 'ARROW_DOWN' },
	{ 'name': 'ARROW_UP' },
	{ 'name': 'MIRRORED_FLAT' },
	{ 'name': 'MIRRORED_FLAT2' },
	{ 'name': 'SHARP_SLASH' },
	{ 'name': 'SHARP_SLASH4' },
	{ 'name': 'FLAT_SLASH2' },
	{ 'name': 'FLAT_SLASH' },
	{ 'name': 'SHARP_SLASH3' },
	{ 'name': 'SHARP_SLASH2' },
	{ 'name': 'DOUBLE_FLAT_ONE_ARROW_DOWN' },
	{ 'name': 'FLAT_ONE_ARROW_DOWN' },
	{ 'name': 'NATURAL_ONE_ARROW_DOWN' },
	{ 'name': 'SHARP_ONE_ARROW_DOWN' },
	{ 'name': 'DOUBLE_SHARP_ONE_ARROW_DOWN' },
	{ 'name': 'DOUBLE_FLAT_ONE_ARROW_UP' },
	{ 'name': 'FLAT_ONE_ARROW_UP' },
	{ 'name': 'NATURAL_ONE_ARROW_UP' },
	{ 'name': 'SHARP_ONE_ARROW_UP' },
	{ 'name': 'DOUBLE_SHARP_ONE_ARROW_UP' },
	{ 'name': 'DOUBLE_FLAT_TWO_ARROWS_DOWN' },
	{ 'name': 'FLAT_TWO_ARROWS_DOWN' },
	{ 'name': 'NATURAL_TWO_ARROWS_DOWN' },
	{ 'name': 'SHARP_TWO_ARROWS_DOWN' },
	{ 'name': 'DOUBLE_SHARP_TWO_ARROWS_DOWN' },
	{ 'name': 'DOUBLE_FLAT_TWO_ARROWS_UP' },
	{ 'name': 'FLAT_TWO_ARROWS_UP' },
	{ 'name': 'NATURAL_TWO_ARROWS_UP' },
	{ 'name': 'SHARP_TWO_ARROWS_UP' },
	{ 'name': 'DOUBLE_SHARP_TWO_ARROWS_UP' },
	{ 'name': 'DOUBLE_FLAT_THREE_ARROWS_DOWN' },
	{ 'name': 'FLAT_THREE_ARROWS_DOWN' },
	{ 'name': 'NATURAL_THREE_ARROWS_DOWN' },
	{ 'name': 'SHARP_THREE_ARROWS_DOWN' },
	{ 'name': 'DOUBLE_SHARP_THREE_ARROWS_DOWN' },
	{ 'name': 'DOUBLE_FLAT_THREE_ARROWS_UP' },
	{ 'name': 'FLAT_THREE_ARROWS_UP' },
	{ 'name': 'NATURAL_THREE_ARROWS_UP' },
	{ 'name': 'SHARP_THREE_ARROWS_UP' },
	{ 'name': 'DOUBLE_SHARP_THREE_ARROWS_UP' },
	{ 'name': 'LOWER_ONE_SEPTIMAL_COMMA' },
	{ 'name': 'RAISE_ONE_SEPTIMAL_COMMA' },
	{ 'name': 'LOWER_TWO_SEPTIMAL_COMMAS' },
	{ 'name': 'RAISE_TWO_SEPTIMAL_COMMAS' },
	{ 'name': 'LOWER_ONE_UNDECIMAL_QUARTERTONE' },
	{ 'name': 'RAISE_ONE_UNDECIMAL_QUARTERTONE' },
	{ 'name': 'LOWER_ONE_TRIDECIMAL_QUARTERTONE' },
	{ 'name': 'RAISE_ONE_TRIDECIMAL_QUARTERTONE' },
	{ 'name': 'DOUBLE_FLAT_EQUAL_TEMPERED' },
	{ 'name': 'FLAT_EQUAL_TEMPERED' },
	{ 'name': 'NATURAL_EQUAL_TEMPERED' },
	{ 'name': 'SHARP_EQUAL_TEMPERED' },
	{ 'name': 'DOUBLE_SHARP_EQUAL_TEMPERED' },
	{ 'name': 'QUARTER_FLAT_EQUAL_TEMPERED' },
	{ 'name': 'QUARTER_SHARP_EQUAL_TEMPERED' },
	{ 'name': 'FLAT_17' },
	{ 'name': 'SHARP_17' },
	{ 'name': 'FLAT_19' },
	{ 'name': 'SHARP_19' },
	{ 'name': 'FLAT_23' },
	{ 'name': 'SHARP_23' },
	{ 'name': 'FLAT_31' },
	{ 'name': 'SHARP_31' },
	{ 'name': 'FLAT_53' },
	{ 'name': 'SHARP_53' },
	{ 'name': 'SORI' },
	{ 'name': 'KORON' }
];

Do you still have an unanswered question? Please log in first to post your question.