On Mon, Dec 16, 2024 at 6:08 AM tran li <litra...@hotmail.com> wrote:

> Got it. Thanks a lot. I didn't realize that it is such a simple task in
> LilyPond.
>
> F. X. P.
>
> On 2024/12/16 18:56, Werner LEMBERG wrote:
> >
> >> Most GUI-based scorewriter applications allow users to drag items to
> >> arbitrary positions and presumably, creates no side effect.  [...]
> >>
> >> However, when searching for a method to do the same in LilyPond, I
> >> cannot find a method that is working in general.  [...]
> > Try `extra-offset`.
>

Hi Li,

extra-offset is easiest, like Werner recommends, and I use it for the
positioning of rehearsal marks, too.

But the place where you'll start to see extra-offset wear at the seams is
when you reflow the music, especially if the rehearsal mark occurs just
before (or just after) a line break. Since you're engraving an ensemble
piece, this is especially likely to happen when you make the parts, because
both line-breaking and the horizontal spacing of music are likely to differ
from the full score.

There is a way to properly position rehearsal marks, however, and I think
it is one of the least appreciated parts of how LilyPond's object
positioning works. In short, even though rehearsal marks look like just any
other piece of markup in your score, LilyPond classifies rehearsal marks as
"break-alignable" items. LilyPond positions such break-alignable items in a
*completely different* way than normal markup and articulations and so on.
This is documented as NR 5.4.9 "Using the break-alignable-interface" ...

https://lilypond.org/doc/v2.25/Documentation/notation/using-the-break_002dalignable_002dinterface

... but you can be forgiven for not really understanding what's going on:

"Rehearsal marks, text marks, bar numbers, and more generally all objects
with break-alignable-interface, collectively referred to as
“break-alignable objects”, may be aligned with notation objects such as bar
lines, key signatures, time signatures, and generally any object with
break-aligned-interface. To be more precise, break-aligned items have a
break-align-symbol property, providing symbols that can be used as ‘anchor
points’ for other objects via the break-align-symbols property. See
break-alignment-interface, for a complete list of available symbols."

To elaborate, you can precisely position normal markup with the pair of ...

  \once \override TextScript.parent-alignment-X = #left
  \once \override TextScript.self-alignment-X = #center

... to say that the center of a markup (self-alignment-X) should align with
the left edge (parent-alignment-X) of the parent note-head to which the
markup is (invisibly) connected. Users usually discover this
double-override pattern fairly easily.

But what the paragraph above in NR 5.4.9 is saying is that you *can not*
use this same pair of overrides to position a rehearsal mark. Note that
this should almost certainly come as a surprise. Instead, you can precisely
position a rehearsal mark (or other break-alignable item) with THREE
overrides across a (changing combination of) TWO grobs, like ...

  \once \override Score.RehearsalMark.break-align-symbols =
#'(time-signature)
  \once \override Score.RehearsalMark.self-alignment-X = #center
  \once \override Score.TimeSignature.break-align-alignment-anchor = #left

... which says that the center of a rehearsal mark (self-alignment-X)
should try to align to any co-occurring time signature
(break-align-symbols), and that (if a time signature is found) the center
of the rehearsal mark should align to the left edge
(break-align-alignment-anchor) of that time signature.

I think it's possible that almost no LilyPond users are using this pattern;
certainly everyone I've ever shared it with has been surprised that it even
exists. But it's not as complicated as it sounds. The trick is that you
absolutely have to copy and modify every example in 5.4.9 to understand
what's going on; do not rely on the verbal descriptions alone. And you have
to understand all the examples given there, since no single example
collects all three overrides together, as I've tried to do here. It also
doesn't help that there are something like three different interfaces full
of break-related properties with names that all sound exactly the same, but
that's ok: treat the properties like algebraic variables, and study how the
break-related properties interact, without relying on the names of the
properties to guide you.

A final example. If you say ...

  \once \override Score.KeySignature.break-align-alignment-anchor = #right
  \once \override Score.RehearsalMark.break-align-symbols =
#'(time-signature key-signature)
  \once \override Score.RehearsalMark.self-alignment-X = #center
  \once \override Score.TimeSignature.break-align-alignment-anchor = #left

... then you're telling LilyPond that you want the center of a rehearsal
mark (self-alignment-X) to search first for any co-occurring time signature
and then (if no time signature is found) to search for any co-occurring key
signature. (Note that this is already branching logic, even though the
overrides don't make it look that way.) If LilyPond finds a time signature
to engrave at the same musical moment as your rehearsal mark, then logic
proceeds as in the above example, ie, aligning the center of the rehearsal
mark to the left edge (break-align-alignment-anchor) of the time signature.
If LilyPond finds no co-occurring time signature, then LilyPond searches
for a key signature to engrave at the same musical moment as your rehearsal
mark. If LilyPond finds such a co-occurring key signature, then LilyPond
aligns the center of the rehearsal mark to the *right* edge
(break-align-alignment-anchor) of the key signature. You can put as many
symbols as you want in the break-align-symbols list; just make sure to
override the break-align-alignment-anchor of each corresponding grob
(addressed at the Score context) or you can be confused, for years, as to
why rehearsal marks continue to be positioned just slightly off of where
you expect.

Hope this helps. This escaped me for more than a decade.

Trevor.

-- 
Trevor Bača
www.trevorbaca.com
soundcloud.com/trevorbaca

Reply via email to