How to set the duration of a rest?

• Dec 5, 2016 - 13:26

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

In reply to 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 by birk

You also need to set the duration of the rest otherwise subsequently editing the rest will fail.

var rest = newElement(Element.REST);
rest.durationType = cursor.element.durationType;
rest.duration = cursor.element.duration;
cursor.add(rest);

Do you still have an unanswered question? Please log in first to post your question.