How to extend all barlines through code
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
I don't think a plugin can alter the staff style setting for these, so looping over them all is likely "the" way.
In reply to I don't think a plugin can… 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"
while (cursor.segment) {
if (element.type == Element.BAR_LINE) {
}
In reply to I'm relatively new to all… by dehwall
I think I have found it now by using 'segment.next'
while (cursor.segment) {
if (element.type == Element.BAR_LINE) {
In reply to I think I have found it now… by dehwall
Hmmm, it changes 'offsetY' but not 'barlineScanTo',
Any Ideas?
In reply to Hmmm, it changes 'offsetY'… 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 It should be barlineSpanTo 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
}
In reply to Many thanks dmitrio95, this… 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 Yes, there isn't an offsetY… 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