lilypond-user
[Top][All Lists]
Advanced

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

Re: Controlling hairpin length


From: Thomas Morley
Subject: Re: Controlling hairpin length
Date: Sat, 12 Dec 2015 22:35:03 +0100

2015-12-12 17:46 GMT+01:00 David Sumbler <address@hidden>:
> Although I quite often find myself needing to use
>
> \override Voice.Hairpin.minimum-length = #2
>
> or similar, I find that the results are unpredictable (to me!)
>
> Sometimes I have a very short hairpin, perhaps starting on a quaver and
> ending on the next quaver.  In the output such a hairpin sometimes
> appears as a short vertical line (i.e. with length=0), and a warning is
> shown in the compiler output.
>
> If I change Hairpin.minimum-length I have to do it by trial and error,
> because the result does not seem necessarily to correspond to the value
> I have specified.  (I am assuming that the units are staff spaces.)  I'm
> guessing that this may perhaps be something to do with having an actual
> dynamic such as mf attached to one or both notes.

It's issue 2207
https://sourceforge.net/p/testlilyissues/issues/2207/

>
> The Internals Reference says that use of the minimum-length property
> with a hairpin "requires an appropriate callback for the
> springs-and-rods property".  Unfortunately I have no clear idea what
> this means, and I haven't managed to find out yet either by searching or
> by experimentation.  The best I have come up with so far is
>
> \override Hairpin.springs-and-rods = #ly:spanner::set-spacing-rods

This is already the default for Hairpins (but nor for Glissando par example)
No need to set it again in your file.

>
> This doesn't improve the output at all, but at least it doesn't produce
> any additional error or warning!
>
> How can I guarantee that all hairpins will be printed with a minimum
> length of, say, 1.5 staff spaces, and the notes spaced appropriately,
> regardless of preceding or following dynamics?

You may find the discussion at the linked issue enlightning.

For now you may try the following as a workaround.
Though, please be aware it's not tested beyond the example, your turn ;)
Ofcorse I'll try to improve the code, if you notice issues

\version "2.18.2"

%% a helper:
#(define (look-up-for-parent name-symbol axis grob)
"Return the parent of @var{grob}, specified by it's @var{name-symbol} in
axis @var{axis} or @var{grob}, if equal to the grob named @var{name-symbol}
already.
If not found, look up for the next parent."
 (let* ((parent (ly:grob-parent grob axis)))
 (cond
   ((not (ly:grob? parent))
    (ly:error
       (_"Perhaps typing error for \"~a\" or \"~a\" is not in the parent-tree.")
       name-symbol name-symbol))
   ((equal? name-symbol (grob::name grob)) grob)
   ((not (equal? name-symbol (grob::name parent)))
    (look-up-for-parent name-symbol axis parent))
   (else parent))))

#(define ((hairpin-minimum-length my-minimum) grob)
  (let* ((bound-left (ly:spanner-bound grob LEFT))
         (bound-right (ly:spanner-bound grob RIGHT))
         (sys (look-up-for-parent 'System Y grob))
         (left-x-ext (ly:grob-extent bound-left sys X))
         (right-x-ext (ly:grob-extent bound-right sys X)))
    (ly:grob-set-property! grob 'minimum-length
      ;; keep 'minimum-length user-settable
      (max (ly:grob-property-data grob 'minimum-length)
           ;; nb, this calculation is only an approximation
           ;; should work in most cases, though
           (+ my-minimum (abs (cdr left-x-ext)) (abs (cdr right-x-ext)))))))

myHairpinMinimumLength =
#(define-music-function (parser location minimum)(number?)
#{
  \override Hairpin.before-line-breaking =
    #(hairpin-minimum-length minimum)
#})

{
    \override Hairpin.color = #red
    \myHairpinMinimumLength #1.5
    \repeat unfold 8 { c4\ffff\> d\pppp\! c d \noBreak }
    \break
    %% overriding 'minimum-length is still possible
    \override Hairpin.minimum-length = 20
    \repeat unfold 8 { c4\ffff\> d\pppp\! c d \noBreak }
}



HTH,
  Harm



reply via email to

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