Adding Lyrics via plugin
Hi, how can I add lyrics in a plugin?
This works fine for text, however it doesn't seem to work for Element.LYRICS. What am I doing wrong?
var Text = newElement(Element.STAFF_TEXT);
Text.text = 'something';
cursor.add(Text);
Best regards,
Fernando
Comments
I don't know the specifics of the plugin syntax, but I do know something of the internal representation. I can tell you that while staff text is added to a segment/track (which is essentially what a "cursor" represents), lyrics are added to chordrests.
Which version of MuseScore do you use? For me it works as expected with
Element.LYRICS
type:In reply to Which version of MuseScore… by dmitrio95
Thanks for this snippet! It works for me when I call
.add(lyr)
on a chord.Do you happen to know how to set the "row number" of stacked lyrics?
I'm not sure if this Plugin API is up-to-date because it does not list the
text
property and calling thesetNo(int)
function yields "TypeError: Property 'setNo' of object Ms::PluginAPI::Element(0x55d29e400780) is not a function"...In reply to Thanks for this snippet. It… by nurfz
The "text" property is listed on the generic "Element" page (https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…). Unfortunately for 3.x the plugin approach was changed from clean object-owned properties to a generic element propertydump without a decent way of knowing which property is supported by which element.
As for the error message, setNo is a method part of a Lyric and you're calling it on a generic Element so perhaps you're not calling it on the lyric itself?
In reply to The "text" property is… by jeetee
try
lyr.verse = 2 //starts from zero
In reply to try lyr.verse = 2 //starts… by msfp
That works, thank you! May I ask where you got this secret knowledge from? ;)
Also, thanks jeetee for the explanation!
In reply to That works, thank you! May I… by nurfz
I digged into src, see "elements has properties inherited from the..." under Learn more