lilypond-user
[Top][All Lists]
Advanced

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

Re: Ragged right for contents but not staff?


From: David Kastrup
Subject: Re: Ragged right for contents but not staff?
Date: Thu, 13 Mar 2014 15:44:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Pierre Perol-Schneider <address@hidden> writes:

> 2014-03-13 14:14 GMT+01:00 Matthias Hüsken <
> address@hidden>:
>
>
>> I know this thread is ancient, but I am only now in the process of
>> upgrading from Lilypond 2.12.2 to 2.18, and I used the attached function
>> alignGrob quite heavily. Unfortunately, it does not work in 2.18 any more,
>> and I do not know enough about the Lilypond internals (and about scheme) to
>> fix it myself. Here is what happens if I try to compile the attached file
>> from David:
>>
>>
> Hi Matthias,
> see enclosed file.

Well, yeah.  But that's still awful to use.  I have not bothered
cleaning up the function (it should really use reduce for finding the
minimum), but one can make the calling much more pleasant.

\version "2.18.0"

alignGrob =
#(define-music-function (parser location grob-to-align reference-grob dir corr)
                        (symbol? symbol? number? number?)
 #{
    \overrideProperty  $grob-to-align . extra-offset #(lambda (grob)
      (let* ((sys (ly:grob-system grob))
             (array (ly:grob-object sys 'all-elements))
             (default-coord (ly:grob-relative-coordinate grob sys X))
             (grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 
'name)))
             (lst (filter
                    (lambda (x) (eq? reference-grob (grob-name x)))
                    (ly:grob-array->list array))))

      ;; find the grob with the X-coordinate closest to object to be aligned
        (let ((ref (car lst)))
           (define closest (lambda (x)
             (if (< (abs (- default-coord
                            (ly:grob-relative-coordinate (car x) sys X)))
                    (abs (- default-coord
                            (ly:grob-relative-coordinate ref sys X))))
                 (set! ref (car x)))
             (if (not (null? (cdr x)))
                 (closest (cdr x)))))

          (closest lst)

     ;; return extra-offset based on choice of alignment
            (cons
              (cond ((< dir 0) (- (car (ly:grob-extent ref sys X))
                                   (car (ly:grob-extent grob sys X))))
                    ((= dir 0) (- (interval-center (ly:grob-extent ref sys X))
                                   (interval-center (ly:grob-extent grob sys 
X))))
                    ((> dir 0) (- (cdr (ly:grob-extent ref sys X))
                                   (cdr (ly:grob-extent grob sys X)))))
              corr))))
  #}
)

ln = \markup \with-color #red \draw-line #'(0 . 6)
uparrow = \markup \combine \arrow-head #Y #UP ##f \draw-line #'(0 . -2)
downarrow = \markup \combine \arrow-head #Y #DOWN ##f \draw-line #'(0 . 2)

\relative c' {

  %% bar 1
  \time 3/4
  \key d \major
  d
  \alignGrob TextScript KeySignature #0 #6
  e-\ln
  \alignGrob TextScript Clef #1 #5.5
  fis-\ln

  %% bar 2
  \time 5/4
  \alignGrob TextScript BarLine #0 #-5.5
  e^\ln
  \alignGrob TextScript Hairpin #1 #1
  d(_\ln
  \alignGrob TextScript Slur #0 #0
  e_\uparrow
  \alignGrob TextScript StaffSymbol #0 #0
  fis^\markup \center-column { "mid-staff" \downarrow  } d)\<

  %% bar 3
  \time 3/4
  \alignGrob TextScript TimeSignature #-1 #-5
  e^\ln
  \alignGrob TextScript TimeSignature #1 #-5
  fis^\ln d

  %% bar 5
  \alignGrob TextScript Stem #0 #-5.5
  e\!^\ln fis
  \alignGrob TextScript Accidental #0 #0
  d!_\uparrow

  %% bar 6
  \time 2/4
  \alignGrob Stem NoteHead #0 #0
   fis
  \alignGrob Stem NoteHead #0 #0
  \alignGrob Script BarLine #0 #0.5
  \alignGrob TextScript StaffSymbol #1 #0
  d\fermata _"end"
  \bar "||"
}


-- 
David Kastrup

reply via email to

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