source file of the GNU LilyPond music typesetter
- (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
+ (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
*/
#include "chord-name-engraver.hh"
+#include "chord-name.hh"
#include "musical-request.hh"
-#include "text-item.hh"
#include "paper-def.hh"
#include "lookup.hh"
#include "paper-def.hh"
#include "main.hh"
#include "dimensions.hh"
+#include "text-item.hh"
+
ADD_THIS_TRANSLATOR (Chord_name_engraver);
Chord_name_engraver::Chord_name_engraver ()
{
+ chord_name_p_ = 0;
+ tonic_req_ = 0;
+ inversion_req_ = 0;
+ bass_req_ = 0;
}
void
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 ()
+Chord_name_engraver::do_process_music ()
{
- if (text_p_arr_.size ())
+ if (chord_name_p_)
return;
if (!pitch_arr_.size ())
return;
- Scalar style = get_property ("textstyle");
- Scalar alignment = get_property ("textalignment");
- Text_def* text_p = new Text_def;
- text_p->align_dir_ = LEFT;
- if (style.length_i ())
- text_p->style_str_ = style;
- if (alignment.isnum_b())
- text_p->align_dir_= (Direction)(int)alignment;
+ bool find_inversion_b = false;
+ SCM chord_inversion = get_property ("chordInversion");
+ if (gh_boolean_p (chord_inversion))
+ find_inversion_b = gh_scm2bool (chord_inversion);
- Musical_pitch tonic = pitch_arr_[0];
- text_p->text_str_ = tonic.str ();
- for (int i=1; i < pitch_arr_.size (); i++)
- {
- Musical_pitch p = pitch_arr_[i];
- int trap = (p.notename_i_ - tonic.notename_i_ + 8) % 8 + 1;
- if (((trap != 3) && (trap != 5)) || (p.accidental_i_))
- {
- text_p->text_str_ += to_str ((p.notename_i_ - tonic.notename_i_ + 8) % 8 + 1);
- if (p.accidental_i_)
- text_p->text_str_ += p.accidental_i_ < 0 ? "-" : "+";
- if (i + 1 < pitch_arr_.size ())
- text_p->text_str_ += "/";
- }
- }
+ chord_name_p_ = new Chord_name;
+ Chord chord = to_chord (pitch_arr_, tonic_req_, inversion_req_, bass_req_,
+ find_inversion_b);
+
+ /*
+ Hmm, why not represent complete chord as list?
+ ((tonic third fifth) (inversion bass))
+ */
+ SCM plist = SCM_EOL;
+ for (int i= chord.pitch_arr_.size (); i--; )
+ plist = gh_cons (chord.pitch_arr_[i].to_scm (), plist);
+
+ chord_name_p_->set_elt_property ("pitches", plist);
+ if (chord.inversion_b_)
+ chord_name_p_->set_elt_property ("inversion",
+ chord.inversion_pitch_.to_scm ());
+ if (chord.bass_b_)
+ chord_name_p_->set_elt_property ("bass", chord.bass_pitch_.to_scm ());
- Text_item* item_p = new Text_item (text_p);
- item_p->dir_ = DOWN;
- item_p->fat_b_ = true;
- text_p_arr_.push (item_p);
- announce_element (Score_element_info (item_p, 0));
+ announce_element (Score_element_info (chord_name_p_, 0));
}
void
Chord_name_engraver::do_pre_move_processing ()
{
- for (int i=0; i < text_p_arr_.size (); i++)
+ if (chord_name_p_)
{
- typeset_element (text_p_arr_[i]);
+ typeset_element (chord_name_p_);
}
- text_p_arr_.clear ();
pitch_arr_.clear ();
+ chord_name_p_ = 0;
+ tonic_req_ = 0;
+ inversion_req_ = 0;
+ bass_req_ = 0;
}