From 56d793a12307e44d79c63a14f72152ba7c664763 Mon Sep 17 00:00:00 2001 From: Kevin Dalley Date: Fri, 4 Jul 2008 22:01:31 +0100 Subject: [PATCH] Corrected on_line for better ledger lines for different staves. --- input/regression/ledger-lines-varying-staves.ly | 50 +++++++++++++++++++++++ lily/include/staff-symbol.hh | 1 + lily/staff-symbol-referencer.cc | 3 +- lily/staff-symbol.cc | 29 +++++++++++++- 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 input/regression/ledger-lines-varying-staves.ly diff --git a/input/regression/ledger-lines-varying-staves.ly b/input/regression/ledger-lines-varying-staves.ly new file mode 100644 index 0000000..7d9f0e0 --- /dev/null +++ b/input/regression/ledger-lines-varying-staves.ly @@ -0,0 +1,50 @@ +\version "2.11.51" +\header { + texidoc = "Ledger lines should appear at every other location +for a variety of staves using both @code{line-count} and address@hidden" +} + +notes = \relative c' { + c1 | d | e | f + g1 | a | b | c + d1 | e | f | g + a1 +} + +\new Staff { + % upper and lower lines both odd + #(define mylines '(-1 0 1)) + \override Staff.StaffSymbol #'line-count = #(length mylines) + \override Staff.StaffSymbol #'line-positions = #mylines + \notes +} + +\new Staff { + % upper and lower lines both even + #(define mylines '(-2 0 2)) + \override Staff.StaffSymbol #'line-positions = #mylines + + \override Staff.StaffSymbol #'line-count = #(length mylines) + \notes +} + +\new Staff { + % lower line odd, upper line even + #(define mylines '(-1 0 2)) + \override Staff.StaffSymbol #'line-positions = #mylines + \override Staff.StaffSymbol #'line-count = #(length mylines) + \notes +} + +\new Staff { + % odd line count + \override Staff.StaffSymbol #'line-count = #5 + \notes +} + +\new Staff { + % even line count + \override Staff.StaffSymbol #'line-count = #4 + \notes +} diff --git a/lily/include/staff-symbol.hh b/lily/include/staff-symbol.hh index 4dacde8..6791e7b 100644 --- a/lily/include/staff-symbol.hh +++ b/lily/include/staff-symbol.hh @@ -24,6 +24,7 @@ public: static int get_steps (Grob *); static int line_count (Grob *); + static bool on_line (Grob *me, int pos); DECLARE_SCHEME_CALLBACK (print, (SCM)); DECLARE_SCHEME_CALLBACK (height, (SCM)); DECLARE_GROB_INTERFACE(); diff --git a/lily/staff-symbol-referencer.cc b/lily/staff-symbol-referencer.cc index e8ef99f..d623bd3 100644 --- a/lily/staff-symbol-referencer.cc +++ b/lily/staff-symbol-referencer.cc @@ -35,8 +35,7 @@ Staff_symbol_referencer::on_staff_line (Grob *me) bool Staff_symbol_referencer::on_line (Grob *me, int pos) { - int sz = line_count (me) - 1; - return ((pos + sz) % 2) == 0; + return Staff_symbol::on_line (me, pos); } bool diff --git a/lily/staff-symbol.cc b/lily/staff-symbol.cc index d4aa9e1..df441d4 100644 --- a/lily/staff-symbol.cc +++ b/lily/staff-symbol.cc @@ -167,8 +167,35 @@ Staff_symbol::height (SCM smob) return ly_interval2scm (y_ext); } +bool +Staff_symbol::on_line (Grob *me, int pos) +{ + SCM line_positions = me->get_property ("line-positions"); + if (scm_is_pair (line_positions)) + { + Real min_line = SCM_FLTMAX; + Real max_line = -SCM_FLTMAX; + for (SCM s = line_positions; scm_is_pair (s); s = scm_cdr (s)) + { + Real current_line = scm_to_double (scm_car (s)); + if (pos == current_line) + return true; + if (current_line > max_line) + max_line = current_line; + if (current_line < min_line) + min_line = current_line; + + } + if (pos < min_line) + return (( (int) (rint (pos - min_line)) % 2) == 0); + if (pos > max_line) + return (( (int) (rint (pos - max_line)) % 2) == 0); - + return false; + } + else + return ((abs (pos + line_count (me)) % 2) == 1); +} ADD_INTERFACE (Staff_symbol, "This spanner draws the lines of a staff. A staff symbol" -- 1.5.4.3