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