Retrieving the note "type" or "name"
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:
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 Look at the documentation of… by nurfz
Actually, your code is based on the "note.pitch". Which is by essence the same for two different notes with the same tempered pitch.
So, for B4 and C5b, Musescore returns 71. And from your table a B. So it doesn't work for me.
Thanks anyway !
In reply to Actually, your code is based… by parkingb
Sure, you still have to select the correct note name from the table depending on your key. For each pitch, there are multiple names in my map. You can use Array.prototype.filter() instead of first()
What you want is "tpc" - that's what distinguishes B from Cb, etc. You don't actually need pitch at all.
In reply to What you want is "tpc" -… by Marc Sabatella
Oh, alright, I forgot about that :) But how do you get the octave? By pitch and integer division?
In reply to Oh, alright, I forgot about… by nurfz
Sure, if you need that. The OP didn't mention octave, just letter name.
In reply to Sure, if you need that. The… by Marc Sabatella
Thanks. This is working fine.
I wrote a short function to "enrich" the note.
I have registered my plugin to do this at:
https://musescore.org/en/project/scorenotes