Plugin API: How to set tpc / pitch of note

• May 19, 2020 - 17:37

Hi all. I am planning to release a plugin which recreates the up arrow / down arrow functions for microtonal tunings. However, I am stuck as setting a note's pitch / tpc property doesn't seem to do anything to it:

n.pitch = 60;
n.tpc = 14;
n.accidentalType = Accidental.SHARP_ARROW_UP;
n.tuning = 133;

I tried the above code as a proof of concept to see if this method would work, but it doesn't.

I've taken a look at the implementation for the plugin system in mscore/plugins/api/elements.cpp and I've come across the setTpc function, however when i to use it in QML, it gives an error saying there is no such property.

Is there any way for me to change just the pitch of an existing note using the plugin API without having to delete it and reconstruct it?

P.S. I am aware of the cmd function which allows me to invoke user controls, however it doesn't allow for an easy way to set a note's exact tonal pitch class as it prefers sharps when going upwards, and flats when going downwards, and notes in the key signature takes precedence over enharmonic equivalent notes that are not.

Any help would be appreciated! Thanks in advance.


Comments

I can't really help too directly as I'm not very up on the plugin interface, but I can tell you a couple of things that might be useful:

  • There are actually two tpc's internally, called, annoyingly enough, tpc1 and tpc2. One is the tpc to use with Concert Pitch turned on, the other is the one to use when it is turned off. And of course, nothing about the numbering tells you which is which. Anyhow, you probably need to set them both, if that's possible

  • While up/down don't give you choice of enharmonic spelling, there are also commands to add accidentals directly, and to change the enharmonic spelling of a note. So one way or another it seems it should be possible to get the job done this way.

It looks like there is an interesting interplay of various note properties implementations here.

In the current implementation setting accidentalType property goes down to Score::changeAccidental() function which, surprisingly, calculates a note's pitch, for some reason, from its line number on a staff and overwrites the existing tpc value. This line number gets updated only on score layout, and by the time when you try to assign accidentalType it still has an old value. Therefore the following options can help here (they seem to work in my tests):

1) Setting line number explicitly (this requires calculating a correct line number though):

n.pitch = 60;
n.tpc = 14;
n.line = 10;
n.accidentalType = Accidental.SHARP_ARROW_UP;
n.tuning = 133;

Actually, on current MuseScore versions this seems to work even without setting pitch and tpc at all:

n.line = 10;
n.accidentalType = Accidental.SHARP_ARROW_UP;
n.tuning = 133;

2) Setting accidental type before changing a note's pitch:

n.accidentalType = Accidental.SHARP_ARROW_UP;
n.pitch = 60;
n.tpc = 14;
n.tuning = 133;

Also it seems like setting tpc property doesn't take transposition into account so if you toggle "Concert pitch" button after changing tpc that way it shows something incorrect. This looks like this would need a correction in this property implementation in MuseScore, but in the meanwhile if this is important for your plugin you may need to assign both tpc1 and tpc2 properties manually. The first approach (with line number calculation) seems to be less affected by this issue.

Alternatively, instead of changing the existing note's properties, you can remove the old note from a chord and add then new one, if this happens to suit your plugin's needs better.

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