From 0b5d0acdc14a073f9cf763c8b596ba02f2a8f08d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benk=C5=91=20P=C3=A1l?= Date: Thu, 19 Jul 2012 23:07:57 +0200 Subject: [PATCH] time signature positioning for non-standard staves the only non-standardness the old code catered for is altered line-count. the aim here is to position time signature similarly with any of the following: \override StaffSymbol #'line-count = #'4 \override StaffSymbol #'line-positions = #'(-2 0 2 4) \override StaffSymbol #'line-positions = #'(-4 -2 0 2) --- lily/time-signature.cc | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lily/time-signature.cc b/lily/time-signature.cc index ad553e4229..082b62a93c 100644 --- a/lily/time-signature.cc +++ b/lily/time-signature.cc @@ -23,6 +23,7 @@ #include "font-interface.hh" #include "international.hh" #include "output-def.hh" +#include "staff-symbol.hh" #include "staff-symbol-referencer.hh" #include "text-interface.hh" #include "warn.hh" @@ -57,8 +58,35 @@ Time_signature::print (SCM smob) else m = numbered_time_signature (me, n, d); - if (Staff_symbol_referencer::line_count (me) % 2 == 0) - m.translate_axis (Staff_symbol_referencer::staff_space (me) / 2, Y_AXIS); + /* + position the signature centred on the staff line + nearest to the middle of the staff + */ + if (Grob *staff = Staff_symbol_referencer::get_staff_symbol (me)) + { + std::vector const linepos = Staff_symbol::line_positions (staff); + if (!linepos.empty ()) + { + Interval const span = Staff_symbol::line_span (staff); + Real const mid = span.center (); + Real pos = linepos.front (); + Real dist = fabs (pos - mid); + for (std::vector::const_iterator + i = linepos.begin (), e = linepos.end (); + ++i != e;) + { + double const d = fabs (*i - mid); + if (d < dist) + { + pos = *i; + dist = d; + } + } + + m.translate_axis + (pos * Staff_symbol_referencer::staff_space (me) / 2, Y_AXIS); + } + } return m.smobbed_copy (); } -- 2.39.2