lilypond-1.1.55
[lilypond.git] / lily / chord-name-engraver.cc
blobdbebdf6e08ce6b3e5b2f2814e48d7118def03c32
1 /*
2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999, 1999 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "chord-name-engraver.hh"
10 #include "chord.hh"
11 #include "musical-request.hh"
12 #include "paper-def.hh"
13 #include "lookup.hh"
14 #include "paper-def.hh"
15 #include "main.hh"
16 #include "dimensions.hh"
17 #include "g-text-item.hh"
19 ADD_THIS_TRANSLATOR (Chord_name_engraver);
21 Chord_name_engraver::Chord_name_engraver ()
23 tonic_req_ = 0;
26 void
27 Chord_name_engraver::acknowledge_element (Score_element_info i)
29 if (Note_req* n = dynamic_cast<Note_req*> (i.req_l_))
30 pitch_arr_.push (n->pitch_);
33 bool
34 Chord_name_engraver::do_try_music (Music* m)
36 if (Note_req* n = dynamic_cast<Note_req*> (m))
38 pitch_arr_.push (n->pitch_);
39 return true;
41 if (Tonic_req* t = dynamic_cast<Tonic_req*> (m))
43 tonic_req_ = t;
44 return true;
46 return false;
49 void
50 Chord_name_engraver::do_process_requests ()
52 if (text_p_arr_.size ())
53 return;
54 if (!pitch_arr_.size ())
55 return;
57 Chord chord (pitch_arr_);
58 Musical_pitch* inversion = 0;
59 Scalar chord_inversion = get_property ("chordInversion", 0);
60 if (chord_inversion.to_bool ())
62 int tonic_i = tonic_req_
63 ? chord.find_notename_i (tonic_req_->pitch_) : chord.find_tonic_i ();
65 if (tonic_i)
67 inversion = &pitch_arr_[0];
68 chord.rebuild_insert_inversion (tonic_i);
72 G_text_item* item_p = new G_text_item;
75 TODO:
76 - switch on property, add american (?) chordNameStyle:
77 Chord::american_str (...)
79 Scalar chordNameStyle = get_property ("chordNameStyle", 0);
80 if (chordNameStyle == "Banter")
81 item_p->text_str_ = chord.banter_str (inversion);
84 item_p->text_str_ = chord.banter_str (inversion);
86 Scalar style = get_property ("textStyle", 0);
87 if (style.length_i ())
88 item_p->style_str_ = style;
90 text_p_arr_.push (item_p);
91 announce_element (Score_element_info (item_p, 0));
94 void
95 Chord_name_engraver::do_pre_move_processing ()
97 for (int i=0; i < text_p_arr_.size (); i++)
99 typeset_element (text_p_arr_[i]);
101 text_p_arr_.clear ();
102 pitch_arr_.clear ();
103 tonic_req_ = 0;