]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-name-engraver.cc
patch::: 1.1.10.jcn1: koorden
[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 "musical-request.hh"
11 #include "text-item.hh"
12 #include "paper-def.hh"
13 #include "lookup.hh"
14 #include "paper-def.hh"
15 #include "main.hh"
16 #include "dimensions.hh"
17
18 ADD_THIS_TRANSLATOR (Chord_name_engraver);
19
20 Chord_name_engraver::Chord_name_engraver ()
21 {
22 }
23
24 void
25 Chord_name_engraver::acknowledge_element (Score_element_info i)
26 {
27   if (Note_req* n = dynamic_cast<Note_req*> (i.req_l_))
28     pitch_arr_.push (n->pitch_);
29 }
30
31 bool
32 Chord_name_engraver::do_try_music (Music* m)
33 {
34   if (Note_req* n = dynamic_cast<Note_req*> (m))
35     {
36       pitch_arr_.push (n->pitch_);
37       return true;
38     }
39   return false;
40 }
41
42 void
43 Chord_name_engraver::do_process_requests ()
44 {
45   if (text_p_arr_.size ())
46     return;
47   if (!pitch_arr_.size ())
48     return;
49
50   Scalar style = get_property ("textstyle");
51   Scalar alignment = get_property ("textalignment");
52   Text_def* text_p = new Text_def;
53   text_p->align_dir_ = LEFT;
54   if (style.length_i ())
55     text_p->style_str_ = style;
56   if (alignment.isnum_b())
57     text_p->align_dir_= (Direction)(int)alignment;
58
59   Musical_pitch tonic = pitch_arr_[0];
60   text_p->text_str_ = tonic.str ();
61   for (int i=1; i < pitch_arr_.size (); i++)
62     {
63       Musical_pitch p = pitch_arr_[i];
64       int trap = (p.notename_i_ - tonic.notename_i_ + 8) % 8 + 1;
65       if (((trap != 3) && (trap != 5)) || (p.accidental_i_))
66         {
67           text_p->text_str_ += to_str ((p.notename_i_ - tonic.notename_i_ + 8) % 8 + 1);
68           if (p.accidental_i_)
69             text_p->text_str_ += p.accidental_i_ < 0 ? "-" : "+";
70           if (i + 1 < pitch_arr_.size ())
71             text_p->text_str_ += "/";
72         }
73     }
74
75   Text_item* item_p =  new Text_item (text_p);
76   item_p->dir_ = DOWN;
77   item_p->fat_b_ = true;
78   text_p_arr_.push (item_p);
79   announce_element (Score_element_info (item_p, 0));
80 }
81
82 void
83 Chord_name_engraver::do_pre_move_processing ()
84 {
85   for (int i=0; i < text_p_arr_.size (); i++)
86     {
87       typeset_element (text_p_arr_[i]);
88     }
89   text_p_arr_.clear ();
90   pitch_arr_.clear ();
91 }
92