adding note in plugin: sound ok, but not display

• May 29, 2015 - 03:04

Hello.

I try to add notes from a plugin in musescore 2.0. So far I manage to make them play a give midi pitch (concert note?), but the note displayed is not matching.

How do I modify the displayed note from the plugin? or better: how to properly add a note from a plugin to not run into that issue at all?

Thanks!
Berteh.

code excerpt, that is repeated for various pitch (eg 40, 52, 64) at different cursors positions:

var tempChord = newElement(Element.CHORD);
var tempNote = newElement(Element.NOTE);
tempNote.pitch=pitch; //music played is ok, but note are strangely always displayed as Bbb
tempNote.tpc=harmony.rootTpc; //seems to have no effect, how to fix note position?
tempChord.add(tempNote);
cursor.add(tempChord);

The full code is available from github along with test scores .


Comments

If I made the correct calculations, all the pitches you quote are E's.

1) Did you note (pun not intended!) if the added notes sooner or later 'fix themselves' when the score is manually edited, after the plug-in run, for instance by raising and lowering a single note nearby?

If this is the case, then a final re-layout pass is missing: try adding a score.doLayout(); statement at the end of the plug-in.

2) How do you compute harmony.rootTpc? Or, more generally, to what do you set the added note TPC? This is what determines how the note is 'spelt'; in the above cases, it should be the value for 'E'. You may get the TPC values here : it is in the 1.3 plug-in documentation, but this part did not change for 2.0.

3) Note that for transposing instruments, you possibly need to set tempNote.tpc1 and tempNote.tcp2 separately. Experiment with these two properties to see if they are really needed in this case and how they work. Documentation is a bit scant on this...

4) If you want to be able to undo your additions, you probably need to add a score.startCmd(); statement at the beginning of the plug-in and a score.endCmd(); at the end. It is possible that this alone triggers the missing re-layout pass quoted above.

tempNote.tpc=harmony.rootTpc; //seems to have no effect, how to fix note position?

note.tpc is a read-only property. So, you have to set tpc1 and tpc2.
For a non-transposing instrument set both to the same value.

thanks @Miwarre and @heuchi, indeed setting tpc1 and tpc2 allows to change the note display.

Now I struggle with the computation of that tpc for new notes. How can I compute the tpc of a note from adding an interval to another note?

My plugin at https://github.com/berteh/musescore-chordsToNotes/ will generate notes from chords notation (Harmony, in MuseScore). It does so by:
- finding the midi pitch and tpc of the harmony root (works)
- adding a note to play that root (works)
- selecting the semitones to add to that note from the Chord name (works)
- adding a note for each of these semitones (note added with the right midi pitch, but not the right tpc).

For a chord CMaj the root is C (pitch 48, tpc 14), and the semitones [4,7].
From my poor understanding of tpc , I want to add a E (pitch 52, tpc 18) and G (pitch 55, tpc 15).

What formula can I use to compute the tpc of these E and G from the infos on C and semitones, that would work for any (valid) value of root tpc and any amount of semitones (max. 21)?

In reply to by berteh

The TPC values are arranged on the circle of fifths. From C to E is 4 steps on the cirlce - from C to G, G to D, D to A, and A to E. In general, four steps on the circle of fifths always given you a major third up. From C to G is one step on the circle of fifths. So your TPC formula could presumably be, add 4 to get the third of the chord, add 1 to get the fifth.

There won't be a single formula ivolving semitones, though - that isn't enough information. For instance, one semitone up from C could be spelled C# or Db. You need to decide which you want to know how to spell it. If you want C#, that is seven steps sharper on the circle. If you want Db, that is five steps flatter.

thanks Miwarre. That discussion on figured bass is indeed very interesting, wish I would have spotted it earlier :/

I indeed followed a similar line of thought , converting a pitch offset (in semitones) to a tpc offset.

Nevertheless, as I am interested in handling most common chords notations, I thought I could simplify the interpretation by going in general for the just/augmented interval but for a few that are usually minor/diminished (3, 6, 10).

If I take a table notation as in the post you refer to that would show like:

pitch offset      tpc offset
(from root)      (from root)
0                    0
1                    7
2                    2
3                   -3   (minor third)
4                    4
5                   -1  
6                   -6  (diminished fifth)
7                    1
8                    8
9                    3
10                  -2  (diminished ninth)
11                   5

In javascript/QML that looks like :
{syntaxhighlighter brush:javascript;}
/** returns tpc of note that is #semitone half-tones higher than rootTPC
eg: semitoneToTPC (tpc of C#, 4) = tpc of E# */
function semitoneToTPC(rootTpc, semitone){
var semiToTpcDiff = [0, 7, 2, -3, 4, -1, -6, 1, 8, 3, -2, 5];
return (rootTpc + semiToTpcDiff[semitone%12]);
}
{/syntaxhighlighter}

Result can be seen/heard in the musescore file Chord Chard after Generation . Let me know what you think of it!

In reply to by berteh

I have added some improvements to your plugin:
- automatic creation of a new staff line (only one initial staff is accepted in the moment)
- correct chord length according to the distance to the next chord symbol
- some additional chords and synonyms (as found in several scores that I tested)

what I did not achieve:
- setting of the new staff line's instrumentId (no idea how to do this)
- remove warning "appendPart: not found"
- the problem that sometimes all chords of a score need to be "touched" for proper detection

Attachment Size
chordsToNotes.qml 13.57 KB

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