lilypond-user
[Top][All Lists]
Advanced

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

Re: shorten a broken hairpin at a linebreak?


From: David Nalesnik
Subject: Re: shorten a broken hairpin at a linebreak?
Date: Mon, 29 Aug 2011 19:01:47 -0500


Not sure about calculating the other end of the whiteout box (from position of the barline, I suppose).

Hi, again --

More experimenting yielded this, which automates the calculation of the width of the whiteout stencil.  I'm not sure how to handle the positioning on the first line, hence the list of offsets in the input.  (A number moves the stencil that far to the left.)  I changed the line-width and added some measures as a test.  Seems to work OK -- except that there is still a tiny trace of hairpins at the line ends :(

Best,
David

\version "2.14.2"

\paper {
  line-width = 6\in
}
#(define (last-bar grob)
   ;; return the X-coordinate of the last barline on a line
   (let* ((sys (ly:grob-system grob))
 (array (ly:grob-object sys 'all-elements))
 (grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
 (lst (filter (lambda (x) (eq? 'BarLine (grob-name x)))
                       (ly:grob-array->list array)))
 (bar-coords (sort (map (lambda (x) (ly:grob-relative-coordinate x sys X)) lst) <)))
 
     (define (find-last-bar bar-coords)
       (if (null? (cdr bar-coords))
    (car bar-coords)
  (find-last-bar (cdr bar-coords))))
  
  (find-last-bar bar-coords)))
  
eraseBrokenHairpin =
#(define-music-function (parser location extent)(list?)
#{
   #(define ((hairpin-eraser extent) grob)
      (ly:stencil-add
(ly:hairpin::print grob)
 ;(stencil-with-color (ly:round-filled-box extent (cons -1 1) 0.0) red)))
 (stencil-with-color (ly:round-filled-box extent (cons -1 1) 0.0) white)))

   #(define (hairpin-callback grob)
     (let* ((orig (ly:grob-original grob))
   (siblings (if (ly:grob? orig)
(ly:spanner-broken-into orig)
'() ))
   (line-width (ly:output-def-lookup (ly:grob-layout grob) 'line-width))
   (bar-pos (last-bar grob)))
   
(define (recursion-helper ls1 ls2 ls3)
  (if (or (null? ls1) (null? ls2))
  ls3
  (append ls3
     (list
(if (and (>= (length ls1) 1)(eq? (car ls1) grob))
    (ly:grob-set-property! grob 'stencil
  (hairpin-eraser (cons (- bar-pos (car ls2)) (- line-width (car ls2))))))
(recursion-helper (cdr ls1) (cdr ls2) ls3 )))))

(define (recursion lst1 lst2)
  (recursion-helper lst1 lst2 '()))
  (display bar-pos) (newline)
   (recursion siblings $extent)))

        \once \override Voice.Hairpin #'after-line-breaking = #hairpin-callback
 #})

%----------------------- Test
%--------------------------------------------------

\relative c' {
       \override Hairpin #'color = #red
       \key ces\major
       \eraseBrokenHairpin #(list 24 0 0) %% offsets to whiteout stencil
               c'1\< ~ c
       \break
       \key cis\major
               d2  e e1
       \break
       \key es\major
       \time 2/2
               f2 g
       \break
       \key e\major
       \time 4/4
               a b\!
}


reply via email to

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