From: David Kastrup Date: Wed, 10 Apr 2013 19:53:11 +0000 (+0200) Subject: Get consistent vertical position for church rests X-Git-Tag: release/2.17.18-1~18^2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6625efe114fb04b18d60fae2c571cdacaf6bef7e;p=lilypond.git Get consistent vertical position for church rests --- diff --git a/lily/include/rest.hh b/lily/include/rest.hh index 5463574751..9a0b811ed7 100644 --- a/lily/include/rest.hh +++ b/lily/include/rest.hh @@ -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); diff --git a/lily/multi-measure-rest.cc b/lily/multi-measure-rest.cc index 92023cf972..e823c298e3 100644 --- a/lily/multi-measure-rest.cc +++ b/lily/multi-measure-rest.cc @@ -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++; diff --git a/lily/rest.cc b/lily/rest.cc index 4a46b7312a..bf6f43758b 100644 --- a/lily/rest.cc +++ b/lily/rest.cc @@ -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 ()));