adding note in plugin: sound ok, but not display
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
andtempNote.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 ascore.endCmd();
at the end. It is possible that this alone triggers the missing re-layout pass quoted above.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 thanks @Miwarre and @heuchi, 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.
In reply to The TPC values are arranged by Marc Sabatella
thank you Marc.
From your explanations and the online doc I found a way to make it work... or so I think at least.
Feel free to test it out it my new plugin chordsToNotes (still a few pending issues, but it works to a usable extent).
B.
In reply to thank you Marc. From your by berteh
Crashes for me, see https://musescore.org/en/node/16812#comment-292966
In reply to thanks @Miwarre and @heuchi, by berteh
In addition, you may find useful this discussion on figured bass with code samples; it is in C++ and you would need to port it to JavaScript, but the transition is not complex.
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:
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 thanks Miwarre. That 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
In reply to I have added some… by Bacchushlg
I tried to use improved version of the plugin, but i get only 1 bass voice instead of 4 voices. I used the sample attached by the author of original plugin and pressed F2 and checked that there are chord marks above the score. But alas...!
Result is attached. I use MS portable: rev. OS: Windows 7, Arch.: i386, MuseScore version (32-bit): 2.3.2, revision: 4592407
Any comments are welcome!, thanks!
In reply to I tried to use improved… by alexander.poro…
I get this problem sometimes - due to "wrong" chord signatures (I don't know what is "wrong").
What helps is to "touch" each chord symbols once (double click) - complicated...
By hazard I noticed that the same effect is provoked by transposing a score. So just transpose to whatever key and transpose back to the original - your problem should be solved: when you use the plug-in, it should work as expected...
In reply to I get this problem sometimes… by Bacchushlg
Thank you very much, Bacchushlg! I'll try.