lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Aligning 'to Coda' rehearsal marks


From: Thomas Morley
Subject: Re: Aligning 'to Coda' rehearsal marks
Date: Thu, 14 Mar 2013 02:09:37 +0100

2013/3/13 Jim Long <address@hidden>:
> I'm not content with my skills in engraving coda jumps.  I suspect
> Lilypond could do better if I knew how to code it.
>
> My current method is to use a rehearsal mark to concatenate some
> text and a Coda glyph, and then apply a trial-end-error X-offset
> until it lines up the way I want it to, and then when the layout
> changes, I usually have to adjust it again.
>
> In my example code, the first score uses \toCoda to create coda
> glyph centered very nicely over the barline.  I modify the
> visibility properties of the rehearsal mark so that if the barline
> is broken, the coda mark will not be visibile at the beginning of
> a line.  I also set the outside-staff-priority so that the coda
> glyph will be engraved in between the staff and the volta
> brackets.  And yes, many of the coda marks are placed oddly in
> the code, to demonstrate that the break-visibility property is
> doing what I want it to do.
>
> This code also scales well to the smaller size shown in the second
> example, although I don't understand why a magnification factor of
> 1.0 results in a smaller size.
>
> The third variable 'txtCoda' contains a more detailed representation
> of what I like to use, but it requires manual manipulation to get it
> to align, and one size does not fit all.
>
> How can I create a coda mark which:
>
> 1) aligns the X-center line of the coda glyph with the X-center of
> the barline;
>
> 2) places the arbitrary "to Coda" alongside the glyph, while leaving
> the glyph itself centered over the barline; and
>
> 3) can be scaled easily (text and glyph) to different sizes, without
> disturbing the alignment of the coda glyph to the barline?
>
> An elegant solution to this would be very welcome.  Thank you for
> your time.
>
> Jim
>
> _______________________________________________
> lilypond-user mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-user
>

Hi Jim,

below some code, which should do what you want.

Usage:
a)
Predefine two markups:
mrkpI = \markup \fontsize #-1 "to Coda"
mrkpII = \markup \fontsize #-1 { \musicglyph #"scripts.coda" }

b)
Combine and align them with `alignCombinedRehearsalMarks´. Use an alist:

myMarkI =
\alignCombinedRehearsalMarks \mrkpI \mrkpII
          #`(;(center-on-first . #t)
             (center-on-second . #t)
             ;(general-align . ,LEFT)
             (outside-staff-priority . 5)
             (break-visibility . ,begin-of-line-invisible)
          )
This alist offers the possibilities to have the RehearsalMark centered
at the first markup or the second markup or align it as you want as a
whole. Please make one choice.
In addition you may want to set outside-staff-priority and
break-visibility within this alist.
Comment what you don't need, choose the values you want. Even an empty
list will combine the two markups, defaulting all other properties.
Some more comments in the code.

The Code:


\version "2.16.2"

alignCombinedRehearsalMarks =
#(define-music-function (parser location mrkp-1 mrkp-2 align)
   (markup? markup? list?)
#{
  %% Combines and aligns two markups
  \once \override Score.RehearsalMark #'before-line-breaking =
         #(lambda (grob)
            (let* (;; mrkp-stils
                   (mrkp-1-stil (grob-interpret-markup grob mrkp-1))
                   (mrkp-2-stil (grob-interpret-markup grob mrkp-2))
                   ;; x-extent of mrkp-stils
                   (mrkp-1-x-length
                     (interval-length (ly:stencil-extent mrkp-1-stil X)))
                   (mrkp-2-x-length
                     (interval-length (ly:stencil-extent mrkp-2-stil X)))
                   ;; get alist-values
                   (general-align (assoc-ref align 'general-align))
                   (center-on-first (assoc-ref align 'center-on-first))
                   (center-on-second (assoc-ref align 'center-on-second))

                   (padding 0.6)
                   ;; combine mrkp-1-stil and mrkp-2-stil
                   (combined-stil
                     (ly:stencil-combine-at-edge
                       (ly:stencil-aligned-to
                          mrkp-1-stil
                          Y
                          CENTER)
                       X
                       RIGHT
                       (ly:stencil-aligned-to
                          mrkp-2-stil
                          Y
                          CENTER)
                       padding))
                   (combined-stil-length
                     (interval-length (ly:stencil-extent combined-stil X)))
                   (set-stencil!
                     (ly:grob-set-property! grob 'stencil combined-stil))
               ;;;; align the stencil,
               ;;;; defined for:
                   ;; center the new stencil on the first markup
                   ;; for all not #f values.
                   ;; (center-on-first . #t)
                   ;; center the new stencil on the second markup
                   ;; for all not #f values.
                   ;; (center-on-second . #t)
                   ;; aligning the whole stencil is possibble with all values,
                   ;; example:
                   ;; (general-align . ,LEFT)
                   (set-alignment!
                      (cond (general-align
                             (ly:grob-set-property! grob 'self-alignment-X
                                general-align))
                            (center-on-first
                             (ly:grob-set-property! grob 'self-alignment-X
                                (/ (- combined-stil-length mrkp-1-x-length)
                                   (* -1 combined-stil-length))))
                            (center-on-second
                             (ly:grob-set-property! grob 'self-alignment-X
                                (/ (- combined-stil-length mrkp-2-x-length)
                                   (* 1 combined-stil-length))))
                            (else #f))))

           set-alignment!
           set-stencil!))
  %% Sets break-visibility
  \once \override Score.RehearsalMark #'break-visibility =
    #(or (assoc-ref align 'break-visibility) #(#f #t #t))
  %% Sets outside-staff-priority
  \once \override Score.RehearsalMark #'outside-staff-priority =
    #(or (assoc-ref align 'outside-staff-priority) 1500)
  \mark ""
#})

mrkpI = \markup \fontsize #-1 "to Coda"
mrkpII = \markup \fontsize #-1 { \musicglyph #"scripts.coda" }

myMarkI =
\alignCombinedRehearsalMarks \mrkpI \mrkpII
          #`(;(center-on-first . #t)
             (center-on-second . #t)
             ;(general-align . ,LEFT)
             (outside-staff-priority . 5)
             (break-visibility . ,begin-of-line-invisible)
          )

myMarkII =
\alignCombinedRehearsalMarks \mrkpI \mrkpII
          #`(;(center-on-first . #t)
             ;(center-on-second . #t)
             (general-align . ,LEFT)
             (outside-staff-priority . 5)
             (break-visibility . ,begin-of-line-visible)
          )

% test %%%%%%%%%%%%

\new Staff {
  \myMarkI R1
  \myMarkI \bar "||" |
  R1 \break
  \myMarkI
  R1 \displayMusic  \myMarkI
  \repeat volta 2 { R1 }
  \alternative { R1 { R1 \myMarkII } } \break
  \repeat volta 2 { R1 \myMarkI }
  \alternative { R1 R1 } \break
}




HTH,
  Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]