]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-name-engraver.cc
release: 1.3.3
[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.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   tonic_req_ = 0;
24   inversion_req_ = 0;
25   bass_req_ = 0;
26 }
27
28 void
29 Chord_name_engraver::acknowledge_element (Score_element_info i)
30 {
31   if (Note_req* n = dynamic_cast<Note_req*> (i.req_l_))
32     pitch_arr_.push (n->pitch_);
33 }
34
35 bool
36 Chord_name_engraver::do_try_music (Music* m)
37 {
38   if (Note_req* n = dynamic_cast<Note_req*> (m))
39     {
40       pitch_arr_.push (n->pitch_);
41       return true;
42     }
43   if (Tonic_req* t = dynamic_cast<Tonic_req*> (m))
44     {
45       tonic_req_ = t;
46       return true;
47     }
48   if (Inversion_req* i = dynamic_cast<Inversion_req*> (m))
49     {
50       inversion_req_ = i;
51       return true;
52     }
53   if (Bass_req* b = dynamic_cast<Bass_req*> (m))
54     {
55       bass_req_ = b;
56       return true;
57     }
58   return false;
59 }
60
61 void
62 Chord_name_engraver::do_process_requests ()
63 {
64   if (text_p_arr_.size ())
65     return;
66   if (!pitch_arr_.size ())
67     return;
68
69   bool find_inversion_b = false;
70   SCM chord_inversion = get_property ("chordInversion", 0);
71   if (gh_boolean_p (chord_inversion))
72     find_inversion_b = gh_scm2bool (chord_inversion);
73
74   Chord chord = to_chord (pitch_arr_, tonic_req_, inversion_req_, bass_req_, 
75     find_inversion_b);
76     
77   Text_item* item_p =  new Text_item;
78
79   /*
80    TODO:
81      - switch on property, add american (?) chordNameStyle:
82        Chord::american_str (...)
83
84   SCM chordNameStyle = get_property ("chordNameStyle", 0);
85   if (chordNameStyle == "Banter")
86     item_p->text_str_ = chord.banter_str (inversion);
87    */
88
89   item_p->text_str_ = chord.banter_str ();
90   
91   text_p_arr_.push (item_p);
92   announce_element (Score_element_info (item_p, 0));
93 }
94
95 void
96 Chord_name_engraver::do_pre_move_processing ()
97 {
98   for (int i=0; i < text_p_arr_.size (); i++)
99     {
100       typeset_element (text_p_arr_[i]);
101     }
102   text_p_arr_.clear ();
103   pitch_arr_.clear ();
104   tonic_req_ = 0;
105   inversion_req_ = 0;
106   bass_req_ = 0;
107 }
108