Attached is a plugin containing a couple of routines that I have found to be
useful that I am offering to the public domain, so they may be used as
I needed to simulate Lock Format, and to do that I needed to know which bars
were at the ends of pages, and at the ends of systems.
Though we now have available
bar.OnNthSystem and bar.NthBarInSystem
it is not trivial to derive from this which bars are the first or last bars
on a page or system. It gets even more complex when you have multirests,
because multirests are treated as a single bar, and all the bars in a
multirest have the same bar.OnNthSystem and bar.NthBarInSystem.
I decided to write a routine I could use whenever I needed to know the
position of a bar in a system or page. So I wrote GetBarPosStaffPage. It
creates an array, indexed by the internal bar number, that contains either
FP for first bar on a page
LP for last bar on a page
FS for first bar on a system
LS for last bar on a system
M for anything else.
(Note that a first or last bar on a page is also the first or last bar on a
Once I have this, it is fairly easy to use, as is shown in the routine
LockFormat in the attached plugin:
LockFormat(score, barnumFirst, barnumLast, arr)
// arr is an array of strings indexed by bar number telling the location of
the first and last bars
// on a system or page. It was generated by calling GetBarPosStaffPage
sysStaff = score.SystemStaff;
for barnum = barnumFirst to (barnumLast + 1)
bar = sysStaff.NthBar(barnum);
if (bar.BreakType != SpecialPageBreak) // leave these alone
if (arr[bar.BarNumber] = "LP") // last bar on a page
bar.BreakType = EndOfPage;
if (arr[bar.BarNumber] = "LS") // last bar on a
system but not page
bar.BreakType = EndOfSystem;
if (barnum = sysStaff.BarCount) // last in
bar.BreakType = EndOfPage;
bar.BreakType = MiddleOfSystem;
Basically, it leaves SpecialPageBreaks alone, and puts an EndOfPage break at
the end of a page (or the last bar in the score), an EndOfSystem break at
the last bar in a system, and MiddleOfSystem breaks everywhere else. Having
the array it is easy to determine these positions.
The breaks are what Lock Format in Sib seems to do, and Roman Molino Dunn
has confirmed the same breaks.
The tricky code is in GetBarPosStaffPage, which handles multirests and some
end conditions. I have already used this in other situations and I think it
is very handy.
I can see that it might also be useful to have an array indexed by internal
page number that contains the first and last bar numbers for each page. I
won't write that one until I need it, though. It might make a good exercise
for the reader...
So if this is useful to anyone, please feel free to reuse the code. If
anyone finds problems with it, please let me know.
LockFormat.zip (1K) Download Attachment
|Free forum by Nabble||Edit this page|