lilypond-devel
[Top][All Lists]
Advanced

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

ambitus: special handling of small ambits' lines (issue4609041)


From: lemniskata . bernoullego
Subject: ambitus: special handling of small ambits' lines (issue4609041)
Date: Sun, 12 Jun 2011 23:04:49 +0000

Reviewers: Mike,

Description:
ambitus: special handling of small ambits' lines

Until now, it was not possible to have all ambits
look good: either the gaps between ambit line
and heads were too big for ambits of 4th and 5th,
or they were too small for other ambits.
This patch introduces automatic scaling
of the gap between heads and line: bigger ambits
are left unchanged, but smaller have their gap
diminished so that the line is long enough.

Please review this at http://codereview.appspot.com/4609041/

Affected files:
  M scm/output-lib.scm


Index: scm/output-lib.scm
diff --git a/scm/output-lib.scm b/scm/output-lib.scm
index c25edf31f68a93de749a87e69e26cd4dde6dfc3d..dc2ff7a159313545f08fbfcb135a4a11b9f323fa 100644
--- a/scm/output-lib.scm
+++ b/scm/output-lib.scm
@@ -915,13 +915,44 @@ between the two text elements."
        (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))
+              ;; top of lower ambitus head:
+              (ground (interval-end (ly:grob-extent head-down common Y)))
+              ;; bottom of upper ambitus head:
+              (roof (interval-start (ly:grob-extent head-up common Y)))
+              ;; total amount of space between ambitus heads -
+              ;; our task is to decide how much of this space will be occupied
+              ;; by the ambitus line. We do this by calculating how big the 
gaps
+              ;; between ambitus line and ambitus heads will be.
+              (space-between-heads (- roof ground))
+              ;; read the property - this is our starting point;
+              ;; we are going to adjust it to fit small ambituses better:
+              (gap-property (ly:grob-property grob 'gap 0.35))
+              ;; We calculate a theoretical gap size using a linear function.
+              ;; the function was determined by trial-and-error; it's main
+              ;; premises are: gap is proportional to space between heads,
+              ;; big value in gap property means that small ambituses won't
+              ;; have any line at all, for values around 0.45 (default)
+              ;; gap approaches 0 when distance betweeen heads approaches 0,
+              ;; and it shouldn't reach 0 too soon with very small values.
+              (proportional (+ (max gap-property 0.3) -0.45
+                             (* 0.2 space-between-heads)))
+              ;; ambitus line looks best if the gap value is quanted.
+              ;; optimal quants are: 0.2 0.45 0.7 0.95 1.2 etc.
+ (quanted-gap (+ (* (floor (/ (- proportional 0.2) 0.25)) 0.25) 0.2))
+              ;; we don't want to quant gap values smaller than 0.2
+              ;; (because quanting them would mean making them 0).
+              (theoretical (if (< proportional 0.2) proportional quanted-gap))
+              ;; The above calculations are mainly for small ambituses;
+              ;; in case of bigger ones they would lead to very big gaps
+              ;; so we restrict them by the value written in the gap property.
+              ;; we also don't want gap values too close to 0, hence the max.
+              (gap (max (min theoretical gap-property) (/ gap-property 4.5)))
               (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.1
              (let* ((layout (ly:grob-layout grob))
                     (line-thick (ly:output-def-lookup layout 'line-thickness))
                     (blot (ly:output-def-lookup layout 'blot-diameter))





reply via email to

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