]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-name-engraver.cc
release: 1.3.131
[lilypond.git] / lily / note-name-engraver.cc
1 /*   
2   note-name-engraver.cc --  implement Note_name_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "musical-request.hh"
12 #include "item.hh"
13
14 class Note_name_engraver : public Engraver
15 {
16 public:
17   VIRTUAL_COPY_CONS(Translator);
18   Link_array<Note_req> req_l_arr_;
19   Link_array<Item> texts_;
20   virtual bool  try_music (Music*m);
21   virtual void create_grobs ();
22   virtual void stop_translation_timestep ();
23 };
24
25 bool
26 Note_name_engraver::try_music (Music *m)
27 {
28   if (Note_req *r = dynamic_cast<Note_req* > (m))
29     {
30       req_l_arr_.push (r);
31       return true;
32     }
33   return false;
34 }
35
36 void
37 Note_name_engraver::create_grobs ()
38 {
39   if (texts_.size ())
40     return;
41   String s ;
42   for (int i=0; i < req_l_arr_.size (); i++)
43     {
44       if (i)
45         s += " ";
46       s += unsmob_pitch (req_l_arr_[i]->get_mus_property ("pitch"))->str ();
47     }
48   if (s.length_i())
49     {
50       Item * t = new Item (get_property ("NoteName"));
51       t->set_grob_property ("text", ly_str02scm ( s.ch_C()));
52       announce_grob (t, req_l_arr_[0]);
53       texts_.push (t);
54     }
55 }
56
57 void
58 Note_name_engraver::stop_translation_timestep ()
59 {
60   for (int i=0; i < texts_.size (); i++)
61     {
62       typeset_grob (texts_[i]);
63     }
64   texts_.clear() ;
65   req_l_arr_.clear ();
66 }
67
68 ADD_THIS_TRANSLATOR(Note_name_engraver);