How to set the duration of a rest?
I started to write a plugin to autogenerate simple scores in MuseScore 2.x. I can't find a way to add rests with a specific duration.
Does anyone know how to:
a) Split a rest in two or more rests or
b) Replace a given chord by a rest with the same duration
I kinda managed to create a new Rest object, but adding it to the score without a duration is not possible. So i might have to add a Fraction object to the rests duration. But i can't manage to initiate or copy a Fraction object.
Comments
You'll need to add a note of the correct duration first (unless you are replacing a note with a rest of the same duration), then you can add a rest at the same position. Have a look at the discussion here: https://musescore.org/en/node/67326#comment-590151. You will need to re position the cursor after adding the note as it automatically moves on.
In reply to You'll need to add a note of by stevel05
Thanks! This seems to work for now:
var position = cursor.tick;
cursor.setDuration(1, 16);
cursor.addNote(0); // placeholder
cursor.rewind(0);
while(cursor.tick < position) {
cursor.next();
}
var rest = newElement(Element.REST);
rest.durationType = cursor.element.durationType;
cursor.add(rest);
cursor.next();
In reply to Thanks! This seems to work by birk
You also need to set the duration of the rest otherwise subsequently editing the rest will fail.