]> git.donarmstrong.com Git - lilypond.git/commitdiff
Adds longas, maximas and non-standard tweaks to MultiMeasureRest.
authorBertrand Bordage <bordage.bertrand@gmail.com>
Thu, 26 May 2011 20:53:47 +0000 (22:53 +0200)
committerGraham Percival <graham@percival-music.ca>
Tue, 14 Jun 2011 19:05:30 +0000 (20:05 +0100)
Fix issue 1655.

input/regression/multi-measure-rest-standard.ly [new file with mode: 0644]
input/regression/multi-measure-rest-tweaks.ly [new file with mode: 0644]
input/regression/multi-measure-rest-usebreve.ly [deleted file]
lily/multi-measure-rest-engraver.cc
lily/multi-measure-rest.cc
scm/define-grob-properties.scm
scm/define-grobs.scm

diff --git a/input/regression/multi-measure-rest-standard.ly b/input/regression/multi-measure-rest-standard.ly
new file mode 100644 (file)
index 0000000..8a398aa
--- /dev/null
@@ -0,0 +1,20 @@
+\header {
+  texidoc = "Only whole, breve, longa and maxima rests are used by default for multi-measure rests."
+}
+
+\version "2.15.0"
+
+\paper {
+  ragged-right = ##t
+  indent = 0
+}
+
+\new Staff {
+  \time 3/8 R4.
+  \time 2/4 R2
+  \time 2/2 R1
+  \time 2/1 R\breve
+  \break
+  \time 4/1 R\longa
+  \time 8/1 R\maxima
+}
diff --git a/input/regression/multi-measure-rest-tweaks.ly b/input/regression/multi-measure-rest-tweaks.ly
new file mode 100644 (file)
index 0000000..f1ef48c
--- /dev/null
@@ -0,0 +1,14 @@
+\header {
+  texidoc = "Multi-measure rests standard values can be tweaked."
+}
+
+\version "2.15.0"
+\new Staff {
+  \override MultiMeasureRest #'usable-duration-logs = #'(2 1)
+  \time 1/4 R4-"Use non-standard multi-measure rests."
+  \time 2/4 R2
+}
+\new Staff {
+  \override MultiMeasureRest #'round-to-longer-rest = ##t
+  \time 3/2 R1.-"Round to the longer rest." \time 7/2 R\breve..
+}
diff --git a/input/regression/multi-measure-rest-usebreve.ly b/input/regression/multi-measure-rest-usebreve.ly
deleted file mode 100644 (file)
index 2ed4f9c..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-\version "2.14.0"
-\header{
-
-  texidoc="For longer measure lengths, the breve rest is used."
-
-}
-
-\layout {
-  \context {
-    \Score
-    skipBars = ##t
-  }
-  ragged-right = ##t   
-}
-
-
-{
-  \time 8/4
-  R1*12
-  \time 4/4
-  R1*6
-}
-
-
index 3fbcdb612b86b8d14f01a90ea9b18507c42d1be0..786ab143c14957c8896542f9cd898e44e2bd6327 100644 (file)
@@ -228,11 +228,6 @@ Multi_measure_rest_engraver::start_translation_timestep ()
       */
       last_rest_->set_property ("measure-count", scm_from_int (num));
 
       */
       last_rest_->set_property ("measure-count", scm_from_int (num));
 
-      SCM sml = get_property ("measureLength");
-      Rational ml = (unsmob_moment (sml)) ? unsmob_moment (sml)->main_part_ : Rational (1);
-      if (ml >= Rational (2))
-       last_rest_->set_property ("use-breve-rest", SCM_BOOL_T);
-
       mmrest_ = 0;
       numbers_.clear ();
 
       mmrest_ = 0;
       numbers_.clear ();
 
@@ -268,9 +263,7 @@ ADD_TRANSLATOR (Multi_measure_rest_engraver,
                "Engrave multi-measure rests that are produced with"
                " @samp{R}.  It reads @code{measurePosition} and"
                " @code{internalBarNumber} to determine what number to print"
                "Engrave multi-measure rests that are produced with"
                " @samp{R}.  It reads @code{measurePosition} and"
                " @code{internalBarNumber} to determine what number to print"
-               " over the @ref{MultiMeasureRest}.  Reads @code{measureLength}"
-               " to determine whether it should use a whole rest or a breve"
-               " rest to represent one measure.",
+               " over the @ref{MultiMeasureRest}.",
                
                /* create */
                "MultiMeasureRest "
                
                /* create */
                "MultiMeasureRest "
@@ -281,8 +274,7 @@ ADD_TRANSLATOR (Multi_measure_rest_engraver,
                "internalBarNumber "
                "restNumberThreshold "
                "currentCommandColumn "
                "internalBarNumber "
                "restNumberThreshold "
                "currentCommandColumn "
-               "measurePosition "
-               "measureLength ",
+               "measurePosition ",
                
                /* write */
                ""
                
                /* write */
                ""
index 9628402a5ecec1ce899d4ef1d4ea57002b7529af..812fd100e41621f0eaa78964fcfc21517684da30 100644 (file)
@@ -22,6 +22,7 @@
 #include "font-interface.hh"
 #include "lookup.hh"
 #include "misc.hh"
 #include "font-interface.hh"
 #include "lookup.hh"
 #include "misc.hh"
+#include "moment.hh"
 #include "output-def.hh"
 #include "paper-column.hh" // urg
 #include "percent-repeat-item.hh"
 #include "output-def.hh"
 #include "paper-column.hh" // urg
 #include "percent-repeat-item.hh"
@@ -118,6 +119,34 @@ Multi_measure_rest::print (SCM smob)
   return mol.smobbed_copy ();
 }
 
   return mol.smobbed_copy ();
 }
 
+int
+measure_duration_log (Grob *me)
+{
+  SCM sml = dynamic_cast<Spanner *> (me)->get_bound (LEFT)
+                                        ->get_property ("measure-length");
+  bool round = to_boolean (me->get_property ("round-to-longer-rest"));
+  Rational ml = (unsmob_moment (sml)) ? unsmob_moment (sml)->main_part_ : Rational (1);
+
+  double duration_log = -log2 (ml.Rational::to_double ());
+  int measure_duration_log = int (ceil (duration_log));
+  if (round && duration_log - measure_duration_log < 0)
+    measure_duration_log--;
+
+  SCM duration_logs_list = me->get_property ("usable-duration-logs");
+  int closest_list_elt = -15; // -15 is out of range.
+
+  for (int i = 0; i < scm_to_int (scm_length (duration_logs_list)); i++)
+  {
+    int list_elt = scm_to_int (scm_list_ref (duration_logs_list, scm_from_int (i)));
+    int shortest_distance = abs (measure_duration_log - closest_list_elt);
+    int distance = abs (measure_duration_log - list_elt);
+    if (distance < shortest_distance)
+      closest_list_elt = list_elt;
+  }
+
+  return closest_list_elt;
+}
+
 Stencil
 Multi_measure_rest::symbol_stencil (Grob *me, Real space)
 {
 Stencil
 Multi_measure_rest::symbol_stencil (Grob *me, Real space)
 {
@@ -140,32 +169,16 @@ Multi_measure_rest::symbol_stencil (Grob *me, Real space)
   Real staff_space = Staff_symbol_referencer::staff_space (me);
 
   Font_metric *musfont = Font_interface::get_default_font (me);
   Real staff_space = Staff_symbol_referencer::staff_space (me);
 
   Font_metric *musfont = Font_interface::get_default_font (me);
+  int mdl = measure_duration_log (me);
 
 
-  SCM sml = me->get_property ("use-breve-rest");
   if (measures == 1)
     {
   if (measures == 1)
     {
-      if (to_boolean (sml))
-       {
-         Stencil s = musfont->find_by_name (Rest::glyph_name (me, -1, "", false));
-
-         s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
-
-         return s;
-       }
-      else
-       {
-         Stencil s = musfont->find_by_name (Rest::glyph_name (me, 0, "", true));
-
-         /*
-           ugh.
-         */
-         if (Staff_symbol_referencer::get_position (me) == 0.0)
-           s.translate_axis (staff_space, Y_AXIS);
-
-         s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
+      Stencil s = musfont->find_by_name (Rest::glyph_name (me, mdl, "", true));
+      if (mdl == 0 && Staff_symbol_referencer::get_position (me) == 0.0)
+        s.translate_axis (staff_space, Y_AXIS);
 
 
-         return s;
-       }
+      s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
+      return s;
     }
   else
     return church_rest (me, musfont, measures, space);
     }
   else
     return church_rest (me, musfont, measures, space);
@@ -208,63 +221,46 @@ Multi_measure_rest::church_rest (Grob *me, Font_metric *musfont, int measures,
 {
   SCM mols = SCM_EOL;
 
 {
   SCM mols = SCM_EOL;
 
-  /* See Wanske pp. 125  */
   int l = measures;
   int count = 0;
   Real symbols_width = 0.0;
   int l = measures;
   int count = 0;
   Real symbols_width = 0.0;
-
-  bool use_breve = to_boolean (me->get_property ("use-breve-rest"));
+  SCM duration_logs_list = me->get_property ("usable-duration-logs");
+  int longest_church_rest = 10; // 10 is out of range.
+  for (int i = 0; i < scm_to_int (scm_length (duration_logs_list)); i++)
+  {
+    longest_church_rest = min (longest_church_rest,
+                               scm_to_int (scm_list_ref (duration_logs_list,
+                                                         scm_from_int (i))));
+  }
 
   while (l)
 
   while (l)
+  {
+    int k;
+    int i = longest_church_rest - 1;
+    int length;
+    int mdl = measure_duration_log (me);
+
+    do
+    {
+      i++;
+      length = int (pow (2, -i));
+    }
+    while (i <= 0 &&
+           !(l >= length && mdl >= longest_church_rest - i));
+
+    l -= length;
+    k = mdl + i;
+
+    Stencil r (musfont->find_by_name ("rests." + to_string (k)));
+    if (k == 0)
     {
     {
-      if (use_breve)
-       {
-         int k;
-         if (l >= 2)
-           {
-             l -= 2;
-             k = -2;
-           }
-         else
-           {
-             l -= 1;
-             k = -1;
-           }
-
-         Stencil r (musfont->find_by_name ("rests." + to_string (k)));
-         symbols_width += r.extent (X_AXIS).length ();
-         mols = scm_cons (r.smobbed_copy (), mols);
-       }
-      else
-       {
-         int k;
-         if (l >= 4)
-           {
-             l -= 4;
-             k = -2;
-           }
-         else if (l >= 2)
-           {
-             l -= 2;
-             k = -1;
-           }
-         else
-           {
-             k = 0;
-             l--;
-           }
-
-         Stencil r (musfont->find_by_name ("rests." + to_string (k)));
-         if (k == 0)
-           {
-             Real staff_space = Staff_symbol_referencer::staff_space (me);
-             r.translate_axis (staff_space, Y_AXIS);
-           }
-         symbols_width += r.extent (X_AXIS).length ();
-         mols = scm_cons (r.smobbed_copy (), mols);
-       }
-      count++;
+      Real staff_space = Staff_symbol_referencer::staff_space (me);
+      r.translate_axis (staff_space, Y_AXIS);
     }
     }
+    symbols_width += r.extent (X_AXIS).length ();
+    mols = scm_cons (r.smobbed_copy (), mols);
+    count++;
+  }
 
   /* Make outer padding this much bigger.  */
   Real outer_padding_factor = 1.5;
 
   /* Make outer padding this much bigger.  */
   Real outer_padding_factor = 1.5;
@@ -367,7 +363,8 @@ ADD_INTERFACE (Multi_measure_rest,
               "hair-thickness "
               "measure-count "
               "minimum-length "
               "hair-thickness "
               "measure-count "
               "minimum-length "
+              "round-to-longer-rest "
               "spacing-pair "
               "thick-thickness "
               "spacing-pair "
               "thick-thickness "
-              "use-breve-rest "
+               "usable-duration-logs "
               );
               );
index 7fd0b138190bf35f20d9fcec62934c92af86839b..8f05a8b324a366f90fb9227b9f893fa6fdf7f57e 100644 (file)
@@ -696,6 +696,10 @@ of an object (e.g., between note and its accidentals).")
      (rotation ,list? "Number of degrees to rotate this object, and
 what point to rotate around.  For example, @code{#'(45 0 0)} rotates
 by 45 degrees around the center of this object.")
      (rotation ,list? "Number of degrees to rotate this object, and
 what point to rotate around.  For example, @code{#'(45 0 0)} rotates
 by 45 degrees around the center of this object.")
+     (round-to-longer-rest ,boolean? "Displays the longer multi-measure
+rest when the length of a measure is between two values of
+@code{usable-duration-logs}.  For example, displays a breve instead of a whole
+in a 3/2 measure.")
 
 
 ;;
 
 
 ;;
@@ -897,6 +901,8 @@ proportionally to their durations.  This looks better in complex
 polyphonic patterns.")
      (used ,boolean? "If set, this spacing column is kept in the
 spacing problem.")
 polyphonic patterns.")
      (used ,boolean? "If set, this spacing column is kept in the
 spacing problem.")
+     (usable-duration-logs ,list? "List of @code{duration-log}s that
+can be used in typesetting the grob.")
 
 
 ;;
 
 
 ;;
@@ -1123,8 +1129,6 @@ Internally used to distribute beam shortening over stems.")
      (system-Y-offset ,number? "The Y-offset (relative to the bottom of the
 top-margin of the page) of the system to which this staff belongs.")
 
      (system-Y-offset ,number? "The Y-offset (relative to the bottom of the
 top-margin of the page) of the system to which this staff belongs.")
 
-     (use-breve-rest ,boolean? "Use breve rests for measures longer
-than a whole rest.")
 
      ;;;;;;;;;;;;;;;;
      ;; ancient notation
 
      ;;;;;;;;;;;;;;;;
      ;; ancient notation
index a2e51a604b8d6dd6cb7904fb681f7d974287db61..ecfeee3d6bf35bd3f7ebeb5e113420bf2e821e2d 100644 (file)
        (staff-position . 0)
        (stencil . ,ly:multi-measure-rest::print)
        (thick-thickness . 6.6)
        (staff-position . 0)
        (stencil . ,ly:multi-measure-rest::print)
        (thick-thickness . 6.6)
+       ;; See Wanske pp. 125
+       (usable-duration-logs . (0 -1 -2 -3))
        (Y-offset . ,ly:staff-symbol-referencer::callback)
        (meta . ((class . Spanner)
                 (interfaces . (font-interface
        (Y-offset . ,ly:staff-symbol-referencer::callback)
        (meta . ((class . Spanner)
                 (interfaces . (font-interface