]> git.donarmstrong.com Git - lilypond.git/commitdiff
Corrected on_line for better ledger lines for different staves.
authorKevin Dalley <kevin@kelphead.org>
Mon, 19 Mar 2007 12:32:37 +0000 (05:32 -0700)
committerNeil Puttock <n.puttock@gmail.com>
Wed, 9 Jul 2008 00:13:02 +0000 (01:13 +0100)
Signed-off-by: Neil Puttock <n.puttock@gmail.com>
input/regression/ledger-lines-varying-staves.ly [new file with mode: 0644]
lily/include/staff-symbol.hh
lily/staff-symbol-referencer.cc
lily/staff-symbol.cc

diff --git a/input/regression/ledger-lines-varying-staves.ly b/input/regression/ledger-lines-varying-staves.ly
new file mode 100644 (file)
index 0000000..26c0b4a
--- /dev/null
@@ -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
+}
index 4dacde8b5353d4c6f49a3ef046b8351aead4e1f4..6791e7be1c21cf575afa1acd42613cd8aa9f2e58 100644 (file)
@@ -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();
index e8ef99f9dd3e180d4e386e2c490fd62f72f465bc..d623bd35b35412f93893a5c7c24497181bf54714 100644 (file)
@@ -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
index d4aa9e116c8bb35abc95a6aaabe33f0baa0852af..6fefc48010750e7daa9b2f9ed0078305047eff4b 100644 (file)
@@ -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"