summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Dalley <kevin@kelphead.org>2007-03-19 05:32:37 -0700
committerNeil Puttock <n.puttock@gmail.com>2008-07-09 01:13:02 +0100
commit6dd9d054f7b528a729c74077b4cf36e644afbeb4 (patch)
tree81f93036854fce4852601b48b8f88ce81a656506
parent173e30f6781380bb3eeb1640ac309585712900ef (diff)
Corrected on_line for better ledger lines for different staves.
Signed-off-by: Neil Puttock <n.puttock@gmail.com>
-rw-r--r--input/regression/ledger-lines-varying-staves.ly51
-rw-r--r--lily/include/staff-symbol.hh1
-rw-r--r--lily/staff-symbol-referencer.cc3
-rw-r--r--lily/staff-symbol.cc29
4 files changed, 81 insertions, 3 deletions
diff --git a/input/regression/ledger-lines-varying-staves.ly b/input/regression/ledger-lines-varying-staves.ly
new file mode 100644
index 0000000000..26c0b4ad69
--- /dev/null
+++ b/input/regression/ledger-lines-varying-staves.ly
@@ -0,0 +1,51 @@
+\version "2.11.52"
+\header {
+ texidoc = "Ledger lines should appear at every other location
+for a variety of staves using both @code{line-count} and
+@code{line-positions}."
+}
+
+notes = \relative c' {
+ \time 3/4
+ c2. | d | e | f
+ g2. | a | b | c
+ d2. | e | f | g
+ a2.
+}
+
+\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 4dacde8b53..6791e7be1c 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 e8ef99f9dd..d623bd35b3 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 d4aa9e116c..6fefc48010 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 = HUGE_VAL;
+ Real max_line = -HUGE_VAL;
+ 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"