]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix #94. Added support for extraNatural.
authorRune Zedeler <rune@lilypond.org>
Tue, 19 Dec 2006 10:53:04 +0000 (11:53 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 19 Dec 2006 10:53:04 +0000 (11:53 +0100)
Now key signature naturals are placed at the same location as the
accidental that they cancels.

input/regression/key-signature-cancellation-extra-natural.ly [new file with mode: 0644]
lily/key-engraver.cc
lily/key-signature-interface.cc

diff --git a/input/regression/key-signature-cancellation-extra-natural.ly b/input/regression/key-signature-cancellation-extra-natural.ly
new file mode 100644 (file)
index 0000000..a103f4e
--- /dev/null
@@ -0,0 +1,23 @@
+\header {
+
+  texidoc = "If @code{extraNatural} is set then keys that are not
+  altered farther away (eg from sharp to double sharp) are
+  cancelled. Otherwise only keys that does not accur in the new key
+  signature are cancelled."  }
+
+
+\version "2.11.2"
+
+\paper {
+  ragged-right = ##t
+}
+{
+  \set Staff.extraNatural = ##f
+  \key fes \major r1
+  \key as \major r1_"No B-natural (#f)"
+  \set Staff.extraNatural = ##t
+  \key gis \major r1
+  \key b \major r1_"with F-natural (#t)"
+
+}
+
index 26b3985e4e31fcb760a08701ec92f4f72cc2ac74..41cb7aed5095e1cc3383a56377a2c24c2272d0c2 100644 (file)
@@ -72,6 +72,7 @@ Key_engraver::create_key (bool is_default)
 
       SCM last = get_property ("lastKeySignature");
       SCM key = get_property ("keySignature");
+      bool extranatural = to_boolean(get_property("extraNatural"));
 
       if ((to_boolean (get_property ("printKeyCancellation"))
           || key == SCM_EOL)
@@ -81,10 +82,13 @@ Key_engraver::create_key (bool is_default)
          SCM *tail = &restore;
          for (SCM s = last; scm_is_pair (s); s = scm_cdr (s))
            {
-             if (scm_assoc (scm_caar (s), key) == SCM_BOOL_F)
+             SCM new_alter_pair = scm_assoc (scm_caar (s), key);
+             int old_alter = scm_to_int (scm_cdar (s));
+             if (new_alter_pair == SCM_BOOL_F
+                 || extranatural
+                    && (scm_to_int(scm_cdr(new_alter_pair))-old_alter)*old_alter < 0)
                {
-                 *tail = scm_acons (scm_caar (s),
-                                    scm_from_int (0), *tail);
+                 *tail = scm_cons (scm_car (s), *tail);
                  tail = SCM_CDRLOC (*tail);
                }
            }
@@ -94,7 +98,7 @@ Key_engraver::create_key (bool is_default)
              cancellation_ = make_item ("KeyCancellation",
                                         key_event_
                                         ? key_event_->self_scm () : SCM_EOL);
-         
+             
              cancellation_->set_property ("alteration-alist", restore);
              cancellation_->set_property ("c0-position",
                                           get_property ("middleCPosition"));
@@ -203,6 +207,7 @@ ADD_TRANSLATOR (Key_engraver,
                /* read */
                "createKeyOnClefChange "
                "explicitKeySignatureVisibility "
+               "extraNatural "
                "keyAlterationOrder "
                "keySignature "
                "keySignature "
index 60a11db86ab831cbc0db12dd035ec20bc3773f96..37f985697ea85844ec17ed41ea3ad01cb919f9f7 100644 (file)
@@ -31,6 +31,9 @@ const int SHARP_TOP_PITCH = 4; /*  ais and bis typeset in lower octave */
 
 /*
   TODO: look this up. I'm not sure where the naturals ought to go.
+
+  COMMENT: Current implementation does not use the NATURAL_TOP_PITCH for anything,
+           always typesets naturals in the same place as the thing they cancel. -rz
 */
 const int NATURAL_TOP_PITCH = 4;
 
@@ -106,6 +109,9 @@ Key_signature_interface::print (SCM smob)
   if (scm_is_number (c0s))
     c0p = scm_to_int (c0s);
 
+  /* Is this the correct way to determine this? -rz */
+  bool is_cancellation = me->name()=="KeyCancellation";
+
   /*
     SCM lists are stacks, so we work from right to left, ending with
     the cancellation signature.
@@ -117,7 +123,10 @@ Key_signature_interface::print (SCM smob)
     {
       int alteration = scm_to_int (scm_cdar (s));
       string font_char
-       = Accidental_interface::get_fontcharname (style, alteration);
+       = Accidental_interface::get_fontcharname (style,
+                                                 is_cancellation
+                                                 ? 0
+                                                 : alteration);
       Stencil acc (fm->find_by_name ("accidentals." + font_char));
 
       if (acc.is_empty ())
@@ -134,7 +143,7 @@ Key_signature_interface::print (SCM smob)
            needed to prevent collisions.
          */
          Real padding = 0.0;
-         if (alteration == 0
+         if (is_cancellation
              && last_pos < pos + 2
              && last_pos > pos - 6)
            padding = 0.3;