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 ())
51 Banter style chord names (almost).
53 - don't print inclusive scale (i.e. no "9" in c 9/11)
55 - use #,b iso -es -is on tonica
56 - switch on property, add american (?) chordNameStyle
58 Scalar chordNameStyle = get_property ("chordNameStyle");
59 if (chordNameStyle == "Banner")
60 chord = pitches_to_banner (pitch_arr_.size ());
64 Scalar style = get_property ("textstyle");
65 Scalar alignment = get_property ("textalignment");
66 Text_def* text_p = new Text_def;
67 text_p->align_dir_ = LEFT;
68 if (style.length_i ())
69 text_p->style_str_ = style;
70 if (alignment.isnum_b())
71 text_p->align_dir_= (Direction)(int)alignment;
73 Musical_pitch tonic = pitch_arr_[0];
75 Array<Musical_pitch> scale;
76 scale.push (Musical_pitch (0)); // c
77 scale.push (Musical_pitch (1)); // d
78 scale.push (Musical_pitch (2)); // e
79 scale.push (Musical_pitch (3)); // f
80 scale.push (Musical_pitch (4)); // g
81 scale.push (Musical_pitch (5)); // a
82 // 7 always means 7-...
83 scale.push (Musical_pitch (6, -1)); // b
85 for (int i = 0; i < scale.size (); i++)
86 scale[i].transpose (tonic);
88 //urg, should do translation in scheme.
89 char const *acc[] = {"\\textflat\\textflat ", "\\textflat ", "", "\\textsharp " , "\\textsharp\\textsharp "};
90 String tonic_str = tonic.str ();
91 tonic_str = tonic_str.left_str (1).upper_str ()
92 + acc[tonic.accidental_i_ + 2];
96 for (int i=1; i < pitch_arr_.size (); i++)
98 Musical_pitch p = pitch_arr_[i];
99 int trap = p.notename_i_ - tonic.notename_i_
100 + (p.octave_i_ - tonic.octave_i_) * 7 + 1;
101 int accidental = p.accidental_i_ - scale[(trap - 1) % 7].accidental_i_;
102 if ((trap == 3) && (accidental == -1))
103 tonic_str += "m"; // hmm
104 else if (accidental || (!(trap % 2) || ((i + 1 == pitch_arr_.size ()) && (trap > 5))))
107 if ((trap == 7) && (accidental == 1))
111 add_str += to_str (trap);
113 add_str += accidental < 0 ? "-" : "+";
119 text_p->text_str_ = tonic_str + "$^{" + add_str + "}$";
120 Text_item* item_p = new Text_item (text_p);
122 item_p->fat_b_ = true;
123 text_p_arr_.push (item_p);
124 announce_element (Score_element_info (item_p, 0));
128 Chord_name_engraver::do_pre_move_processing ()
130 for (int i=0; i < text_p_arr_.size (); i++)
132 typeset_element (text_p_arr_[i]);
134 text_p_arr_.clear ();