lilypond-user
[Top][All Lists]
Advanced

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

Re: Horizontally centered notes


From: Kieren MacMillan
Subject: Re: Horizontally centered notes
Date: Wed, 14 Feb 2018 17:41:02 -0500

Hi Caio,

> It is a bit strange that there is no method (that I know of) to write 
> centralized notes

#(define center-column
   (lambda (col)
     (let* ((left-col (ly:grob-object col 'left-neighbor))
            (right-col (ly:grob-object col 'right-neighbor))
            ; If a column adjoining our column is a PaperColumn, ours
            ; is not alone in the measure.  We make no adjustments.
            (alone?
             (and (eq? #t (ly:grob-property left-col 'non-musical))
                  (eq? #t (ly:grob-property right-col 'non-musical)))))
       (if alone?
           (let* ((elts-list
                   (ly:grob-array->list (ly:grob-object col 'elements)))
                  (note-cols
                   (filter
                    (lambda (elt)
                      (grob::has-interface elt 'note-column-interface))
                    elts-list))
                  (all-rests
                   (map (lambda (c)
                          (ly:grob-object c 'rest))
                     note-cols))
                  (all-rests (filter ly:grob? all-rests))
                  (all-notes
                   (map
                    (lambda (c)
                      (ly:grob-object c 'note-heads))
                    note-cols))
                  (all
                   (map (lambda (ga)
                          (if (ly:grob-array? ga)
                              (ly:grob-array->list ga)
                              '()))
                     all-notes))
                  (all (flatten-list all))
                  (all (append all all-rests))
                  (same-dur?
                   (every (lambda (o)
                            (equal?
                             (ly:grob-property o 'duration-log)
                             (ly:grob-property (car all)
                               'duration-log)))
                     all)))
             (if same-dur?
                 (let* ((sys (ly:grob-system col))
                        (col-center (interval-center
                                     (ly:grob-extent col sys X)))
                        (left-right-X
                         (cdr (ly:grob-extent left-col sys X)))
                        (right-left-X
                         (car (ly:grob-extent right-col sys X)))
                        (middle-X
                         (- (average left-right-X right-left-X)
                           col-center)))
                   (ly:grob-translate-axis! col middle-X X))))))))

centerSolitaryPaperColumn =
  \override Score.PaperColumn.after-line-breaking = #center-column

Hope that helps!
Kieren.
________________________________

Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: address@hidden




reply via email to

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