From fe50accb90e596532cd211a314c8a53196686487 Mon Sep 17 00:00:00 2001 From: Neil Puttock Date: Wed, 26 Aug 2009 21:11:36 +0100 Subject: [PATCH] Move ambitus print callback to scheme. * implement ambitus::print callback in output-lib.scm * add interface description to define-grob-interfaces.scm * allow user override of padding using grob property 'gap * remove 'join-heads * remove ambitus.cc/.hh * tidy ambitus-engraver.cc * add regression test for 'gap * add convert rule for ly:ambitus::print --- input/regression/ambitus-gap.ly | 20 ++++++ input/regression/ambitus-pitch-ordering.ly | 12 ++-- input/regression/ambitus.ly | 33 ++++----- lily/ambitus-engraver.cc | 38 ++++++----- lily/ambitus.cc | 78 ---------------------- lily/include/ambitus.hh | 24 ------- python/convertrules.py | 5 +- scm/define-grob-interfaces.scm | 5 ++ scm/define-grob-properties.scm | 3 - scm/define-grobs.scm | 7 +- scm/lily-library.scm | 3 + scm/output-lib.scm | 35 ++++++++++ scm/safe-lily.scm | 1 - 13 files changed, 111 insertions(+), 153 deletions(-) create mode 100644 input/regression/ambitus-gap.ly delete mode 100644 lily/ambitus.cc delete mode 100644 lily/include/ambitus.hh diff --git a/input/regression/ambitus-gap.ly b/input/regression/ambitus-gap.ly new file mode 100644 index 0000000000..6539ce8550 --- /dev/null +++ b/input/regression/ambitus-gap.ly @@ -0,0 +1,20 @@ +\version "2.13.4" + +\header { + texidoc = "The gaps between an @code{AmbitusLine} and its +note heads are set by the @code{gap} property." +} + +\layout { + \context { + \Voice + \consists "Ambitus_engraver" + } +} + +\new Staff { + \time 2/4 + \override AmbitusLine #'gap = #1 + c'4 g'' +} + diff --git a/input/regression/ambitus-pitch-ordering.ly b/input/regression/ambitus-pitch-ordering.ly index 91b2d86d97..58beb5ace5 100644 --- a/input/regression/ambitus-pitch-ordering.ly +++ b/input/regression/ambitus-pitch-ordering.ly @@ -1,13 +1,11 @@ -\header { - texidoc = "Ambituses use actual pitch not lexicographic ordering." - } - \version "2.12.0" -\paper { - ragged-right=##t +\header { + texidoc = "Ambitus use actual pitch not lexicographic ordering." } \new Voice \with { \consists "Ambitus_engraver" } { - \clef F c eis fes + \clef F + c4 eis fes2 } + diff --git a/input/regression/ambitus.ly b/input/regression/ambitus.ly index f53e3e987b..03c6a776fb 100644 --- a/input/regression/ambitus.ly +++ b/input/regression/ambitus.ly @@ -1,27 +1,28 @@ +\version "2.12.0" + \header { - texidoc = "Ambituses indicate pitch ranges for voices. + texidoc = "Ambitus indicate pitch ranges for voices. Accidentals only show up if they're not part of key -signature. @code{AmbitusNoteHead} grobs also have ledger lines. - +signature. @code{AmbitusNoteHead} grobs also have ledger lines. " } -\version "2.12.0" \layout { - ragged-right = ##t - \context { - \Voice - \consists Ambitus_engraver - } + \context { + \Voice + \consists "Ambitus_engraver" + } } -\relative << - \new Staff { \time 2/4 c4 f' } - \new Staff \relative { - \time 2/4 - \key d \major - cis as' - } + \new Staff \relative c'{ + \time 2/4 + c4 f' + } + \new Staff \relative c' { + \time 2/4 + \key d \major + cis as' + } >> diff --git a/lily/ambitus-engraver.cc b/lily/ambitus-engraver.cc index 2585bd8bc1..b1e89885ae 100644 --- a/lily/ambitus-engraver.cc +++ b/lily/ambitus-engraver.cc @@ -82,8 +82,8 @@ Ambitus_engraver::create_ambitus () Ambitus_engraver::Ambitus_engraver () { ambitus_ = 0; - heads_[LEFT] = heads_[RIGHT] = 0; - accidentals_[LEFT] = accidentals_[RIGHT] = 0; + heads_.set (0, 0); + accidentals_.set (0, 0); group_ = 0; is_typeset_ = false; start_key_sig_ = SCM_EOL; @@ -145,8 +145,7 @@ Ambitus_engraver::finalize () if (ambitus_ && !pitch_interval_.is_empty ()) { Grob *accidental_placement = - make_item ("AccidentalPlacement", - accidentals_[DOWN]->self_scm ()); + make_item ("AccidentalPlacement", accidentals_[DOWN]->self_scm ()); Direction d = DOWN; do @@ -154,8 +153,7 @@ Ambitus_engraver::finalize () Pitch p = pitch_interval_[d]; heads_[d]->set_property ("cause", causes_[d]->self_scm()); heads_[d]->set_property ("staff-position", - scm_from_int (start_c0_ - + p.steps ())); + scm_from_int (start_c0_ + p.steps ())); SCM handle = scm_assoc (scm_cons (scm_from_int (p.get_octave ()), scm_from_int (p.get_notename ())), @@ -166,7 +164,8 @@ Ambitus_engraver::finalize () start_key_sig_); Rational sig_alter = (handle != SCM_BOOL_F) - ? robust_scm2rational (scm_cdr (handle), Rational (0)) : Rational (0); + ? robust_scm2rational (scm_cdr (handle), Rational (0)) + : Rational (0); if (sig_alter == p.get_alteration ()) { @@ -174,17 +173,19 @@ Ambitus_engraver::finalize () heads_[d]->set_object ("accidental-grob", SCM_EOL); } else - { - accidentals_[d]->set_property ("alteration", ly_rational2scm (p.get_alteration ())); - } - Separation_item::add_conditional_item (heads_[d], accidental_placement); - Accidental_placement::add_accidental (accidental_placement, accidentals_[d]); + accidentals_[d]-> + set_property ("alteration", + ly_rational2scm (p.get_alteration ())); + Separation_item::add_conditional_item (heads_[d], + accidental_placement); + Accidental_placement::add_accidental (accidental_placement, + accidentals_[d]); + Pointer_group_interface::add_grob (ambitus_, + ly_symbol2scm ("note-heads"), + heads_[d]); } while (flip (&d) != DOWN); - - Pointer_group_interface::add_grob (ambitus_, ly_symbol2scm ("note-heads"), heads_[DOWN]); - Pointer_group_interface::add_grob (ambitus_, ly_symbol2scm ("note-heads"), heads_[UP]); Axis_group_interface::add_element (group_, accidental_placement); } else @@ -194,7 +195,7 @@ Ambitus_engraver::finalize () { accidentals_[d]->suicide (); heads_[d]->suicide (); - } + } while (flip (&d) != DOWN); ambitus_->suicide (); @@ -204,7 +205,7 @@ Ambitus_engraver::finalize () ADD_ACKNOWLEDGER (Ambitus_engraver, note_head); ADD_TRANSLATOR (Ambitus_engraver, /* doc */ - "", + "Create an ambitus.", /* create */ "AccidentalPlacement " @@ -214,7 +215,8 @@ ADD_TRANSLATOR (Ambitus_engraver, "AmbitusNoteHead ", /* read */ - "", + "keySignature " + "middleCPosition ", /* write */ "" diff --git a/lily/ambitus.cc b/lily/ambitus.cc deleted file mode 100644 index 85fb297886..0000000000 --- a/lily/ambitus.cc +++ /dev/null @@ -1,78 +0,0 @@ -/* - ambitus.cc -- implement Ambitus - - source file of the GNU LilyPond music typesetter - - (c) 2002--2009 Juergen Reuter -*/ - -#include "ambitus.hh" - -#include "staff-symbol-referencer.hh" -#include "pitch.hh" -#include "note-head.hh" -#include "item.hh" -#include "font-interface.hh" -#include "output-def.hh" -#include "lookup.hh" -#include "pointer-group-interface.hh" - -MAKE_SCHEME_CALLBACK (Ambitus, print, 1); -SCM -Ambitus::print (SCM smob) -{ - Item *me = (Item *) unsmob_grob (smob); - Stencil stencil; - - // FIXME : should be Ambitus_line join heads - extract_grob_set (me, "note-heads", heads); - if (to_boolean (me->get_property ("join-heads")) - && heads.size () > 1) - { - Grob *common - = common_refpoint_of_array (vector (heads.begin (), - heads.begin () + 2), - me, Y_AXIS); - - Grob *minh = heads[0]; - Grob *maxh = heads[1]; - - if (minh->relative_coordinate (common, Y_AXIS) - > maxh->relative_coordinate (common, Y_AXIS)) - { - Grob *t = maxh; - maxh = minh; - minh = t; - } - - Real pad = 0.35; - Real pmax = maxh->extent (common, Y_AXIS)[DOWN] - pad; - Real pmin = minh->extent (common, Y_AXIS)[UP] + pad; - - if (pmin < pmax) - { - Real linethickness = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness")) - * robust_scm2double (me->get_property ("thickness"), 1.0); - Real blotdiameter = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter")); - Interval x_extent = 0.5 * linethickness * Interval (-1, 1); - Interval y_extent = Interval (pmin, pmax); - Box line_box (x_extent, y_extent); - - Stencil line = Lookup::round_filled_box (line_box, blotdiameter); - line.translate_axis (- me->relative_coordinate (common, Y_AXIS), - Y_AXIS); - return line.smobbed_copy (); - } - } - - return SCM_EOL; -} - -ADD_INTERFACE (Ambitus, - "The line between note heads for a pitch range.", - - /* properties */ - "join-heads " - "note-heads " - "thickness " - ); diff --git a/lily/include/ambitus.hh b/lily/include/ambitus.hh deleted file mode 100644 index dc8d3c9bfd..0000000000 --- a/lily/include/ambitus.hh +++ /dev/null @@ -1,24 +0,0 @@ -/* - ambitus.hh - - source file of the GNU LilyPond music typesetter - - (c) 2000--2009 Juergen Reuter -*/ - -#ifndef AMBITUS_HH -#define AMBITUS_HH - -#include "lily-proto.hh" -#include "grob-interface.hh" - -struct Ambitus -{ - DECLARE_SCHEME_CALLBACK (print, (SCM smob)); - DECLARE_GROB_INTERFACE(); - static Slice get_positions (Grob *); - static Interval head_width (Grob *me, Grob *common); -}; - -#endif // AMBITUS_HH - diff --git a/python/convertrules.py b/python/convertrules.py index e0d118f11a..80e13b6c0a 100644 --- a/python/convertrules.py +++ b/python/convertrules.py @@ -2914,7 +2914,8 @@ added. BeatGrouping has been eliminated.\n\ Different settings for vertical layout.\n\ ly:system-start-text::print -> system-start-text::print\n\ Beam #'thickness -> Beam #'beam-thickness\n\ -ly:note-head::brew-ez-stencil -> note-head::brew-ez-stencil")) +ly:note-head::brew-ez-stencil -> note-head::brew-ez-stencil\n\ +ly:ambitus::print -> ambitus::print")) def conv(str): if re.search("override-auto-beam-setting", str): stderr_write ("\n") @@ -2937,7 +2938,7 @@ def conv(str): stderr_write(NOT_SMART % _("alignment-offsets has been changed to alignment-distances: \ you must now specify the distances between staves rather than the offset of staves.\n")) stderr_write(UPDATE_MANUALLY) - str = re.sub ('ly:(system-start-text::print|note-head::brew-ez-stencil)', + str = re.sub ('ly:(system-start-text::print|note-head::brew-ez-stencil|ambitus::print)', '\\1', str) str = re.sub ('(\\bBeam\\s+#\')(?=thickness\\b)', '\\1beam-', str) return str diff --git a/scm/define-grob-interfaces.scm b/scm/define-grob-interfaces.scm index f06b0d4a90..23d200ebde 100644 --- a/scm/define-grob-interfaces.scm +++ b/scm/define-grob-interfaces.scm @@ -15,6 +15,11 @@ note)." '()) +(ly:add-interface + 'ambitus-interface + "The line between note heads for a pitch range." + '(gap note-heads thickness)) + (ly:add-interface 'bass-figure-interface "A bass figure text." diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index d0b65b64e4..0ff4f7641a 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -471,7 +471,6 @@ position a non-spaced line relative to the staff for which it has affinity. See @var{next-staff-spacing} for the format of this list.") - ;; ;; k ;; @@ -1073,8 +1072,6 @@ ligature grob in (in @code{staff-space} units).") (inclinatum ,boolean? "Is this neume an inclinatum?") - (join-heads ,boolean? "Whether to join the note heads of an ambitus -grob with a vertical line.") (join-right-amount ,number? "A length used for calculating the Y-extent of mensural ligatures.") diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 3182c54018..766f2f928a 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -122,14 +122,13 @@ (AmbitusLine . ( - (join-heads . #t) - (stencil . ,ly:ambitus::print) + (gap . 0.35) + (stencil . ,ambitus::print) (thickness . 2) (X-offset . ,ly:self-alignment-interface::centered-on-x-parent) (meta . ((class . Item) (interfaces . (ambitus-interface - font-interface - staff-symbol-referencer-interface)))))) + font-interface)))))) (AmbitusNoteHead . ( diff --git a/scm/lily-library.scm b/scm/lily-library.scm index e7f1d295d8..c24683a75e 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -398,6 +398,9 @@ found." (define-public empty-interval '(+inf.0 . -inf.0)) +(define-public (symmetric-interval expr) + (cons (- expr) expr)) + (define-public (interval-length x) "Length of the number-pair X, when an interval" (max 0 (- (cdr x) (car x)))) diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 444f77df06..eee181a928 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -766,3 +766,38 @@ (+ (ly:self-alignment-interface::y-aligned-on-self grob) (interval-center extent)))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ambitus + +(define-public (ambitus::print 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)) + (gap (ly:grob-property grob 'gap 0.35)) + (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) + (let* ((layout (ly:grob-layout grob)) + (line-thick (ly:output-def-lookup layout 'line-thickness)) + (blot (ly:output-def-lookup layout 'blot-diameter)) + (grob-thick (ly:grob-property grob 'thickness 2)) + (width (* line-thick grob-thick)) + (x-ext (symmetric-interval (/ width 2))) + (y-ext (cons point-min point-max)) + (line (ly:round-filled-box x-ext y-ext blot)) + (y-coord (ly:grob-relative-coordinate grob common Y))) + + (ly:stencil-translate-axis line (- y-coord) Y)) + empty-stencil)) + (begin + (ly:grob-suicide! grob) + (list))))) diff --git a/scm/safe-lily.scm b/scm/safe-lily.scm index 1793003de2..2521a4ac77 100644 --- a/scm/safe-lily.scm +++ b/scm/safe-lily.scm @@ -144,7 +144,6 @@ ;;$defaultlayout ly:accidental-interface::print - ly:ambitus::print ly:arpeggio::print ly:arpeggio::brew-chord-bracket ly:bar-line::print -- 2.39.2