[SOLVED] Working out written pitch of a note for transposing instrument?
[THIS QUERY IS NOW SOLVED — SEE COMMENT BELOW]
1) note.pitch always returns the sounding MIDI pitch
2) note.tpc2 will tell you how the written note is spelled, but not which octave it's in.
Therefore you can't figure out what the written pitch is from comparing tpc2 vs. tpc1, because you can't differentiate between instruments with the same key but different octaves. For instance, a Middle C on a baritone saxophone and an Eb clarinet would return the same tpc2 (14), but would have very different sounding MIDI pitch (39 vs 63). But you can't work out from there what the written note must be, as it could have been a C3 written pitch, and it was an alto saxophone (also sounding 39).
(PS: I wish the Note object had a 'writtenPitch' property)
Comments
For anyone else trying to work out how to do this, you can use the (completely undocumented) 'line' property of Note, which is defined in the Element superclass.
This returns an integer that specifies whereabouts on the current staff the notehead is. It takes into account the current score view (e.g. Concert or Transposed) and the current clef — which 'pitch' and the various 'tpc' parameters do not.
The value of 0 is defined as the top line of the staff (so in Treble clef, that would be F5), 1 is the first space down (E5), and so on. Negative numbers are used to calculate the height above the staff (e.g. -2 would be A5, with one ledger line).
Note that this does not tell you the given accidental, so you still need to examine one of the tpc values to figure that out.
In reply to For anyone else trying to… by michaelnorris
Absolutely correct. I would add that the same thing can be done with the 'posY' of the note with steps of 0.5 (value 0 at the same position). Interestingly, we can find this page https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class… in the 'Plugins API' documentation with a large amount of properties assigned to the 'note element', but they are not actually accessible. Among them: 'epitch', 'ppitch' and 'transposition', which would seem very promising,,,