2018-04-15 5:04 GMT+02:00 Edward Neeman <edward.nee...@gmail.com>:
> My dream option would be to be able to create a function that would give one
> set of shorten-pair values at the Ped. marking, and another set of values
> for the pedal changes.

How about attached.

It doesn't move the "Ped."-marking, though.
Please read comments and doc-strings.
Not tested beyond the given example!

\version "2.18.2" 

#(define (note-column::main-extent grob)
"Return extent of the noteheads in the 'main column', (i.e. excluding any
suspended noteheads), or extent of the rest (if there are no heads)."
  (let* ((note-heads (ly:grob-object grob 'note-heads))
         (stem (ly:grob-object grob 'stem))
         (rest (ly:grob-object grob 'rest)))
    (cond ((ly:grob-array? note-heads)
           (let (;; get the cdr from all note-heads-extents, where the car
                 ;; is zero
                     (lambda (n-h)
                       (let ((ext (ly:grob-extent n-h grob X)))
                          (and (= (car ext) 0) (cdr ext))))
                     (ly:grob-array->list note-heads))))
             ;; better be paranoid, find the max of n-h-right-coords and 
             ;; return a pair with (cons 0 <max>)
             (cons 0.0 (reduce max 0 n-h-right-coords))))
          ((ly:grob? rest)
           (ly:grob-extent rest grob X))
          ;; better be paranoid
          (else '(0 . 0)))))

#(define (adjust-piano-pedal-bracket val)
  (lambda (grob)
    ;; grob is supposed to be PianoPedalBracket.
    ;; Returns a number-pair to set shorten-pair.
    ;; This pair is calculated warranting no gap between consecutive
    ;; PianoPedalBrackets.
    ;; If `val' is #f the extent of left and right bounding
    ;; NoteColumns are calculated. Half of those lengths are taken then.
    ;; (Only the NoteColumn's main extent is taken, disregarding suspended
    ;; NoteHeads)
     (let* ((orig (ly:grob-original grob))
            (siblings (if (ly:grob? orig)
                          (ly:spanner-broken-into orig) '()))
            (with-text? (ly:grob? (ly:grob-object grob 'pedal-text)))
            (left-val #f)
            (right-val #f))
       (if val
             (set! left-val val)
             (set! right-val (- val)))
           (let* ((left-bound (ly:spanner-bound grob LEFT))
                  (left-bound-elts-array (ly:grob-object left-bound 'elements))
                    (if (ly:grob-array? left-bound-elts-array)
                        (ly:grob-array->list left-bound-elts-array)
                      (lambda (g)
                        (grob::has-interface g 'note-column-interface))
                    (if (pair? left-bound-nc-list)
                        (car left-bound-nc-list)
                    (if left-bound-note-column
                             (note-column::main-extent left-bound-note-column))
                  (right-bound (ly:spanner-bound grob RIGHT))
                    (ly:grob-object right-bound 'elements))
                    (if (ly:grob-array? right-bound-elts-array)
                        (ly:grob-array->list right-bound-elts-array)
                      (lambda (g)
                        (grob::has-interface g 'note-column-interface))
                    (if (pair? right-bound-nc-list)
                        (car right-bound-nc-list)
                    (if right-bound-note-column
                             (note-column::main-extent right-bound-note-column))
                  (set! left-val left-val-default)
                  (set! right-val right-val-default)))
       (if (pair? siblings) 
             ((equal? grob (car siblings))
               (if with-text?
                   (cons 0 0)
                   (cons left-val 0)))
             ((equal? grob (last siblings))
               (cons 0 right-val))
               (cons 0 0)))
           (if with-text?
               (cons 0 right-val)
               (cons left-val right-val))))))

adjustPianoPedalBracket =
#(define-music-function (parser location amount mus)((number? #f) ly:music?)
"Adjusts the printed extent of @code{PianoPedalBracket}s.
The optional @var{amount} specifies how much they are extended.
If @var{amount} remains unset half of the extent of the bounding NoteColumns
are used.
Limitation: Doesn't work with @code{\\once}. 
            For one-time usage set @code{'shorten-pair} manually.
  \override Staff.PianoPedalBracket.shorten-pair = 
    #(adjust-piano-pedal-bracket amount)
  \new Staff
    \relative {
      \set Staff.pedalSustainStyle =#'mixed
      c'1\sustainOn d
      <cis d>1 \sustainOff\sustainOn 
      d\sustainOff\sustainOn d\sustainOff e\sustainOn e f\sustainOff f
  \new Staff
    \relative {
      <>^"\\adjustPianoPedalBracket without further argument:"
      \set Staff.pedalSustainStyle =#'mixed
      c'1\sustainOn d
      <cis d>1 \sustainOff\sustainOn 
      d\sustainOff\sustainOn d\sustainOff e\sustainOn e f\sustainOff f
  \new Staff
      <>^"\\adjustPianoPedalBracket with numeric argument:"
      \set Staff.pedalSustainStyle =#'mixed
      \adjustPianoPedalBracket 5
      s1\sustainOn s
      s \sustainOff\sustainOn 
      s\sustainOff\sustainOn s\sustainOff s\sustainOn s s\sustainOff s
lilypond-user mailing list

Reply via email to