From f542a0188fa0fc160b5580c119c64eb1966f196a Mon Sep 17 00:00:00 2001 From: Rune Zedeler Date: Tue, 19 Dec 2006 11:53:04 +0100 Subject: [PATCH] Fix #94. Added support for extraNatural. Now key signature naturals are placed at the same location as the accidental that they cancels. --- ...ey-signature-cancellation-extra-natural.ly | 23 +++++++++++++++++++ lily/key-engraver.cc | 13 +++++++---- lily/key-signature-interface.cc | 13 +++++++++-- 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 input/regression/key-signature-cancellation-extra-natural.ly diff --git a/input/regression/key-signature-cancellation-extra-natural.ly b/input/regression/key-signature-cancellation-extra-natural.ly new file mode 100644 index 0000000000..a103f4ed50 --- /dev/null +++ b/input/regression/key-signature-cancellation-extra-natural.ly @@ -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)" + +} + diff --git a/lily/key-engraver.cc b/lily/key-engraver.cc index 26b3985e4e..41cb7aed50 100644 --- a/lily/key-engraver.cc +++ b/lily/key-engraver.cc @@ -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 " diff --git a/lily/key-signature-interface.cc b/lily/key-signature-interface.cc index 5705b46ccf..4c8d28f510 100644 --- a/lily/key-signature-interface.cc +++ b/lily/key-signature-interface.cc @@ -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; -- 2.39.2