]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/rest.cc
Doc-de: updates to Notation manual
[lilypond.git] / lily / rest.cc
index 53387664b5b33708393ba2b3d9f966b007e220ed..552d20f6702dc69d089a71650cf5a1ce262de29d 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 1997--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -40,20 +40,34 @@ Rest::y_offset_callback (SCM smob)
   Real ss = Staff_symbol_referencer::staff_space (me);
 
   bool position_override = scm_is_number (me->get_property ("staff-position"));
-  Real amount = robust_scm2double (me->get_property ("staff-position"), 0)
-    * 0.5 * ss;
-  
-  if (line_count % 2)
+  Real amount;
+
+  if (position_override)
     {
-      if (duration_log == 0 && line_count > 1)
-       amount += ss;
+      amount =
+        robust_scm2double (me->get_property ("staff-position"), 0) * 0.5 * ss;
+      /*
+        trust the client on good positioning;
+        would be tempting to adjust position of rests longer than a quarter
+        to be properly aligned to staff lines,
+        but custom rest shapes may not need that sort of care.
+      */
     }
   else
-    amount += ss / 2;
+    {
+      amount = 2 * ss * get_grob_direction (me);
+
+      if (line_count % 2 == 0)
+        amount += ss / 2;
+    }
+
+  /*
+    make a semibreve rest hang from the next line,
+    except for a single line staff
+  */
+  if (duration_log == 0 && line_count > 1)
+    amount += ss;
 
-  if (!position_override)
-    amount += 2 * ss * get_grob_direction (me);; 
-  
   return scm_from_double (amount);
 }
 
@@ -80,16 +94,17 @@ string
 Rest::glyph_name (Grob *me, int balltype, string style, bool try_ledgers)
 {
   bool is_ledgered = false;
-  if (try_ledgers && (balltype == 0 || balltype == 1))
+  if (try_ledgers && (balltype == -1 || balltype == 0 || balltype == 1))
     {
       Real rad = Staff_symbol_referencer::staff_radius (me) * 2.0;
       Real pos = Staff_symbol_referencer::get_position (me);
 
       /*
-       Figure out when the rest is far enough outside the staff. This
-       could bemore generic, but hey, we understand this even after
-       dinner.
+        Figure out when the rest is far enough outside the staff. This
+        could bemore generic, but hey, we understand this even after
+        dinner.
       */
+      is_ledgered |= (balltype == -1) && (pos <= -rad - 3 || pos >= +rad + 1);
       is_ledgered |= (balltype == 0) && (pos >= +rad + 2 || pos < -rad);
       is_ledgered |= (balltype == 1) && (pos <= -rad - 2 || pos > +rad);
     }
@@ -100,26 +115,26 @@ Rest::glyph_name (Grob *me, int balltype, string style, bool try_ledgers)
     {
 
       /*
-       FIXME: Currently, ancient font does not provide ledgered rests;
-       hence the "o" suffix in the glyph name is bogus.  But do we need
-       ledgered rests at all now that we can draw ledger lines with
-       variable width, length and blotdiameter? -- jr
+        FIXME: Currently, ancient font does not provide ledgered rests;
+        hence the "o" suffix in the glyph name is bogus.  But do we need
+        ledgered rests at all now that we can draw ledger lines with
+        variable width, length and blotdiameter? -- jr
       */
       is_ledgered = 0;
 
       /*
-       There are no 32th/64th/128th mensural/neomensural rests.  In
-       these cases, revert back to default style.
+        There are no 32th/64th/128th mensural/neomensural rests.  In
+        these cases, revert back to default style.
       */
       if (balltype > 4)
-       actual_style = "";
+        actual_style = "";
     }
 
   if ((style == "classical") && (balltype != 2))
     {
       /*
-       classical style: revert back to default style for any rest other
-       than quarter rest
+        classical style: revert back to default style for any rest other
+        than quarter rest
       */
       actual_style = "";
     }
@@ -127,14 +142,14 @@ Rest::glyph_name (Grob *me, int balltype, string style, bool try_ledgers)
   if (style == "default")
     {
       /*
-       Some parts of lily still prefer style "default" over "".
-       Correct this here. -- jr
+        Some parts of lily still prefer style "default" over "".
+        Correct this here. -- jr
       */
       actual_style = "";
     }
 
   return ("rests." + to_string (balltype) + (is_ledgered ? "o" : "")
-         + actual_style);
+          + actual_style);
 }
 
 MAKE_SCHEME_CALLBACK (Rest, print, 1);
@@ -147,10 +162,7 @@ Rest::brew_internal_stencil (Grob *me, bool ledgered)
 
   int balltype = scm_to_int (balltype_scm);
 
-  string style;
-  SCM style_scm = me->get_property ("style");
-  if (scm_is_symbol (style_scm))
-    style = ly_scm2string (scm_symbol_to_string (style_scm));
+  string style = robust_symbol2string (me->get_property ("style"), "default");
 
   Font_metric *fm = Font_interface::get_default_font (me);
   string font_char = glyph_name (me, balltype, style, ledgered);
@@ -220,8 +232,8 @@ Rest::generic_extent_callback (Grob *me, Axis a)
 MAKE_SCHEME_CALLBACK (Rest, pure_height, 3);
 SCM
 Rest::pure_height (SCM smob,
-                  SCM /* start */,
-                  SCM /* end */)
+                   SCM /* start */,
+                   SCM /* end */)
 {
   Grob *me = unsmob_grob (smob);
   SCM m = brew_internal_stencil (me, false);
@@ -229,13 +241,13 @@ Rest::pure_height (SCM smob,
 }
 
 ADD_INTERFACE (Rest,
-              "A rest symbol.  The property @code{style} can be"
-              " @code{default}, @code{mensural}, @code{neomensural} or"
-              " @code{classical}.",
-
-              /* properties */
-              "direction "
-              "minimum-distance "
-              "style "
-              );
+               "A rest symbol.  The property @code{style} can be"
+               " @code{default}, @code{mensural}, @code{neomensural} or"
+               " @code{classical}.",
+
+               /* properties */
+               "direction "
+               "minimum-distance "
+               "style "
+              );