Changing the barlines surrounding a selection
Hi, I'm having trouble changing the barlines surrounding a range selection.
I've combed through some old forum posts and doxygen several times, but I've never gotten it to work exactly how I would like (either the wrong barline changes, or nothing changes at all)...
function addRepeats() {
var c = curScore.newCursor();
//c.filter = Segment.All;
c.rewind(Cursor.SELECTION_START);
//var seg = curScore.selection.startSegment
//while (seg.prev && seg.segmentType != Segment.BarLineType) {
// seg = seg.prev
//}
//while(! seg.elementAt(0).barlineType) {
// seg.prev
//}
/*while(c.prev() && ! c.segment.elementAt(0).barlineType) {
c.prev();
var seg = c.segment;
}*/
curScore.selection.select(c) //tackle weird range select problem
while(curScore.selection.elements[0] && curScore.selection.elements[0].type != Element.BARLINE) {
cmd('prev-element')
}
curScore.selection.elements[0].barlineType = 4;
//var seg = c.measure.elements[0];
//seg.barlineType = 4;
//seg.elementAt(0).barlineType = 4;
}
Currently I'm only trying to get the leftmost barline to work, and the stuff in comments is other things I've tried.
Thanks in advance for your time :)
Comments
how about
better compare !=undefined cos !0 is true
Cursor.SELECTION_START requires a range selection, won't work if user's selecting one note
curScore.selection.select may require a following curScore.endCmd()
In reply to how about var c =… by msfp
> Cursor.SELECTION_START requires a range selection, won't work if user's selecting one note
I was aware of that already, but you're right, changing it has only benefits.
Your suggestion unfortunately doesn't seem to work, it only changes the first barline in the score (meaning the while loop stops at !seg and doesnt detect the barline)
In reply to > Cursor.SELECTION_START… by XiaoMigros
> first barline in the score
demo mscz?
In reply to > first barline in the score… by msfp
oh i kind of get it, weird result when barlineType = 4
might be related to https://musescore.org/en/node/330048#comment-1119468
do you get to the expected barline with barlineType = 2?
In reply to oh i kind of get it, weird… by msfp
type 2 worked once (crashed the other times), type 4 has yet to work.
In reply to type 2 worked once (crashed… by XiaoMigros
I'll try adding it from the previous measure (for type 4), that should do it.
In reply to I'll try adding it from the… by XiaoMigros
added notes
https://musescore.org/en/node/345122