lilypond-1.5.10
[lilypond.git] / lily / note-name-engraver.cc
blobc6e0261b2c389079b4476b563886d0d7b4e22031
1 /*
2 note-name-engraver.cc -- implement Note_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "engraver.hh"
11 #include "musical-request.hh"
12 #include "item.hh"
14 class Note_name_engraver : public Engraver
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 ();
25 bool
26 Note_name_engraver::try_music (Music *m)
28 if (Note_req *r = dynamic_cast<Note_req* > (m))
30 req_l_arr_.push (r);
31 return true;
33 return false;
36 void
37 Note_name_engraver::create_grobs ()
39 if (texts_.size ())
40 return;
41 String s ;
42 for (int i=0; i < req_l_arr_.size (); i++)
44 if (i)
45 s += " ";
46 s += unsmob_pitch (req_l_arr_[i]->get_mus_property ("pitch"))->str ();
48 if (s.length_i ())
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);
57 void
58 Note_name_engraver::stop_translation_timestep ()
60 for (int i=0; i < texts_.size (); i++)
62 typeset_grob (texts_[i]);
64 texts_.clear () ;
65 req_l_arr_.clear ();
68 ADD_THIS_TRANSLATOR (Note_name_engraver);