]> git.donarmstrong.com Git - lilypond.git/commitdiff
make sure that AmbitusLine is visible for small ambits
authorJanek Warchol <lemniskata.bernoullego@gmail.com>
Sun, 12 Jun 2011 22:34:45 +0000 (00:34 +0200)
committerJanek Warchoł <lemniskata.bernoullego@gmail.com>
Fri, 6 Sep 2013 07:51:54 +0000 (09:51 +0200)
Until now, the gap between ambitus heads and ambitus line
was constant, so either the gap had to be very small or
the line wasn't visible in case of smaller ambits (like
4th or 5th). With this patch ambitus gap will be calculated
dynamically, depending on the distance between ambitus heads.

Also, the default gap for bigger ambits is changed so that
ambitus line will end precisely in the staffline or in the
middle of staffspace.

input/regression/ambitus-gap.ly
scm/define-grob-interfaces.scm
scm/define-grob-properties.scm
scm/define-grobs.scm
scm/output-lib.scm

index 106b956eb93059e4c623b65f554bc3b5d2a6fe50..65848e4507f2af14fb47415dcab64dcd6c2c1182 100644 (file)
@@ -2,7 +2,9 @@
 
 \header {
   texidoc = "The gaps between an @code{AmbitusLine} and its
-note heads are set by the @code{gap} property."
+note heads are set by the @code{gap} property. By default,
+@code{gap} is a function that reduces the gap for small intervals
+(e.g. a fourth), so that the line remains visible."
 }
 
 \layout {
@@ -18,3 +20,9 @@ note heads are set by the @code{gap} property."
   c'4 g''
 }
 
+\new Staff <<
+  \time 2/4
+  { d'' g'' }
+  \\
+  { c' g' }
+>>
index 54d360903ae5924731dc9988fbf086ffb57f30df..59a97b69670867c6c85ed0dd4d8aae976374c9b7 100644 (file)
@@ -35,6 +35,8 @@ note)."
  'ambitus-interface
  "The line between note heads for a pitch range."
  '(gap
+   length-fraction
+   maximum-gap
    note-heads
    thickness))
 
index b779edbb4f13b61a3670654a3ab127ffb018ce76..93859cb50444bca1b6ffb3c8ebe30f41f45608d5 100644 (file)
@@ -578,6 +578,8 @@ to beams from this stem.  Further beams are typeset as beamlets.")
      (max-stretch ,number? "The maximum amount that this
 @code{VerticalAxisGroup} can be vertically stretched (for example, in
 order to better fill a page).")
+     (maximum-gap ,number? "Maximum value allowed for @code{gap}
+property.")
      (measure-count ,integer? "The number of measures for a
 multi-measure rest.")
      (measure-length ,ly:moment? "Length of a measure.  Used in some
index 184d086b304216b0fb21d977a83ed5d3728c4ec1..9a0576454ef908b18eddde8eb6dae3d103307bfb 100644 (file)
 
     (AmbitusLine
      . (
-        (gap . 0.35)
+        (gap . ,ambitus-line::calc-gap)
+        (length-fraction . 0.7)
+        (maximum-gap . 0.45)
         (stencil . ,ambitus::print)
         (thickness . 2)
         (X-offset . ,ly:self-alignment-interface::centered-on-x-parent)
index 23ff2640bb4f3efce22411efd1b6fbb907999a15..7d83471e72630467f0b061e8dd907daa8e1b6398 100644 (file)
@@ -1241,6 +1241,31 @@ parent or the parent has no setting."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; ambitus
 
+;; Calculate the gaps between ambitus heads and ends of ambitus line.
+;; Start by determining desired length of the ambitus line (based on
+;; length-fraction property), calc gap from that and make sure that
+;; it doesn't exceed maximum allowed value.
+
+(define-public (ambitus-line::calc-gap grob)
+  (let ((heads (ly:grob-object grob 'note-heads)))
+
+  (if (and (ly:grob-array? heads)
+             (= (ly:grob-array-length heads) 2))
+      (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
+              (head-down (ly:grob-array-ref heads 0))
+              (head-up (ly:grob-array-ref heads 1))
+              (fraction (ly:grob-property grob 'length-fraction 0.7))
+              (max-gap (ly:grob-property grob 'maximum-gap 0.45))
+              ; distance between noteheads:
+              (distance (- (interval-start (ly:grob-extent head-up common Y))
+                          (interval-end (ly:grob-extent head-down common Y))))
+              (gap (* 0.5 distance (- 1 fraction))))
+
+         (min gap max-gap))
+      0)))
+
+;; Print a line connecting ambitus heads:
+
 (define-public (ambitus::print grob)
   (let ((heads (ly:grob-object grob 'note-heads)))
 
@@ -1249,13 +1274,15 @@ parent or the parent has no setting."
         (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
                (head-down (ly:grob-array-ref heads 0))
                (head-up (ly:grob-array-ref heads 1))
-               (gap (ly:grob-property grob 'gap 0.35))
+               ;; The value used when 'gap' property cannot be read is small
+               ;; to make sure that ambitus of a fifth will have a visible line.
+               (gap (ly:grob-property grob 'gap 0.25))
                (point-min (+ (interval-end (ly:grob-extent head-down common Y))
                              gap))
                (point-max (- (interval-start (ly:grob-extent head-up common Y))
                              gap)))
 
-          (if (< point-min point-max)
+          (if (< (+ point-min 0.1) point-max) ; don't print lines shorter than 0.1ss
               (let* ((layout (ly:grob-layout grob))
                      (line-thick (ly:output-def-lookup layout 'line-thickness))
                      (blot (ly:output-def-lookup layout 'blot-diameter))