2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "chord-name-engraver.hh"
10 #include "musical-request.hh"
11 #include "text-item.hh"
12 #include "paper-def.hh"
14 #include "paper-def.hh"
16 #include "dimensions.hh"
18 ADD_THIS_TRANSLATOR (Chord_name_engraver);
20 Chord_name_engraver::Chord_name_engraver ()
25 Chord_name_engraver::acknowledge_element (Score_element_info i)
27 if (Note_req* n = dynamic_cast<Note_req*> (i.req_l_))
28 pitch_arr_.push (n->pitch_);
32 Chord_name_engraver::do_try_music (Music* m)
34 if (Note_req* n = dynamic_cast<Note_req*> (m))
36 pitch_arr_.push (n->pitch_);
43 Chord_name_engraver::do_process_requests ()
45 if (text_p_arr_.size ())
47 if (!pitch_arr_.size ())
50 Scalar style = get_property ("textstyle");
51 Scalar alignment = get_property ("textalignment");
52 Text_def* text_p = new Text_def;
53 text_p->align_dir_ = LEFT;
54 if (style.length_i ())
55 text_p->style_str_ = style;
56 if (alignment.isnum_b())
57 text_p->align_dir_= (Direction)(int)alignment;
59 Musical_pitch tonic = pitch_arr_[0];
60 text_p->text_str_ = tonic.str ();
61 for (int i=1; i < pitch_arr_.size (); i++)
63 Musical_pitch p = pitch_arr_[i];
64 int trap = (p.notename_i_ - tonic.notename_i_ + 8) % 8 + 1;
65 if (((trap != 3) && (trap != 5)) || (p.accidental_i_))
67 text_p->text_str_ += to_str ((p.notename_i_ - tonic.notename_i_ + 8) % 8 + 1);
69 text_p->text_str_ += p.accidental_i_ < 0 ? "-" : "+";
70 if (i + 1 < pitch_arr_.size ())
71 text_p->text_str_ += "/";
75 Text_item* item_p = new Text_item (text_p);
77 item_p->fat_b_ = true;
78 text_p_arr_.push (item_p);
79 announce_element (Score_element_info (item_p, 0));
83 Chord_name_engraver::do_pre_move_processing ()
85 for (int i=0; i < text_p_arr_.size (); i++)
87 typeset_element (text_p_arr_[i]);