Adding a TimeSignature in the middle of the score crashes MuseScore
I'm trying to create different time signatures in a score.
Setting the time signature at the very beginning of the score works fine.
But adding a new time signature later-on in the score (but still at the beginning of a new measure) simply crashes MuseScore.
This is a little code to reproduce it:
import QtQuick 2.0
import MuseScore 3.0
MuseScore {
menuPath: "Plugins.pluginName"
description: "Description goes here"
requiresScore: false
version: "1.0"
onRun: {
// 1) create a score with one measure
var score = newScore("McveTimeSig", "bass-flute", 1);
var cursor = score.newCursor();
cursor.track = 0;
score.startCmd();
cursor.rewind(0);
// 2) setting the original time signature (OK)
// (here 5/4)
var beatsByMeasure = 5;
var ts = newElement(Element.TIMESIG);
ts.timesig = fraction(beatsByMeasure, 4);
cursor.add(ts);
console.log("Adapting measure to " + beatsByMeasure + "/4");
// 3) adding notes (more notes than available in the unique 5/4 measure)
cursor.rewind(0);
var cur_time = cursor.segment.tick;
var counter = 0;
for (var i = 0; i < (beatsByMeasure + 2); i++, counter++) {
if (counter > 0) {
// 3.1) moving to the next position
cursor.rewindToTick(cur_time); // be sure to move to the next rest, as now defined
var success = cursor.next();
if (!success) {
// We couldn't move to the next position == we are at the end of the score
// 3.2) A new measure
console.log("Adding A measure");
score.appendMeasures(1);
cursor.rewindToTick(cur_time);
cursor.next();
// START OF FEATURE .............
// 3.3) Changing the signature of that new measure
var ts = newElement(Element.TIMESIG);
ts.timesig = fraction(++beatsByMeasure, 4); // going for a 6/4
cursor.add(ts); // <--- BREAK MuseScore
//break; // attempt to isolate the issue
cursor.rewindToTick(cur_time); // be sure to move to the next rest, as now defined
cursor.next();
// ............... END OF FEATURE
}
}
// 3.4) Converting the current rest to a note of 1/4
cursor.setDuration(1, 4); // quarter
var note = cursor.element;
console.log("Adding note (" + i + ") at " + note.parent.tick);
restToNote(note, 60 + i);
cur_time = cursor.segment.tick;
}
score.endCmd();
}
function restToNote(rest, pitch) {
if (rest.type != Element.REST)
return;
//console.log("==ON A REST==");
var cur_time = rest.parent.tick; // getting rest's segment's tick
var duration = rest.duration;
var oCursor = curScore.newCursor()
oCursor.rewindToTick(cur_time);
oCursor.addNote(pitch);
oCursor.rewindToTick(cur_time);
var chord = oCursor.element;
var note = chord.notes[0];
return note;
}
}
Anyone has an idea how to have this working ?
Thanks,
Comments
It seems to work. You even dont need to be at the begining of measure to add time signature.
import QtQuick 2.0
import MuseScore 3.0
In reply to It seems to work. You even… by sammik
Hi, I elaborated from your example, and I made crash MuseScore again.
This is weird. I think the order of instructions is really important.
In your example, in the new measure, if you add first the new Signature before adding the note, MS crashes.
In your example, in the new measure, if you add the new Signature after adding the note, MS doesn't crash (your example).
This one is OK:
This one is KO:
Any way, thanks. I'll adapt my code knowing this strange behaviour.
In reply to Hi, I elaborated from your… by parkingb
I am not sure, what really is doing crash, as adding time signature without adding notes works for me as well.
onRun: {
console.log("hello createscore");
var score = newScore("Test-Score", "piano", 5);
It seems, that problem is addig time signature to measure added by Plugin API.
In reply to I am not sure, what really… by sammik
SHould I create a new bug report for this ? I never know. I encounter relatively often bugs with the API...
In reply to SHould I create a new bug… by parkingb
I am not authority at all, but it really seems to be bug to me, so I think You can create Issue ticket.