]> git.donarmstrong.com Git - lilypond.git/commitdiff
Move ambitus print callback to scheme.
authorNeil Puttock <n.puttock@gmail.com>
Wed, 26 Aug 2009 20:11:36 +0000 (21:11 +0100)
committerNeil Puttock <n.puttock@gmail.com>
Wed, 26 Aug 2009 20:11:36 +0000 (21:11 +0100)
* 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

13 files changed:
input/regression/ambitus-gap.ly [new file with mode: 0644]
input/regression/ambitus-pitch-ordering.ly
input/regression/ambitus.ly
lily/ambitus-engraver.cc
lily/ambitus.cc [deleted file]
lily/include/ambitus.hh [deleted file]
python/convertrules.py
scm/define-grob-interfaces.scm
scm/define-grob-properties.scm
scm/define-grobs.scm
scm/lily-library.scm
scm/output-lib.scm
scm/safe-lily.scm

diff --git a/input/regression/ambitus-gap.ly b/input/regression/ambitus-gap.ly
new file mode 100644 (file)
index 0000000..6539ce8
--- /dev/null
@@ -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''
+}
+
index 91b2d86d979f764b2f3d38e38c2217ca271667ac..58beb5ace508136a8c0483eb5af5db49c54dbbdf 100644 (file)
@@ -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
 }
+
index f53e3e987b8824fb6852256b9165f2a8bc139680..03c6a776fbeb89de671ed5518cb94a505632783b 100644 (file)
@@ -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'
+  }
 >>
index 2585bd8bc1c0fe00f9f55a85232e97ecb82cc7c1..b1e89885aee9f5bae4bf7a6a21b91f606e99114a 100644 (file)
@@ -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 (file)
index 85fb297..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
-  ambitus.cc -- implement Ambitus
-
-  source file of the GNU LilyPond music typesetter
-
-  (c) 2002--2009 Juergen Reuter <reuter@ipd.uka.de>
-*/
-
-#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<Grob*> (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 (file)
index dc8d3c9..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
-  ambitus.hh
-
-  source file of the GNU LilyPond music typesetter
-
-  (c) 2000--2009 Juergen Reuter <reuter@ipd.uka.de>
-*/
-
-#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
-
index e0d118f11a7826ce0b8400938728311c1e0ce3e7..80e13b6c0a44606c0ffccd7743fe8cde3bd8605a 100644 (file)
@@ -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
index f06b0d4a90c767a94e5cb53e01fae6a87980adbd..23d200ebde905434de288e8fc10365f8eecf898f 100644 (file)
 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."
index d0b65b64e48f2c27230c0e5f28175ceff1fd2b49..0ff4f7641a0f713f90bc19dac75fa780bda10873 100644 (file)
@@ -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.")
 
index 3182c54018f6e718f99d2de81f554038f5d3e0ea..766f2f928af9b60db77781a13dec041640be6d32 100644 (file)
 
     (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
      . (
index e7f1d295d81ea98708163f173acf76e0f6067979..c24683a75ef1543d5a697f6db8c57907efc7d682 100644 (file)
@@ -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))))
index 444f77df06965be181cb0f660dbef72cb85914b7..eee181a928ae3e76603d5c72d407f23b414e4afa 100644 (file)
     (+
      (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)))))
index 1793003de29f8dfb50eb7a015814910e765fd829..2521a4ac772131a3107c44014165e0683693ef2f 100644 (file)
    ;;$defaultlayout
 
    ly:accidental-interface::print
-   ly:ambitus::print
    ly:arpeggio::print
    ly:arpeggio::brew-chord-bracket
    ly:bar-line::print