]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/rest.cc
Fix 1816: Lilypond-book: Give images 1mm less linewidth
[lilypond.git] / lily / rest.cc
index 92e0e6e029c5c2fd98bc94c557a5d3f914e87dc8..0115e5176fbbf56921767051b0389b85ab84eee2 100644 (file)
@@ -1,9 +1,20 @@
 /*
-  rest.cc -- implement Rest
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 1997--2007 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
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "rest.hh"
@@ -30,22 +41,39 @@ Rest::y_offset_callback (SCM smob)
 
   bool position_override = scm_is_number (me->get_property ("staff-position"));
   Real amount = robust_scm2double (me->get_property ("staff-position"), 0)
-    * 0.5 * ss;
-  
+                * 0.5 * ss;
+
   if (line_count % 2)
     {
       if (duration_log == 0 && line_count > 1)
-       amount += ss;
+        amount += ss;
     }
   else
     amount += ss / 2;
 
   if (!position_override)
-    amount += 2 * ss * get_grob_direction (me);; 
-  
+    amount += 2 * ss * get_grob_direction (me);
+
+
   return scm_from_double (amount);
 }
 
+/* A rest might lie under a beam, in which case it should be cross-staff if
+   the beam is cross-staff because the rest's position depends on the
+   formatting of the beam. */
+MAKE_SCHEME_CALLBACK (Rest, calc_cross_staff, 1);
+SCM
+Rest::calc_cross_staff (SCM smob)
+{
+  Grob *me = unsmob_grob (smob);
+  Grob *stem = unsmob_grob (me->get_object ("stem"));
+
+  if (!stem)
+    return SCM_BOOL_F;
+
+  return stem->get_property ("cross-staff");
+}
+
 /*
   make this function easily usable in C++
 */
@@ -53,16 +81,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);
     }
@@ -73,26 +102,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 = "";
     }
@@ -100,14 +129,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);
@@ -134,6 +163,21 @@ Rest::brew_internal_stencil (Grob *me, bool ledgered)
   return out.smobbed_copy ();
 }
 
+/**
+   translate the rest vertically by amount DY, but only if
+   it doesn't have staff-position set.
+*/
+void
+Rest::translate (Grob *me, int dy)
+{
+  if (!scm_is_number (me->get_property ("staff-position")))
+    {
+      me->translate_axis (dy * Staff_symbol_referencer::staff_space (me) / 2.0, Y_AXIS);
+      Grob *p = me->get_parent (Y_AXIS);
+      p->flush_extent_cache (Y_AXIS);
+    }
+}
+
 SCM
 Rest::print (SCM smob)
 {
@@ -177,25 +221,23 @@ 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)
+Rest::pure_height (SCM smob,
+                   SCM /* start */,
+                   SCM /* end */)
 {
-  (void) start;
-  (void) end;
-  
   Grob *me = unsmob_grob (smob);
   SCM m = brew_internal_stencil (me, false);
   return ly_interval2scm (unsmob_stencil (m)->extent (Y_AXIS));
 }
 
 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 "
+              );