]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/hairpin.cc
2003 -> 2004
[lilypond.git] / lily / hairpin.cc
index 26518b007f167fc25e0a7b746b3676a07772e366..00d315f4099f39110e7548eb8c8a3e57485ce5d3 100644 (file)
@@ -3,17 +3,20 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+#include "staff-symbol-referencer.hh"
 #include "molecule.hh"
+#include "line-interface.hh"
 #include "hairpin.hh"
 #include "spanner.hh"
 #include "font-interface.hh"
 #include "dimensions.hh"
 #include "paper-def.hh"
-#include "debug.hh"
+#include "warn.hh"
 #include "paper-column.hh"
+#include "lookup.hh"
 
 MAKE_SCHEME_CALLBACK (Hairpin, brew_molecule, 1);
 
@@ -23,10 +26,8 @@ Hairpin::brew_molecule (SCM smob)
   Grob *me= unsmob_grob (smob);
   Spanner *spanner = dynamic_cast<Spanner*> (me);
 
-  Real line = me->paper_l ()->get_var ("stafflinethickness");  
-  
   SCM s = me->get_grob_property ("grow-direction");
-  if (!ly_dir_p (s))
+  if (!is_direction (s))
     {
       me->suicide ();
       return SCM_EOL;
@@ -35,7 +36,11 @@ Hairpin::brew_molecule (SCM smob)
   Direction grow_dir = to_dir (s);
 
 
-  /* Ugh, must be same as Text_spanner::brew_molecule.  */  
+  /* Ugh, must be same as Text_spanner::brew_molecule.  */
+
+  /*
+    Ugh. property name is not general.
+   */
   Real padding = gh_scm2double (me->get_grob_property ("if-text-padding"));
  
   Drul_array<bool> broken;
@@ -70,7 +75,7 @@ Hairpin::brew_molecule (SCM smob)
                make the padding a little smaller, here.
              */
              Interval e =b->extent (common, X_AXIS);
-             if (e.empty_b ())
+             if (e.is_empty ())
                e = Interval (0,0) + b->relative_coordinate (common, X_AXIS);
              
              x_points[d] = e.center () - d  * padding /3; // ugh.
@@ -78,7 +83,7 @@ Hairpin::brew_molecule (SCM smob)
          else
            {
              Interval e =b->extent (common, X_AXIS);
-             if (!e.empty_b ())
+             if (!e.is_empty ())
                x_points[d] = e[-d] - d*padding;
            }
        }
@@ -96,8 +101,8 @@ Hairpin::brew_molecule (SCM smob)
     }
 
   bool continued = broken[Direction (-grow_dir)];
-  Real height = gh_scm2double (me->get_grob_property ("height"));
-  Real thick = line * gh_scm2double (me->get_grob_property ("thickness"));
+  Real height = robust_scm2double (me->get_grob_property ("height"), 0.2) *
+    Staff_symbol_referencer::staff_space (me);
 
   Real starth, endh;
   if (grow_dir < 0)
@@ -110,33 +115,26 @@ Hairpin::brew_molecule (SCM smob)
       starth = continued ? height/2 : 0.0;
       endh = height;
     }
-  
+
   /*
-    TODO: junk this and, make a general
+    should do relative to staff-symbol staff-space?
+   */
 
-    Lookup::line  (XY1, XY2).
-  */
-  SCM hairpin = scm_list_n (ly_symbol2scm ("hairpin"),
-                        gh_double2scm (thick),
-                        gh_double2scm (width),
-                        gh_double2scm (starth),
-                        gh_double2scm (endh),
-                        SCM_UNDEFINED);
+  Molecule mol;
+  mol  = Line_interface::line (me, Offset (0, starth), Offset (width, endh));
+  mol.add_molecule (Line_interface::line (me,
+                                                Offset (0, -starth),
+                                                Offset (width, -endh)));
 
-  /*
-    We make the hairpin too large in Y direction, so it stays at
-    proper distance from the staff.
-  */
-  Interval yext = 2* height  * Interval (-1,1);
-  Box b (Interval (0, width), yext);
-  Molecule mol (b, hairpin);
-  
   mol.translate_axis (x_points[LEFT]
                      - bounds[LEFT]->relative_coordinate (common, X_AXIS),
                      X_AXIS);
-
   return mol.smobbed_copy ();
 }
 
 
 
+ADD_INTERFACE (Hairpin, "hairpin-interface",
+  "hairpin crescendo.",
+  "grow-direction height if-text-padding");
+