diff options
author | Bertrand Bordage <bordage.bertrand@gmail.com> | 2011-05-26 22:53:47 +0200 |
---|---|---|
committer | Graham Percival <graham@percival-music.ca> | 2011-06-14 20:05:30 +0100 |
commit | 104f80daf1dab11ef5b598006e3d4be8dfbe1926 (patch) | |
tree | 245f5aacc16e40cf58b48c84826de2abdb642c8c | |
parent | 6d04f3f2faa85840f62a9e072202d0faf28a95f7 (diff) |
Adds longas, maximas and non-standard tweaks to MultiMeasureRest.
Fix issue 1655.
-rw-r--r-- | input/regression/multi-measure-rest-standard.ly | 20 | ||||
-rw-r--r-- | input/regression/multi-measure-rest-tweaks.ly | 14 | ||||
-rw-r--r-- | input/regression/multi-measure-rest-usebreve.ly | 24 | ||||
-rw-r--r-- | lily/multi-measure-rest-engraver.cc | 12 | ||||
-rw-r--r-- | lily/multi-measure-rest.cc | 143 | ||||
-rw-r--r-- | scm/define-grob-properties.scm | 8 | ||||
-rw-r--r-- | scm/define-grobs.scm | 2 |
7 files changed, 114 insertions, 109 deletions
diff --git a/input/regression/multi-measure-rest-standard.ly b/input/regression/multi-measure-rest-standard.ly new file mode 100644 index 0000000000..8a398aab44 --- /dev/null +++ b/input/regression/multi-measure-rest-standard.ly @@ -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 index 0000000000..f1ef48c275 --- /dev/null +++ b/input/regression/multi-measure-rest-tweaks.ly @@ -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 index 2ed4f9c791..0000000000 --- a/input/regression/multi-measure-rest-usebreve.ly +++ /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 -} - - diff --git a/lily/multi-measure-rest-engraver.cc b/lily/multi-measure-rest-engraver.cc index 3fbcdb612b..786ab143c1 100644 --- a/lily/multi-measure-rest-engraver.cc +++ b/lily/multi-measure-rest-engraver.cc @@ -228,11 +228,6 @@ Multi_measure_rest_engraver::start_translation_timestep () */ 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 (); @@ -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" - " 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 " @@ -281,8 +274,7 @@ ADD_TRANSLATOR (Multi_measure_rest_engraver, "internalBarNumber " "restNumberThreshold " "currentCommandColumn " - "measurePosition " - "measureLength ", + "measurePosition ", /* write */ "" diff --git a/lily/multi-measure-rest.cc b/lily/multi-measure-rest.cc index 9628402a5e..812fd100e4 100644 --- a/lily/multi-measure-rest.cc +++ b/lily/multi-measure-rest.cc @@ -22,6 +22,7 @@ #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" @@ -118,6 +119,34 @@ Multi_measure_rest::print (SCM smob) 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) { @@ -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); + int mdl = measure_duration_log (me); - SCM sml = me->get_property ("use-breve-rest"); 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); @@ -208,63 +221,46 @@ Multi_measure_rest::church_rest (Grob *me, Font_metric *musfont, int measures, { SCM mols = SCM_EOL; - /* See Wanske pp. 125 */ 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) + { + 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; @@ -367,7 +363,8 @@ ADD_INTERFACE (Multi_measure_rest, "hair-thickness " "measure-count " "minimum-length " + "round-to-longer-rest " "spacing-pair " "thick-thickness " - "use-breve-rest " + "usable-duration-logs " ); diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 7fd0b13819..8f05a8b324 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -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.") + (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.") + (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.") - (use-breve-rest ,boolean? "Use breve rests for measures longer -than a whole rest.") ;;;;;;;;;;;;;;;; ;; ancient notation diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index a2e51a604b..ecfeee3d6b 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -1309,6 +1309,8 @@ (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 |