Changing the barlines surrounding a selection

• Feb 16, 2023 - 15:18

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

  var c = curScore.newCursor();
  c.inputStateMode=Cursor.INPUT_STATE_SYNC_WITH_SCORE
  var seg = c.segment
  while (seg && seg.elementAt(c.track).type != Element.BAR_LINE ) {
    seg = seg.prev
  }
  seg.elementAt(c.track).barlineType = 2

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 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)

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