]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/accidental-engraver.cc
release: 1.5.44
[lilypond.git] / lily / accidental-engraver.cc
index 5b476a05cb8dd922f4fe61228761046c7a4832e9..14dd955cd3a18914530f1a594bb57a87e3119ae7 100644 (file)
@@ -2,7 +2,7 @@
   accidental-engraver.cc -- implement accidental_engraver
 
   (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  Modified 2001-2002 by Rune Zedeler <rz@daimi.au.dk>
+  Modified 2001 by Rune Zedeler <rz@daimi.au.dk>
 */
 
 #include "musical-request.hh"
@@ -19,8 +19,6 @@
 #include "arpeggio.hh"
 #include "warn.hh"
 
-#include "translator-group.hh"
-
 /**
 
 
@@ -45,7 +43,7 @@ protected:
   virtual void finalize ();
 public:
 
-  // todo -> property   (why? -rz)
+  // todo -> property
   SCM last_keysig_;
 
   /*
@@ -58,7 +56,6 @@ public:
   Link_array<Grob> head_l_arr_;
   Link_array<Item> forced_l_arr_;
   Link_array<Grob> tie_l_arr_;
-  Link_array<Translator_group> origin_l_arr_;
 
 };
 
@@ -73,22 +70,14 @@ void
 Accidental_engraver::initialize ()
 {
   last_keysig_ = get_property ("keySignature");
-
-  Translator_group * trans_ = daddy_trans_l_;
-  while (trans_) {
-    trans_ -> set_property ("localKeySignature",  ly_deep_copy(last_keysig_));
-    trans_ = trans_->daddy_trans_l_;
-  }
-  daddy_trans_l_->set_children_property("localKeySignature",last_keysig_);
-
+  daddy_trans_l_->set_property ("localKeySignature",  last_keysig_);  
 }
 
 /** calculates the number of accidentals on basis of the current local key sig
-  * (passed as argument)
+  * (passed as argument).
   * Returns number of accidentals (0, 1 or 2).
   *   Negative (-1 or -2) if accidental has changed.
   **/
-// FIXME: Use references for SCM-values
 static int
 number_accidentals (SCM sig, Note_req * note_l, SCM curbarnum, SCM lazyness,
                    bool ignore_octave_b)
@@ -125,46 +114,31 @@ number_accidentals (SCM sig, Note_req * note_l, SCM curbarnum, SCM lazyness,
   return a==p ? num : -num;
 }
 
-int
-number_accidentals (Note_req * note_l, Translator_group * origin_l,
-                   SCM accidentals_sl, SCM curbarnum_s) {
+static int
+number_accidentals (SCM localsig, Note_req * note_l, SCM accidentals_l,
+                   SCM curbarnum) {
   int number=0;
   int diff=0;
-  if(gh_pair_p(accidentals_sl) && !gh_symbol_p(ly_car(accidentals_sl)))
-    warning(_f("Accidental typesetting list must begin with context-name: %s",
-              ly_scm2string(ly_car(accidentals_sl)).ch_C()));
-  while(gh_pair_p(accidentals_sl) && origin_l) {
-    // If pair then it is a new accidentals typesetting rule to be checked
-    if(gh_pair_p(ly_car(accidentals_sl))) {
-      SCM type = gh_caar(accidentals_sl);
-      SCM lazyness = gh_cdar(accidentals_sl);
-      SCM localsig = origin_l->get_property ("localKeySignature");
-      bool same_octave_b =
-       gh_eq_p(ly_symbol2scm("same-octave"),type);
-      bool any_octave_b =
-       gh_eq_p(ly_symbol2scm("any-octave"),type);
-      if(same_octave_b || any_octave_b) {
+  while(gh_pair_p(accidentals_l)) {
+    if(gh_pair_p(ly_car(accidentals_l))) {
+      SCM type = gh_caar(accidentals_l);
+      SCM lazyness = gh_cdar(accidentals_l);
+      bool measure_same_octave_b =
+       gh_eq_p(ly_symbol2scm("measure-same-octave"),type);
+      bool measure_any_octave_b =
+       gh_eq_p(ly_symbol2scm("measure-any-octave"),type);
+      if(measure_same_octave_b || measure_any_octave_b) {
        int n = number_accidentals
-         (localsig,note_l,curbarnum_s,lazyness,any_octave_b);
+         (localsig,note_l,curbarnum,lazyness,measure_any_octave_b);
        diff |= n<0;
        number = max(number,abs(n));     
       }
-      else warning(_f("unknown accidental typesetting: %s. Ignored",
+      else warning(_f("unknown accidental typesetting: %s",
                      ly_symbol2string(type).ch_C()));
     }
-    // if symbol then it is a context name. Scan parent contexts to find it.
-    else if (gh_symbol_p(ly_car(accidentals_sl))) {
-      String context = ly_symbol2string(ly_car(accidentals_sl));
-      while (origin_l && !origin_l->is_alias_b(context)) {
-        origin_l = origin_l->daddy_trans_l_;
-      }
-      if (!origin_l)
-       warning(_f("Symbol is not a parent context: %s. Ignored",
-                  context.ch_C()));
-    }
-    else warning(_f("Accidental typesetting must be pair or context-name: %s",
-                     ly_scm2string(ly_car(accidentals_sl)).ch_C()));
-    accidentals_sl = ly_cdr(accidentals_sl);
+    else warning(_f("Accidental typesetting must be pair: %s",
+                     ly_scm2string(ly_car(accidentals_l)).ch_C()));
+    accidentals_l = ly_cdr(accidentals_l);
   }
   return diff ? -number : number;
 }
@@ -174,9 +148,9 @@ Accidental_engraver::create_grobs ()
 {
   if (!key_item_p_ && mel_l_arr_.size ()) 
     {
-      //SCM localsig = get_property ("localKeySignature");
-      SCM accidentals_sl =  get_property ("autoAccidentals");
-      SCM cautionaries_sl =  get_property ("autoCautionaries");
+      SCM localsig = get_property ("localKeySignature");
+      SCM accidentals_l =  get_property ("autoAccidentals");
+      SCM cautionaries_l =  get_property ("autoCautionaries");
       SCM barnum = get_property ("currentBarNumber");
 
       bool extra_natural_b = get_property ("extraNatural")==SCM_BOOL_T;
@@ -184,10 +158,9 @@ Accidental_engraver::create_grobs ()
        {
          Grob * support_l = head_l_arr_[i];
          Note_req * note_l = mel_l_arr_[i];
-         Translator_group * origin_l = origin_l_arr_[i];
 
-         int num = number_accidentals(note_l,origin_l,accidentals_sl,barnum);
-         int num_caut = number_accidentals(note_l,origin_l,cautionaries_sl,barnum);
+         int num = number_accidentals(localsig,note_l,accidentals_l,barnum);
+         int num_caut = number_accidentals(localsig,note_l,cautionaries_l,barnum);
          bool cautionary = to_boolean (note_l->get_mus_property ("cautionary"));
          if (abs(num_caut)>abs(num))
            {
@@ -205,8 +178,8 @@ Accidental_engraver::create_grobs ()
 
          Grob *tie_break_reminder = 0;
          bool tie_changes = false;
-         for (int j=0; j < tie_l_arr_.size (); j++)
-           if (support_l == Tie::head (tie_l_arr_[j], RIGHT))
+         for (int i=0; i < tie_l_arr_.size (); i++)
+           if (support_l == Tie::head (tie_l_arr_[i], RIGHT))
              {
                tie_changes = different;
                /* Enable accidentals for broken tie
@@ -216,7 +189,7 @@ Accidental_engraver::create_grobs ()
                   
                   Maybe check property noTieBreakForceAccidental? */
                if (different)
-                 tie_break_reminder = tie_l_arr_[j];
+                 tie_break_reminder = tie_l_arr_[i];
                break;
              }
 
@@ -258,40 +231,30 @@ Accidental_engraver::create_grobs ()
          int n = pitch->notename_i_;
          int o = pitch->octave_i_;
          int a = pitch->alteration_i_;
-         SCM on_s = gh_cons (gh_int2scm (o), gh_int2scm (n));
-
-         /*
-           TODO: Speed this up!
-           Perhaps only check translators mentioned in the auto-accidentals?
-           -rz
-         */
-         Translator_group * trans_ = origin_l_arr_[i];
-         while (trans_) {
-           SCM localsig = trans_->get_property ("localKeySignature");
-           if (tie_changes)
-             {
-               /*
-                 Remember an alteration that is different both from
-                 that of the tied note and of the key signature.
-               */
-               localsig = ly_assoc_front_x
-                 (localsig, on_s, gh_cons(SCM_BOOL_T,barnum));
-             }
-           else
-             {
-               /*
-                 not really really correct if there are more than one
-                 noteheads with the same notename.
-               */
-               localsig = ly_assoc_front_x
-                 (localsig, on_s, gh_cons(gh_int2scm (a),barnum)); 
-             }
-           trans_->set_property ("localKeySignature",  localsig);
-           trans_ = trans_->daddy_trans_l_;
-         }
-       }
+         SCM on = gh_cons (gh_int2scm (o), gh_int2scm (n));
+         if (tie_changes)
+           {
+             /*
+               Remember an alteration that is different both from
+               that of the tied note and of the key signature.
+              */
+             localsig = ly_assoc_front_x
+               (localsig, on, gh_cons(SCM_BOOL_T,barnum));
+           }
+         else
+           {
+             /*
+               not really really correct if there are more than one
+               noteheads with the same notename.
+              */
+             localsig = ly_assoc_front_x
+               (localsig, on, gh_cons(gh_int2scm (a),barnum)); 
+           }
+        }
+  
+      daddy_trans_l_->set_property ("localKeySignature",  localsig);
     }
-
+  
   
   if (key_item_p_)
     {
@@ -330,8 +293,7 @@ Accidental_engraver::stop_translation_timestep ()
   arpeggios_.clear ();
   tie_l_arr_.clear ();
   head_l_arr_.clear ();
-  forced_l_arr_.clear ();
-  origin_l_arr_.clear ();
+  forced_l_arr_.clear ();      
 }
 
 void
@@ -343,7 +305,6 @@ Accidental_engraver::acknowledge_grob (Grob_info info)
     {
       mel_l_arr_.push (note_l);
       head_l_arr_.push (info.grob_l_);
-      origin_l_arr_.push (info.origin_trans_l_->daddy_trans_l_);
     }
   else if (Tie::has_interface (info.grob_l_))
     {
@@ -366,19 +327,12 @@ Accidental_engraver::process_music ()
   
   SCM sig = get_property ("keySignature");
 
-  /* Detect key sig changes.
-     Update all parents and children
-     */
-  if (last_keysig_ != sig) {
-    Translator_group * trans_ = daddy_trans_l_;
-    while (trans_) {
-      trans_ -> set_property ("localKeySignature",  ly_deep_copy(sig));
-      trans_ = trans_->daddy_trans_l_;
+  /* Detect key sig changes. */
+  if (last_keysig_ != sig) 
+    {
+      daddy_trans_l_->set_property ("localKeySignature",  ly_deep_copy (sig));
+      last_keysig_ = sig;
     }
-    daddy_trans_l_->set_children_property("localKeySignature",sig);
-
-    last_keysig_ = sig;
-  }
 }
 
 
@@ -386,7 +340,6 @@ Accidental_engraver::process_music ()
 
 
 ENTER_DESCRIPTION(Accidental_engraver,
-/* The FIXME below is deprecated and should be removed. -rz */
 /* descr */       "Make accidentals.  Catches note heads, ties and notices key-change
 events.  Due to interaction with ties (which don't come together
 with note heads), this needs to be in a context higher than Tie_engraver. FIXME",