]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/accidental-engraver.cc
Run grand replace for 2015.
[lilypond.git] / lily / accidental-engraver.cc
index bc013f516f34d3d834ab28ce2ee5eb8b19232d6e..fcc9fcb97792643723097414cbe6cbdb600ba289 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
   Modified 2001--2002 by Rune Zedeler <rz@daimi.au.dk>
 
   LilyPond is free software: you can redistribute it and/or modify
@@ -58,6 +58,7 @@ Accidental_entry::Accidental_entry ()
   melodic_ = 0;
   accidental_ = 0;
   origin_ = 0;
+  origin_engraver_ = 0;
   head_ = 0;
 }
 
@@ -72,7 +73,7 @@ protected:
   TRANSLATOR_DECLARATIONS (Accidental_engraver);
   void process_music ();
 
-  void acknowledge_tie (Grob_info);
+  void acknowledge_end_tie (Grob_info);
   void acknowledge_arpeggio (Grob_info);
   void acknowledge_rhythmic_head (Grob_info);
   void acknowledge_finger (Grob_info);
@@ -98,7 +99,7 @@ public:
 };
 
 /*
-  localKeySignature is changed at runtime, which means that references
+  localAlterations is changed at runtime, which means that references
   in grobs should always store ly_deep_copy ()s of those.
 */
 
@@ -119,7 +120,7 @@ Accidental_engraver::update_local_key_signature (SCM new_sig)
 {
   last_keysig_ = new_sig;
   set_context_property_on_children (context (),
-                                    ly_symbol2scm ("localKeySignature"),
+                                    ly_symbol2scm ("localAlterations"),
                                     new_sig);
 
   Context *trans = context ()->get_parent_context ();
@@ -130,9 +131,9 @@ Accidental_engraver::update_local_key_signature (SCM new_sig)
   */
 
   SCM val;
-  while (trans && trans->where_defined (ly_symbol2scm ("localKeySignature"), &val) == trans)
+  while (trans && trans->here_defined (ly_symbol2scm ("localAlterations"), &val))
     {
-      trans->set_property ("localKeySignature", ly_deep_copy (last_keysig_));
+      trans->set_property ("localAlterations", ly_deep_copy (last_keysig_));
       trans = trans->get_parent_context ();
     }
 }
@@ -232,7 +233,7 @@ Accidental_engraver::process_acknowledged ()
           Stream_event *note = accidentals_[i].melodic_;
           Context *origin = accidentals_[i].origin_;
 
-          Pitch *pitch = unsmob_pitch (note->get_property ("pitch"));
+          Pitch *pitch = Pitch::unsmob (note->get_property ("pitch"));
           if (!pitch)
             continue;
 
@@ -328,7 +329,11 @@ Accidental_engraver::make_standard_accidental (Stream_event * /* note */,
   if (!accidental_placement_)
     accidental_placement_ = make_item ("AccidentalPlacement",
                                        a->self_scm ());
-  Accidental_placement::add_accidental (accidental_placement_, a);
+
+  Accidental_placement::add_accidental
+    (accidental_placement_, a,
+     get_property ("accidentalGrouping") == ly_symbol2scm ("voice"),
+     (long) trans);
 
   note_head->set_object ("accidental-grob", a->self_scm ());
 
@@ -343,7 +348,7 @@ Accidental_engraver::make_suggested_accidental (Stream_event * /* note */,
   Grob *a = trans->make_item ("AccidentalSuggestion", note_head->self_scm ());
 
   Side_position_interface::add_support (a, note_head);
-  if (Grob *stem = unsmob_grob (a->get_object ("stem")))
+  if (Grob *stem = Grob::unsmob (a->get_object ("stem")))
     Side_position_interface::add_support (a, stem);
 
   a->set_parent (note_head, X_AXIS);
@@ -362,6 +367,18 @@ Accidental_engraver::stop_translation_timestep ()
   for (vsize j = ties_.size (); j--;)
     {
       Grob *r = Tie::head (ties_[j], RIGHT);
+      Grob *l = Tie::head (ties_[j], LEFT);
+      if (l && r)
+        {
+          // Don't mark accidentals as "tied" when the pitch is not
+          // actually the same.  This is relevant for enharmonic ties.
+          Stream_event *le = Stream_event::unsmob (l->get_property ("cause"));
+          Stream_event *re = Stream_event::unsmob (r->get_property ("cause"));
+          if (le && re
+              && !ly_is_equal (le->get_property ("pitch"), re->get_property ("pitch")))
+            continue;
+        }
+
       for (vsize i = accidentals_.size (); i--;)
         if (accidentals_[i].head_ == r)
           {
@@ -382,7 +399,7 @@ Accidental_engraver::stop_translation_timestep ()
 
       int barnum = measure_number (origin);
 
-      Pitch *pitch = unsmob_pitch (note->get_property ("pitch"));
+      Pitch *pitch = Pitch::unsmob (note->get_property ("pitch"));
       if (!pitch)
         continue;
 
@@ -392,12 +409,12 @@ Accidental_engraver::stop_translation_timestep ()
       SCM key = scm_cons (scm_from_int (o), scm_from_int (n));
 
       Moment end_mp = measure_position (context (),
-                                        unsmob_duration (note->get_property ("duration")));
+                                        Duration::unsmob (note->get_property ("duration")));
       SCM position = scm_cons (scm_from_int (barnum), end_mp.smobbed_copy ());
 
       SCM localsig = SCM_EOL;
       while (origin
-             && origin->where_defined (ly_symbol2scm ("localKeySignature"), &localsig))
+             && origin->where_defined (ly_symbol2scm ("localAlterations"), &localsig))
         {
           bool change = false;
           if (accidentals_[i].tied_
@@ -424,7 +441,7 @@ Accidental_engraver::stop_translation_timestep ()
             }
 
           if (change)
-            origin->set_property ("localKeySignature", localsig);
+            origin->set_property ("localAlterations", localsig);
 
           origin = origin->get_parent_context ();
         }
@@ -447,27 +464,25 @@ Accidental_engraver::acknowledge_rhythmic_head (Grob_info info)
   Stream_event *note = info.event_cause ();
   if (note
       && (note->in_event_class ("note-event")
-          || note->in_event_class ("trill-span-event")))
+          || note->in_event_class ("trill-span-event"))
+      // option to skip accidentals on string harmonics
+      && (to_boolean (get_property ("harmonicAccidentals"))
+          || info.grob ()->get_property ("style") != ly_symbol2scm ("harmonic"))
+      // ignore accidentals in non-printing voices like NullVoice
+      && !to_boolean (info.context ()->get_property ("nullAccidentals")))
     {
-      /*
-        string harmonics usually don't have accidentals.
-      */
-      if (info.grob ()->get_property ("style") != ly_symbol2scm ("harmonic")
-          || to_boolean (get_property ("harmonicAccidentals")))
-        {
-          Accidental_entry entry;
-          entry.head_ = info.grob ();
-          entry.origin_engraver_ = dynamic_cast<Engraver *> (info.origin_translator ());
-          entry.origin_ = entry.origin_engraver_->context ();
-          entry.melodic_ = note;
+      Accidental_entry entry;
+      entry.head_ = info.grob ();
+      entry.origin_engraver_ = dynamic_cast<Engraver *> (info.origin_translator ());
+      entry.origin_ = entry.origin_engraver_->context ();
+      entry.melodic_ = note;
 
-          accidentals_.push_back (entry);
-        }
+      accidentals_.push_back (entry);
     }
 }
 
 void
-Accidental_engraver::acknowledge_tie (Grob_info info)
+Accidental_engraver::acknowledge_end_tie (Grob_info info)
 {
   ties_.push_back (dynamic_cast<Spanner *> (info.grob ()));
 }
@@ -493,7 +508,7 @@ Accidental_engraver::acknowledge_finger (Grob_info info)
 void
 Accidental_engraver::process_music ()
 {
-  SCM sig = get_property ("keySignature");
+  SCM sig = get_property ("keyAlterations");
   if (last_keysig_ != sig)
     update_local_key_signature (sig);
 }
@@ -501,7 +516,7 @@ Accidental_engraver::process_music ()
 ADD_ACKNOWLEDGER (Accidental_engraver, arpeggio);
 ADD_ACKNOWLEDGER (Accidental_engraver, finger);
 ADD_ACKNOWLEDGER (Accidental_engraver, rhythmic_head);
-ADD_ACKNOWLEDGER (Accidental_engraver, tie);
+ADD_END_ACKNOWLEDGER (Accidental_engraver, tie);
 ADD_ACKNOWLEDGER (Accidental_engraver, note_column);
 
 ADD_TRANSLATOR (Accidental_engraver,
@@ -524,9 +539,10 @@ ADD_TRANSLATOR (Accidental_engraver,
                 "internalBarNumber "
                 "extraNatural "
                 "harmonicAccidentals "
-                "keySignature "
-                "localKeySignature ",
+                "accidentalGrouping "
+                "keyAlterations "
+                "localAlterations ",
 
                 /* write */
-                "localKeySignature "
+                "localAlterations "
                );