How to extend all barlines through code

• Dec 17, 2022 - 20:11

I'm picking up a sample Tonic Solfa plugin and enhancing it for use in MS3+ and adding a few more details.

Ideally I would like to be able to extend the existing barlines of a score as per the example image.

How can I adjust offsetX and barlineScanTo programmatically for ALL barlines?

Attachment Size
extending barlines.jpg 86.65 KB

Comments

In reply to by jeetee

I'm relatively new to all this and find the documentation confusing. How do I loop through each BarLine. This extends the first barline OK but then receives a type error on element.type.

Description: Extend BarLines
Requires Score
Debug: BAR LINE Barline
20:-1: TypeError: Cannot read property 'type' of null

So I guess that ''element' is not being set as I think it should be

MuseScore {
version: "3.0"
description: "Extend BarLines"

onRun: { 
    var cursor = curScore.newCursor();
    cursor.rewind(0);

    var ix=0

    var measure = cursor.measure;
    var segment = measure.firstSegment;
    var element = segment.elementAt(ix);
    //curScore.startCmd();

while (cursor.segment) {
if (element.type == Element.BAR_LINE) {

    console.log("BAR LINE",element.userName());
    element.offsetY = -4;

    element.barlineScanTo = 8;

  } else {
    console.log("Element ("+element.userName()+")");
        }
    ix++
    cursor.next;
    measure = cursor.measure;
    segment = cursor.segment;
    element = segment.elementAt(ix);
   // console.log(cursor.measure,measure.firstSegment,ix,segment.elementAt(0))
  }
    //curScore.endCmd();
    Qt.quit();
}

}

In reply to by dehwall

I think I have found it now by using 'segment.next'

while (cursor.segment) {
if (element.type == Element.BAR_LINE) {

    console.log("BAR LINE",element.userName());
    element.offsetY = -4;

    element.barlineScanTo = 8;

  } else {
    console.log("Element ("+element.userName()+")");
        }
    ix++
    segment = segment.next;     
    element = segment.elementAt(0);

  }

In reply to by dehwall

It should be barlineSpanTo, not "scan". With this spelling it does work for me.

Also note that if your goal is to change this for the entire staff you can just do
element.staff.staffBarlineSpanTo = 8
which would change the staff setting rather than individual barlines.

In reply to by dmitrio95

Many thanks dmitrio95, this works exactly how I need it to now - "Should have gone to SpecSavers!".
However I can't see an offsetY property exposed for element.staff.????

Properties
bool small
qreal mag
QColor color
Staff color. More...
bool playbackVoice1 Whether voice 1 participates in playback. More...
bool playbackVoice2 Whether voice 2 participates in playback. More...
bool playbackVoice3 Whether voice 3 participates in playback. More...
bool playbackVoice4 Whether voice 4 participates in playback. More...
int staffBarlineSpan
int staffBarlineSpanFrom
int staffBarlineSpanTo
qreal staffUserdist User-defined amount of additional space before this staff. More...
Ms::PluginAPI::Part part

import MuseScore 3.0
MuseScore {
version: "1.0"
description: "Extend BarLines"
onRun: {
var cursor = curScore.newCursor();
var endTick;
var endTick = curScore.lastSegment.tick
curScore.startCmd();
console.log(endTick,curScore.nstaves);
for (var track = 0; track < curScore.nstaves*4; track+=4) {
cursor.rewind(0); // sets voice to 0
var measure = cursor.measure;
var segment = measure.firstSegment;
var element = segment.elementAt(track);
segment = measure.firstSegment;
endTick = curScore.lastSegment.tick

    while (segment.tick &lt; endTick) {
        if (segment.segmentType == Segment.EndBarLine ) {                    
           element.offsetY = -4;
           element.barlineSpanTo = 8;        
          //element.offset= Qt.point(8, -4) 
        }         
        segment = segment.next;     
        element = segment.elementAt(track);  
    } // end while tick
      } // End for       
   curScore.endCmd();
   Qt.quit();
}

}

In reply to by dehwall

Yes, there isn't an offsetY staff setting. But if you need to extend barlines in the upper direction you can instead use the staffBarlineSpanFrom property of staff (or barlineSpanFrom for an individual barline). That should work better than combining offsetY and barlineSpanTo for that purpose.

In reply to by dmitrio95

Thanks dmitrio95 - barlineSpanFrom was doing strange things such as reporting in Inspector / console.log that the value had changed but not displayed. Clicking the reset option in inspector though then showed the extended line...

However, the loop method suits me fine as I want to be selective in which staves it is applied to and it gives me a little more control.

It's been a good learning curve in my foray into plugins.... I hope to have a tonic solfa plugin available in the near future

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