Writing text to a special notehead
I figured out, how to write a text in a score with a plugin.
import QtQuick 2.0
import MuseScore 1.0
MuseScore {
version: "2.0"
description: "None"
menuPath: "Plugins.Fingersatz"
onRun: {
var cursor = curScore.newCursor();
cursor.rewind(0);
var text = newElement(Element.TEXT);
text.text = "1";
text.color = "#ff0000";
cursor.add(text);
Qt.quit();
} // end onRun
}
But this write the text at the beginning of the score.
Q1: What commands do I need, that the anchor of the text is the note head I activated in the score.
Q2: Is there a command like text.style = RH fingering?
Comments
1)
cursor.rewind(0)
puts your cursor at the beginning of the score. You're likely looking forcursor.rewind(1)
to end up at the start of your selection. I'm not sure if it works when you have only a notehead selected though. It does work if the note was selected with Shift-click2) If you want to create a fingering text element, don't use Element.TEXT but rather use Element.FINGERING as the element type. I'm also unsure about this, but it could be that you'll have to add it to the annotations of the selected note/segment rather than simply at the cursor position.
You could create a simple score of 1 measure with a note with a fingering on it and then loop over that score to try and find out where the Fingering is attached to (walk.qml might help in doing so)
Chances are that the text-style will be better or correct if you use the most specific element type available. Setting the text-style is currently not possible, but a code patch to enable this is already pending (https://github.com/musescore/MuseScore/pull/2408).
Once it is in place you'll be able to write
In reply to 1) cursor.rewind(0) puts your by jeetee
Thank you, that works.
This works not. Writing "fingering" or "Fingering" causes
Debug: cannot create type 0
14:-1: TypeError: Type error
14:-1: TypeError: Type error
14:-1: TypeError: Type error
Warning: :14: TypeError: Type error
Writing "FINGERING" causes a runtime error and musescore are finished.
In reply to 1) cursor.rewind(0) puts your by hasenfuss
The Element type has to be all in capitals to work. This works for me:
giving the following output
I'm guessing your crash is caused by the call to
cursor.add()
. Internally it uses the undo stack to add the element. To be able to do that from within a plugin, you'll need to callcurScore.startCmd();
andcurScore.endCmd();
respectively before and after thecursor.add()
call.All actions you do between startCmd and endCmd will result in one 'undo-action' afterwards. So if you run for example (pseudocode):
and then press the Undo shortcut (Ctrl+Z) all 10 added notes will be removed in the same undo command.
If you however would run (pseudocode):
you'd have to trigger Undo 10 times afterwards to make all notes disappear again.
In reply to The Element type has to be by jeetee
Thank you. But it seems to me, I have to know which language or syntax is used for the plugins. I am familiar with the basis of Visualbasic and php, if I want to go on with my experiments.
In reply to Thank you. But it seems to by hasenfuss
The plugins are written on top of the QtQuick/QML framework. This means that the language used within your plugin.qml file is Javascript (https://developer.mozilla.org/en-US/docs/Web/JavaScript).