]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-name-engraver.cc
patch::: 1.3.15.jcn1
[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--1999 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 "text-item.hh"
18
19 ADD_THIS_TRANSLATOR (Chord_name_engraver);
20
21 Chord_name_engraver::Chord_name_engraver ()
22 {
23   chord_name_p_ = 0;
24   tonic_req_ = 0;
25   inversion_req_ = 0;
26   bass_req_ = 0;
27 }
28
29 void
30 Chord_name_engraver::acknowledge_element (Score_element_info i)
31 {
32   if (Note_req* n = dynamic_cast<Note_req*> (i.req_l_))
33     pitch_arr_.push (n->pitch_);
34 }
35
36 bool
37 Chord_name_engraver::do_try_music (Music* m)
38 {
39   if (Note_req* n = dynamic_cast<Note_req*> (m))
40     {
41       pitch_arr_.push (n->pitch_);
42       return true;
43     }
44   if (Tonic_req* t = dynamic_cast<Tonic_req*> (m))
45     {
46       tonic_req_ = t;
47       return true;
48     }
49   if (Inversion_req* i = dynamic_cast<Inversion_req*> (m))
50     {
51       inversion_req_ = i;
52       return true;
53     }
54   if (Bass_req* b = dynamic_cast<Bass_req*> (m))
55     {
56       bass_req_ = b;
57       return true;
58     }
59   return false;
60 }
61
62 void
63 Chord_name_engraver::do_process_requests ()
64 {
65   if (chord_name_p_)
66     return;
67   if (!pitch_arr_.size ())
68     return;
69
70   bool find_inversion_b = false;
71   SCM chord_inversion = get_property ("chordInversion", 0);
72   if (gh_boolean_p (chord_inversion))
73     find_inversion_b = gh_scm2bool (chord_inversion);
74
75   chord_name_p_ = new Chord_name;
76   chord_name_p_->set (to_chord (pitch_arr_, tonic_req_, inversion_req_, bass_req_, find_inversion_b));
77     
78   announce_element (Score_element_info (chord_name_p_, 0));
79 }
80
81 void
82 Chord_name_engraver::do_pre_move_processing ()
83 {
84   if (chord_name_p_)
85     {
86       typeset_element (chord_name_p_);
87     }
88   pitch_arr_.clear ();
89   chord_name_p_ = 0;
90   tonic_req_ = 0;
91   inversion_req_ = 0;
92   bass_req_ = 0;
93 }
94