]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/chord-name-engraver.cc
partial: 1.3.13.jcn
[lilypond.git] / lily / chord-name-engraver.cc
index 336eacb3ed4a36437d5485c61e58bc948e86f7b8..21f0a99f1ad7f4fa239b76293bc60574e0ba0233 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1998--1999 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "chord-name-engraver.hh"
 #include "paper-def.hh"
 #include "main.hh"
 #include "dimensions.hh"
-#include "g-text-item.hh"
+#include "text-item.hh"
 
 ADD_THIS_TRANSLATOR (Chord_name_engraver);
 
 Chord_name_engraver::Chord_name_engraver ()
 {
+  chord_p_ = 0;
+  tonic_req_ = 0;
+  inversion_req_ = 0;
+  bass_req_ = 0;
 }
 
 void
@@ -37,65 +41,53 @@ Chord_name_engraver::do_try_music (Music* m)
       pitch_arr_.push (n->pitch_);
       return true;
     }
+  if (Tonic_req* t = dynamic_cast<Tonic_req*> (m))
+    {
+      tonic_req_ = t;
+      return true;
+    }
+  if (Inversion_req* i = dynamic_cast<Inversion_req*> (m))
+    {
+      inversion_req_ = i;
+      return true;
+    }
+  if (Bass_req* b = dynamic_cast<Bass_req*> (m))
+    {
+      bass_req_ = b;
+      return true;
+    }
   return false;
 }
 
 void
 Chord_name_engraver::do_process_requests ()
 {
-  if (text_p_arr_.size ())
+  if (chord_p_)
     return;
   if (!pitch_arr_.size ())
     return;
 
-  /*
-   Banter style chord names (almost).
-   TODO:
-     - move this stuff to new Item class Chord_name
-     - switch on property, add american (?) chordNameStyle
-
-  Scalar chordNameStyle = get_property ("chordNameStyle", 0);
-  if (chordNameStyle == "Banter")
-     chord = pitches_to_banter (pitch_arr_));
+  bool find_inversion_b = false;
+  SCM chord_inversion = get_property ("chordInversion", 0);
+  if (gh_boolean_p (chord_inversion))
+    find_inversion_b = gh_scm2bool (chord_inversion);
 
-   */
-
-  Chord chord (pitch_arr_);
-  Musical_pitch* inversion = 0;
-  Scalar chord_inversion = get_property ("chordInversion", 0);
-  if (chord_inversion.to_bool ())
-    {
-      int tonic_i = chord.find_tonic_i ();
-      if (tonic_i)
-       {
-         inversion = &pitch_arr_[0];
-         Scalar preserve = get_property ("chordInversionPreserve", 0);
-         if (preserve.to_bool ())
-           chord.rebuild_from_base (tonic_i);
-         else
-           chord.rebuild_insert_inversion (tonic_i);
-       }
-    }
+  chord_p_ = new Chord (to_chord (pitch_arr_, tonic_req_, inversion_req_, bass_req_, find_inversion_b));
     
-  G_text_item* item_p =  new G_text_item;
-
-  item_p->text_str_ = chord.banter_str (inversion);
-  
-  Scalar style = get_property ("textstyle", 0);
-  if (style.length_i ())
-    item_p->style_str_ = style;
-  
-  text_p_arr_.push (item_p);
-  announce_element (Score_element_info (item_p, 0));
+  announce_element (Score_element_info (chord_p_, 0));
 }
 
 void
 Chord_name_engraver::do_pre_move_processing ()
 {
-  for (int i=0; i < text_p_arr_.size (); i++)
+  if (chord_p_)
     {
-      typeset_element (text_p_arr_[i]);
+      typeset_element (chord_p_);
     }
-  text_p_arr_.clear ();
   pitch_arr_.clear ();
+  chord_p_ = 0;
+  tonic_req_ = 0;
+  inversion_req_ = 0;
+  bass_req_ = 0;
 }
+