From 1883fef6da1f91b1985ac296f0eb5bc9aee613ec Mon Sep 17 00:00:00 2001 From: Janek Warchol Date: Mon, 13 Jun 2011 00:34:45 +0200 Subject: [PATCH] make sure that AmbitusLine is visible for small ambits 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 | 10 +++++++++- scm/define-grob-interfaces.scm | 2 ++ scm/define-grob-properties.scm | 2 ++ scm/define-grobs.scm | 4 +++- scm/output-lib.scm | 31 +++++++++++++++++++++++++++++-- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/input/regression/ambitus-gap.ly b/input/regression/ambitus-gap.ly index 106b956eb9..65848e4507 100644 --- a/input/regression/ambitus-gap.ly +++ b/input/regression/ambitus-gap.ly @@ -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' } +>> diff --git a/scm/define-grob-interfaces.scm b/scm/define-grob-interfaces.scm index 54d360903a..59a97b6967 100644 --- a/scm/define-grob-interfaces.scm +++ b/scm/define-grob-interfaces.scm @@ -35,6 +35,8 @@ note)." 'ambitus-interface "The line between note heads for a pitch range." '(gap + length-fraction + maximum-gap note-heads thickness)) diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index b779edbb4f..93859cb504 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -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 diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 184d086b30..9a0576454e 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -141,7 +141,9 @@ (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) diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 23ff2640bb..7d83471e72 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -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)) -- 2.39.5