]> git.donarmstrong.com Git - lilypond.git/commitdiff
Get consistent vertical position for church rests
authorDavid Kastrup <dak@gnu.org>
Wed, 10 Apr 2013 19:53:11 +0000 (21:53 +0200)
committerDavid Kastrup <dak@gnu.org>
Tue, 30 Apr 2013 10:57:03 +0000 (12:57 +0200)
lily/include/rest.hh
lily/multi-measure-rest.cc
lily/rest.cc

index 5463574751d01b1a6ce0ac8bed8a867eeaf84d1f..9a0b811ed7c30e4dc73aaf5ba2eee579e6493874 100644 (file)
@@ -30,7 +30,7 @@ public:
   DECLARE_SCHEME_CALLBACK (y_offset_callback, (SCM));
   DECLARE_SCHEME_CALLBACK (calc_cross_staff, (SCM));
   DECLARE_GROB_INTERFACE ();
-  static string glyph_name (Grob *, int, string, bool);
+  static string glyph_name (Grob *, int, string, bool, Real);
   static Real staff_position_internal (Grob *, int /* duration_log */,
                                        int /* dir */);
   static SCM brew_internal_stencil (Grob *, bool);
index 92023cf972b5c569b74a4d5b7c437e69979c8032..e823c298e319ee2dc47b95f0d77cde384465a748 100644 (file)
@@ -223,17 +223,16 @@ Multi_measure_rest::symbol_stencil (Grob *me, Real space)
   Font_metric *musfont = Font_interface::get_default_font (me);
   int mdl = calc_measure_duration_log (me, true);
 
-  if (me->get_property ("staff-position") == SCM_EOL)
-    {
-      int dir = get_grob_direction (me);
-      Real pos = Rest::staff_position_internal (me, mdl, dir);
-      me->set_property ("staff-position", scm_from_double (pos));
-    }
-
   if (measure_count == 1)
     {
+      if (me->get_property ("staff-position") == SCM_EOL)
+        {
+          int dir = get_grob_direction (me);
+          Real pos = Rest::staff_position_internal (me, mdl, dir);
+          me->set_property ("staff-position", scm_from_double (pos));
+        }
  
-      Stencil s = musfont->find_by_name (Rest::glyph_name (me, mdl, "", true));
+      Stencil s = musfont->find_by_name (Rest::glyph_name (me, mdl, "", true, 0.0));
 
       s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
       return s;
@@ -282,6 +281,22 @@ Multi_measure_rest::church_rest (Grob *me, Font_metric *musfont, int measure_cou
   Real symbols_width = 0.0;
   double total_duration = measure_count * pow (2.0, -calc_measure_duration_log (me, true));
 
+  SCM staff_position = me->get_property ("staff-position");
+
+  if (!scm_is_number (staff_position))
+    {
+      // Staff position is somewhat icky regarding its definition for
+      // compatibility reasons.  It is intended to be the baseline of
+      // a breve rest.  However, when the staff space is more than
+      // single space (like with tablature), it looks better if all
+      // rests are actually hanging.  So staff position, in reality,
+      // is the semi-breve position - 2.  Everything else is
+      // calculated from there.
+      int dir = get_grob_direction (me);
+      Real pos = Rest::staff_position_internal (me, 0, dir);
+      me->set_property ("staff-position", scm_from_double (pos - 2));
+    }
+
   while (total_duration > 0)
     {
       int dl = calc_closest_duration_log (me, total_duration, false, true);
@@ -289,12 +304,17 @@ Multi_measure_rest::church_rest (Grob *me, Font_metric *musfont, int measure_cou
 
       total_duration -= duration;
 
-      Stencil r = musfont->find_by_name (Rest::glyph_name (me, dl, "", true));
+      Stencil r = musfont->find_by_name (Rest::glyph_name (me, dl, "", true, 2));
+
+      Real staff_space = Staff_symbol_referencer::staff_space (me);
       if (dl == 0)
         {
-          Real staff_space = Staff_symbol_referencer::staff_space (me);
           r.translate_axis (staff_space, Y_AXIS);
         }
+      else
+        {
+          r.translate_axis (staff_space-r.extent (Y_AXIS).at (UP), Y_AXIS);
+        }
       symbols_width += r.extent (X_AXIS).length ();
       mols = scm_cons (r.smobbed_copy (), mols);
       symbol_count++;
index 4a46b7312aa8feab0946a83fa6ad17552a8601e6..bf6f43758b0e764d1e0766e6f6548c97e92d454a 100644 (file)
@@ -159,13 +159,14 @@ Rest::calc_cross_staff (SCM smob)
   make this function easily usable in C++
 */
 string
-Rest::glyph_name (Grob *me, int durlog, string style, bool try_ledgers)
+Rest::glyph_name (Grob *me, int durlog, string style, bool try_ledgers,
+                  Real offset)
 {
   bool is_ledgered = false;
   if (try_ledgers && (durlog == -1 || durlog == 0 || durlog == 1))
     {
-      int const pos = int (Staff_symbol_referencer::get_position (me));
-
+      int const pos = int (Staff_symbol_referencer::get_position (me)
+                           + offset);
       /*
         half rests need ledger if not lying on a staff line,
         whole rests need ledger if not hanging from a staff line,
@@ -233,7 +234,7 @@ Rest::brew_internal_stencil (Grob *me, bool ledgered)
   string style = robust_symbol2string (me->get_property ("style"), "default");
 
   Font_metric *fm = Font_interface::get_default_font (me);
-  string font_char = glyph_name (me, durlog, style, ledgered);
+  string font_char = glyph_name (me, durlog, style, ledgered, 0.0);
   Stencil out = fm->find_by_name (font_char);
   if (out.is_empty ())
     me->warning (_f ("rest `%s' not found", font_char.c_str ()));