]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-name-engraver.cc
patch::: 1.1.26.jcn4: koord vixen
[lilypond.git] / lily / chord-name-engraver.cc
1 /*
2   chord-name-engraver.cc -- implement Chord_name_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
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"
18
19 ADD_THIS_TRANSLATOR (Chord_name_engraver);
20
21 Chord_name_engraver::Chord_name_engraver ()
22 {
23 }
24
25 void
26 Chord_name_engraver::acknowledge_element (Score_element_info i)
27 {
28   if (Note_req* n = dynamic_cast<Note_req*> (i.req_l_))
29     pitch_arr_.push (n->pitch_);
30 }
31
32 bool
33 Chord_name_engraver::do_try_music (Music* m)
34 {
35   if (Note_req* n = dynamic_cast<Note_req*> (m))
36     {
37       pitch_arr_.push (n->pitch_);
38       return true;
39     }
40   return false;
41 }
42
43 void
44 Chord_name_engraver::do_process_requests ()
45 {
46   if (text_p_arr_.size ())
47     return;
48   if (!pitch_arr_.size ())
49     return;
50
51   /*
52    Banter style chord names (almost).
53    TODO:
54      - move this stuff to new Item class Chord_name
55      - switch on property, add american (?) chordNameStyle
56
57   Scalar chordNameStyle = get_property ("chordNameStyle", 0);
58   if (chordNameStyle == "Banter")
59      chord = pitches_to_banter (pitch_arr_));
60
61    */
62
63   Chord chord (pitch_arr_);
64   Musical_pitch* inversion = 0;
65   Scalar chord_inversion = get_property ("chordInversion", 0);
66   if (chord_inversion.to_bool ())
67     {
68       int tonic_i = chord.find_tonic_i ();
69       if (tonic_i)
70         {
71           inversion = &pitch_arr_[0];
72           Scalar preserve = get_property ("chordInversionPreserve", 0);
73           if (preserve.to_bool ())
74             chord.rebuild_from_base (tonic_i);
75           else
76             chord.rebuild_insert_inversion (tonic_i);
77         }
78     }
79     
80   G_text_item* item_p =  new G_text_item;
81
82   item_p->text_str_ = chord.banter_str (inversion);
83   
84   Scalar style = get_property ("textstyle", 0);
85   if (style.length_i ())
86     item_p->style_str_ = style;
87   
88   text_p_arr_.push (item_p);
89   announce_element (Score_element_info (item_p, 0));
90 }
91
92 void
93 Chord_name_engraver::do_pre_move_processing ()
94 {
95   for (int i=0; i < text_p_arr_.size (); i++)
96     {
97       typeset_element (text_p_arr_[i]);
98     }
99   text_p_arr_.clear ();
100   pitch_arr_.clear ();
101 }