]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-name-engraver.cc
release: 1.3.61
[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--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "chord-name-engraver.hh"
10 #include "chord-name.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 "item.hh"
18
19
20 ADD_THIS_TRANSLATOR (Chord_name_engraver);
21
22 Chord_name_engraver::Chord_name_engraver ()
23 {
24   chord_name_p_ = 0;
25   tonic_req_ = 0;
26   inversion_req_ = 0;
27   bass_req_ = 0;
28 }
29
30 void
31 Chord_name_engraver::acknowledge_element (Score_element_info i)
32 {
33   if (Note_req* n = dynamic_cast<Note_req*> (i.req_l_))
34     pitch_arr_.push (n->pitch_);
35 }
36
37 bool
38 Chord_name_engraver::do_try_music (Music* m)
39 {
40   if (Note_req* n = dynamic_cast<Note_req*> (m))
41     {
42       pitch_arr_.push (n->pitch_);
43       return true;
44     }
45   if (Tonic_req* t = dynamic_cast<Tonic_req*> (m))
46     {
47       tonic_req_ = t;
48       return true;
49     }
50   if (Inversion_req* i = dynamic_cast<Inversion_req*> (m))
51     {
52       inversion_req_ = i;
53       return true;
54     }
55   if (Bass_req* b = dynamic_cast<Bass_req*> (m))
56     {
57       bass_req_ = b;
58       return true;
59     }
60   return false;
61 }
62
63 void
64 Chord_name_engraver::do_process_music ()
65 {
66   if (chord_name_p_)
67     return;
68   if (!pitch_arr_.size ())
69     return;
70
71   bool find_inversion_b = false;
72   SCM chord_inversion = get_property ("chordInversion");
73   if (gh_boolean_p (chord_inversion))
74     find_inversion_b = gh_scm2bool (chord_inversion);
75
76   chord_name_p_ = new Chord_name (get_property ("basicChordNameProperties"));
77   Chord chord = to_chord (pitch_arr_, tonic_req_, inversion_req_, bass_req_,
78                           find_inversion_b);
79
80   /*
81     Hmm, why not represent complete chord as list?
82     ((tonic third fifth) (inversion bass))
83   */
84   SCM plist = SCM_EOL;
85   for (int i= chord.pitch_arr_.size (); i--; )
86     plist = gh_cons (chord.pitch_arr_[i].to_scm (), plist);
87   
88   chord_name_p_->set_elt_property ("pitches", plist);
89   if (chord.inversion_b_)
90     chord_name_p_->set_elt_property ("inversion",
91                                      chord.inversion_pitch_.to_scm ());
92   if (chord.bass_b_)
93     chord_name_p_->set_elt_property ("bass", chord.bass_pitch_.to_scm ());
94
95   announce_element (Score_element_info (chord_name_p_, 0));
96 }
97
98 void
99 Chord_name_engraver::do_pre_move_processing ()
100 {
101   if (chord_name_p_)
102     {
103       typeset_element (chord_name_p_);
104     }
105   pitch_arr_.clear ();
106   chord_name_p_ = 0;
107   tonic_req_ = 0;
108   inversion_req_ = 0;
109   bass_req_ = 0;
110 }
111