Adding Tempo text or clef within plugin crashes Musescore (2). What am I doing wrong?
I'm trying to write a plugin that can generate a melody - something like the random2 plugin, but with some constraints on what melody is generated.
User input is (among other things) the instrument.
What I would like to do is to set a clef appropriate for the selected instrument programmatically. But when I try to do that, Musescore crashes.
As basis for my code, I looked at the random2 plugin. This fragment creates a timesignature:
var cursor = score.newCursor();
cursor.track = 0;
var ts = newElement(Element.TIMESIG);
My -naive- assumption is that something similar should work for adding a clef, so I wrote:
var cleff = newElement(Element.CLEF);
But when I do that, Musescore crashes. Another problem is that the API documentation (inside the plugin creator) lists only 2 properties and no methods for a Clef Element - I would need to set the clef type somewhere, no?
I have a similar issue for the tempo. I want to set the tempo of the entire piece to 4 quarters per second. So I wrote:
var tempoText = newElement(Element.TEMPO_TEXT);
tempoText.tempo = 4.0;
again, musescore crashes.
What am I doing wrong?