From: Benkő Pál Date: Mon, 27 Feb 2012 06:40:31 +0000 (+0100) Subject: Issue 2337: avoid infinite loop: search next staff line directly X-Git-Tag: release/2.15.31-1~8 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9ef93a7de18000749c30b541f618379bc292aae0;p=lilypond.git Issue 2337: avoid infinite loop: search next staff line directly --- diff --git a/input/regression/rest-on-nonstandard-staff.ly b/input/regression/rest-on-nonstandard-staff.ly index 4870f578cf..f81aebdfbc 100644 --- a/input/regression/rest-on-nonstandard-staff.ly +++ b/input/regression/rest-on-nonstandard-staff.ly @@ -55,4 +55,9 @@ mus = { \override Staff.StaffSymbol #'line-positions = #'(-4 -2 1 5) \mus } + + \new Staff { + \stopStaff + \mus + } >> diff --git a/lily/rest.cc b/lily/rest.cc index a25e6a9319..0bb61444b4 100644 --- a/lily/rest.cc +++ b/lily/rest.cc @@ -26,6 +26,7 @@ #include "output-def.hh" #include "paper-score.hh" #include "staff-symbol-referencer.hh" +#include "staff-symbol.hh" #include "stencil.hh" #include "grob.hh" @@ -48,7 +49,7 @@ Rest::y_offset_callback (SCM smob) robust_scm2double (me->get_property ("staff-position"), 0) * 0.5 * ss; /* - semibreve rests were always positioned one off + semibreve rests are positioned one staff line off */ if (duration_log == 0) amount += ss; @@ -66,17 +67,25 @@ Rest::y_offset_callback (SCM smob) /* make a semibreve rest hang from the next line, - except for a single line staff; - assume the next line being integer steps away + except for a single line staff */ if (duration_log == 0 && line_count > 1) - ++pos; + pos += 2; /* make sure rest is aligned to a staff line */ - while (!Staff_symbol_referencer::on_line (me, pos)) - ++pos; + if (Grob *staff = Staff_symbol_referencer::get_staff_symbol(me)) + { + std::vector linepos = Staff_symbol::line_positions (staff); + std::sort(linepos.begin(), linepos.end()); + std::vector::const_iterator it + = std::lower_bound(linepos.begin(), linepos.end(), pos); + if (it != linepos.end()) + { + pos = (int)ceil(*it); + } + } amount = ss * 0.5 * pos; } @@ -112,14 +121,14 @@ Rest::glyph_name (Grob *me, int durlog, string style, bool try_ledgers) int const pos = int (Staff_symbol_referencer::get_position (me)); /* - half rests need ledger if not lying on a staff line, - whole rests need ledger if not hanging from a staff line, - breve rests need ledger if neither lying on nor hanging from a staff line + half rests need ledger if not lying on a staff line, + whole rests need ledger if not hanging from a staff line, + breve rests need ledger if neither lying on nor hanging from a staff line */ if (-1 <= durlog && durlog <= 1) is_ledgered = !Staff_symbol_referencer::on_staff_line (me, pos) - && !(durlog == -1 - && Staff_symbol_referencer::on_staff_line (me, pos + 2)); + && !(durlog == -1 + && Staff_symbol_referencer::on_staff_line (me, pos + 2)); } string actual_style (style.c_str ());