Hi Kieren,
On Sun, Mar 22, 2015 at 3:32 PM, Kieren MacMillan <
kieren_macmil...@sympatico.ca> wrote:
> Hi David,
>
> As always, great work! I will use this on all my scores, once it’s
> “perfect”.
>
:)
>
> In the meantime, it doesn’t distinguish cases where centering *shouldn’t*
> be applied, e.g.
>
> \new PianoStaff <<
> \new Staff {
> <c' e' g' c''>1\accent\fermata\f\arpeggio
> c'4 d' e' f'
> R1
> }
> \new Staff {
> R1
> R1
> <c' e' g' c''>1\accent\fermata\f\arpeggio
> }
> \new Staff {
> c'4 r r2
> }
> >>
>
Ah...that's because paper-columns encompass multiple staves... And thus is
dashed all hope of simplicity...
>
> Is there a way to:
> (a) have the function automatically check all staves in the current
> system, and only enable centering if there are only multi-measure rests,
> full-measure notes, or skips/blank; and/or
>
Try the attached out. It will only center an object if the contents of all
staves can reasonably be centered.
> (b) manually enable or disable the function on a per-measure basis?
>
>
Not sure about this. It would be easy, of course, to define shortcuts for
\override/\once \override/\revert and the like, but I fear you have
something more difficult in mind :)
--David
\version "2.19.17"
\paper {
right-margin = 3\in
}
#(define center-column
(lambda (grob)
(if (grob::has-interface grob 'note-column-interface)
(let* ((col (ly:item-get-column grob))
(sys (ly:grob-system col))
(all-cols
(ly:grob-array->list
(ly:grob-object sys 'columns)))
(measure-no
(car (ly:grob-property col 'rhythmic-location)))
; we need to find out if there is another
; PaperColumn in the measure. If there is,
; we make no adjustments.
(in-company?
; is there a column...
(any
(lambda (c)
(and
; which is NOT our column...
(not (eq? col c))
; which is a PaperColumn...
(not (eq? #t (ly:grob-property c 'non-musical)))
; which is in the same measure
(eq?
(car (ly:grob-property c 'rhythmic-location))
measure-no)))
all-cols))
(alone? (not in-company?))) ; :)
(if alone?
(let* ((left-col (ly:grob-object col 'left-neighbor))
(right-col (ly:grob-object col 'right-neighbor))
;(measure-len (ly:grob-property left-col 'measure-length))
(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* ((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))))))
;; do nothing if override applied to something other
;; than NoteColumn
'()
)))
%%%%%%%%%%%%%%
{
\new PianoStaff <<
\new Staff {
<cis' eis' gis' cis''>1\accent\fermata\f\arpeggio
c'4 d' e' f'
R1
}
\new Staff {
R1
R1
<c' e' g' c''>1\accent\fermata\f\arpeggio
}
>>
}
\new PianoStaff <<
\new Staff {
<c' e' g' c''>1\accent\fermata\f\arpeggio
c'4 d' e' f'
R1
}
\new Staff {
R1
R1
<c' e' g' c''>1\accent\fermata\f\arpeggio
}
\new Staff {
c'4 r4 r2
R1
<<
{
\voiceOne c''1
}
\new Voice {
\voiceTwo c1
}
>>
}
>>
\new PianoStaff <<
\new Staff {
<c' e' g' c''>1\accent\fermata\f\arpeggio
c'4 d' e' f'
R1
}
\new Staff {
R1
R1
<c' e' g' c''>1\accent\fermata\f\arpeggio
}
\new Staff {
c'4 s4 s2
R1
<<
{
\voiceOne c''4
}
\new Voice {
\voiceTwo c1
}
>>
}
>>
\layout {
ragged-right = ##f
\context {
\Voice
\override NoteColumn.after-line-breaking = #center-column
}
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user