lilypond-1.3.58
authorfred <fred>
Tue, 26 Mar 2002 23:22:41 +0000 (23:22 +0000)
committerfred <fred>
Tue, 26 Mar 2002 23:22:41 +0000 (23:22 +0000)
lily/include/key-engraver.hh
lily/include/newkey.hh [new file with mode: 0644]
lily/local-key-engraver.cc
lily/newkey.cc [new file with mode: 0644]

index 171ef13e9e11410a18e0ec7e2c68416f3ebb5a99..408f961d67d9725b7bd1f6b361a235c4e780be86 100644 (file)
 #define KEYGRAV_HH
 
 #include "engraver.hh"
-#include "key.hh"
+
 #include "musical-pitch.hh"
+#include "protected-scm.hh"
+#include "newkey.hh"
+
 
 /**
   Make the key signature.
@@ -29,13 +32,12 @@ public:
   /*
     TODO: move these into properties.
    */
-  Key key_;
+  Newkey key_;
   Key_change_req * keyreq_l_;
   Key_item * item_p_;
 
-  Array<Musical_pitch> accidental_idx_arr_;
-  Array<Musical_pitch> old_accidental_idx_arr_;
-
+  Protected_scm old_accs_;
+  Protected_scm new_accs_;  
 
   bool key_changed_b() const;
     
diff --git a/lily/include/newkey.hh b/lily/include/newkey.hh
new file mode 100644 (file)
index 0000000..32c3ad7
--- /dev/null
@@ -0,0 +1,32 @@
+/*   
+  newkey.hh -- declare Newkey
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  
+ */
+
+#ifndef NEWKEY_HH
+#define NEWKEY_HH
+
+#include "protected-scm.hh" 
+
+class Newkey
+{
+  /*
+    alist mapping 
+    (octave . notename) -> accidental and notename -> accidental
+   */
+  Protected_scm key_alist_;
+public:
+  void set (int name, int acc);
+  void set (int oct, int name, int acc);
+  void clear ();
+  void set_scm (SCM k, SCM v);
+  Newkey();
+  int get (int oct, int name);
+  int get (int name);
+};
+#endif /* NEWKEY_HH */
+
index 192baaee47dc8da1c9ca03707469b510d7f437cf..d8350f1c7a3ad5ad9198424958d13d3147a6e788 100644 (file)
@@ -20,7 +20,7 @@
 #include "staff-symbol-referencer.hh"
 #include "side-position-interface.hh"
 #include "engraver.hh"
-#include "key.hh"
+
 #include "parray.hh"
 
 
@@ -42,7 +42,7 @@ protected:
   virtual void do_removal_processing ();
 public:
   
-  Key local_key_;
+  Newkey local_key_;
   Key_engraver *key_grav_l_;
   Array<Note_req* > mel_l_arr_;
   Array<Item*> support_l_arr_;
@@ -111,15 +111,15 @@ Local_key_engraver::process_acknowledged ()
          /* see if there's a tie that "changes" the accidental */
          /* works because if there's a tie, the note to the left
             is of the same pitch as the actual note */
-         bool tie_changes = tied_l_arr_.find_l (support_l)
-           && !local_key_.different_acc (note_l->pitch_);
 
+         int prev_acc =local_key_.get (note_l->pitch_.octave_i_,
+                                       note_l->pitch_.notename_i_);
+         bool different = prev_acc != note_l->pitch_.accidental_i_;
+         
+         bool tie_changes = tied_l_arr_.find_l (support_l) && different;
          if (!forget
-
-             && ((note_l->forceacc_b_
-                  || !local_key_.different_acc (note_l->pitch_)
-                  || local_key_.internal_forceacc (note_l->pitch_)))
-
+             && (note_l->forceacc_b_
+                 || !different)
              && !tie_changes)
            {
              if (!key_item_p_) 
@@ -132,15 +132,21 @@ Local_key_engraver::process_acknowledged ()
                  announce_element (Score_element_info (key_item_p_, 0));
                }
 
+             
+             bool extra_natural
+               = sign (prev_acc) * (prev_acc - note_l->pitch_.accidental_i_) == 1 ;
+
              key_item_p_->add_pitch (note_l->pitch_,
                                      note_l->cautionary_b_,
-                                     local_key_.double_to_single_acc(note_l->pitch_));
+                                     extra_natural);
              Side_position_interface (key_item_p_).add_support (support_l);
            }
          
          if (!forget)
            {
-             local_key_.set (note_l->pitch_);
+             local_key_.set (note_l->pitch_.octave_i_, note_l->pitch_.notename_i_,
+                             note_l->pitch_.accidental_i_);
+#if 0
              if (!tied_l_arr_.find_l (support_l))
                {
                  local_key_.clear_internal_forceacc (note_l->pitch_);
@@ -149,6 +155,7 @@ Local_key_engraver::process_acknowledged ()
                {
                  local_key_.set_internal_forceacc (note_l->pitch_);
                }
+#endif
            }
         }
     }
diff --git a/lily/newkey.cc b/lily/newkey.cc
new file mode 100644 (file)
index 0000000..31bd1c9
--- /dev/null
@@ -0,0 +1,45 @@
+#include "newkey.hh"
+
+Newkey::Newkey ()
+{
+  clear();
+}
+
+void
+Newkey::clear()
+{
+  key_alist_ = SCM_EOL;
+}
+
+void
+Newkey::set (int n, int a)
+{
+  set_scm (gh_int2scm (n), gh_int2scm (a));
+}
+
+void
+Newkey::set (int o, int n, int a)
+{
+  set_scm (gh_cons (gh_int2scm (o),gh_int2scm(n)), gh_int2scm (a));
+}
+
+void
+Newkey::set_scm (SCM k, SCM v)
+{
+  key_alist_
+    = scm_assoc_set_x (key_alist_, k, v);  
+}
+
+int
+Newkey::get (int o, int n)
+{
+  SCM r = scm_assoc (gh_cons (gh_int2scm (o), gh_int2scm (n)), key_alist_);
+  return r == SCM_BOOL_F ? get (n) : gh_cdr (r);
+}
+
+int
+Newkey::get (int n)
+{
+  SCM r = scm_assoc (gh_int2scm (n), key_alist_);
+  return r == SCM_BOOL_F ? 0: gh_cdr (r);
+}