From e86b2ea93e8b9e829520e258c24416060e296bdb Mon Sep 17 00:00:00 2001 From: Keith OHara Date: Sat, 3 Jan 2015 14:29:39 -0800 Subject: [PATCH] property to set voiced-rest positions; issue 3902 --- input/regression/rest-polyphonic.ly | 5 ++++- lily/rest.cc | 19 ++++++++++--------- scm/define-grob-properties.scm | 2 ++ scm/define-grobs.scm | 2 ++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/input/regression/rest-polyphonic.ly b/input/regression/rest-polyphonic.ly index a1e762923b..4dca1efc9a 100644 --- a/input/regression/rest-polyphonic.ly +++ b/input/regression/rest-polyphonic.ly @@ -2,7 +2,7 @@ texidoc = "In polyphonic situations, rests are moved according to their @code{direction} even if there is no opposite note or rest. -The amount is two @code{staff-space}s. " +The amount in @code{staff-position}s is set by @code{voiced-position}." } @@ -15,6 +15,9 @@ The amount is two @code{staff-space}s. " \new Staff \relative c' { << { r8 g''4 g8 r g4 g8 } \\ { d,4 r \stemUp b r } >> + \override Staff.Rest.voiced-position = 2 + << { r8 g''4 g8 r g4 g8 } \\ + { d,4 r \stemUp b r } >> } diff --git a/lily/rest.cc b/lily/rest.cc index b202519cf5..9e5dc046e1 100644 --- a/lily/rest.cc +++ b/lily/rest.cc @@ -72,12 +72,13 @@ Rest::staff_position_internal (Grob *me, int duration_log, int dir) return pos; } - pos = 4 * dir; + Real vpos = dir * robust_scm2int (me->get_property ("voiced-position"), 0); + pos = vpos; if (duration_log > 1) /* Only half notes or longer want alignment with staff lines */ return pos; - + /* We need a staff symbol for actually aligning anything */ @@ -89,9 +90,9 @@ Rest::staff_position_internal (Grob *me, int duration_log, int dir) if (linepos.empty ()) return pos; - + std::sort (linepos.begin (), linepos.end ()); - + if (duration_log == 0) { /* @@ -105,7 +106,7 @@ Rest::staff_position_internal (Grob *me, int duration_log, int dir) make a semibreve rest hang from the next available line, except when there is none. */ - + std::vector::const_iterator it = std::upper_bound (linepos.begin (), linepos.end (), pos); if (it != linepos.end ()) @@ -127,16 +128,15 @@ Rest::staff_position_internal (Grob *me, int duration_log, int dir) return pos; /* If we have a voiced position, make sure that it's on the - proper side of neutral before using it. If it isn't, we fall - back to a constant offset from neutral position. + proper side of neutral before using it. */ Real neutral = staff_position_internal (me, duration_log, 0); if (dir * (pos - neutral) > 0) return pos; - - return neutral + 4 * dir; + else + return neutral + vpos; } /* A rest might lie under a beam, in which case it should be cross-staff if @@ -318,4 +318,5 @@ ADD_INTERFACE (Rest, "direction " "minimum-distance " "style " + "voiced-position " ); diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 4a95ca5c47..72597bc84e 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -1112,6 +1112,8 @@ positioning?") ;;; (vertical-skylines ,ly:skyline-pair? "Two skylines, one above and one below this grob.") + (voiced-position ,number? "The staff-position of a voiced +@code{Rest}, negative if the rest has @code{direction} @code{DOWN}.") ;;; ;;; w diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index c859b52bcb..252733d166 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -1513,6 +1513,7 @@ (thick-thickness . 6.6) ;; See Wanske pp. 125 (usable-duration-logs . ,(iota 4 -3)) + (voiced-position . 4) (Y-extent . ,(ly:make-unpure-pure-container ly:multi-measure-rest::height)) (Y-offset . ,staff-symbol-referencer::callback) (meta . ((class . Spanner) @@ -1880,6 +1881,7 @@ (duration-log . ,stem::calc-duration-log) (minimum-distance . 0.25) (stencil . ,ly:rest::print) + (voiced-position . 4) (X-extent . ,ly:rest::width) (Y-extent . ,(ly:make-unpure-pure-container ly:rest::height ly:rest::pure-height)) (Y-offset . ,(ly:make-unpure-pure-container ly:rest::y-offset-callback)) -- 2.39.2