]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-name-engraver.cc
*** empty log message ***
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "item.hh"
12
13 class Note_name_engraver : public Engraver
14 {
15 public:
16   TRANSLATOR_DECLARATIONS (Note_name_engraver);
17
18   Link_array<Music> events_;
19   Link_array<Item> texts_;
20   virtual bool  try_music (Music*m);
21   virtual void process_music ();
22   virtual void stop_translation_timestep ();
23 };
24
25 bool
26 Note_name_engraver::try_music (Music *m)
27 {
28   if (m->is_mus_type ("note-event"))
29     {
30       events_.push (m);
31       return true;
32     }
33   return false;
34 }
35
36 void
37 Note_name_engraver::process_music ()
38 {
39   String s ;
40   for (int i = 0; i < events_.size (); i++)
41     {
42       if (i)
43         s += " ";
44       Pitch p = *unsmob_pitch (events_[i]->get_property ("pitch"));
45
46       if (!to_boolean (get_property ("printOctaveNames")))
47           p = Pitch (-1, p.get_notename (), p.get_alteration ());
48           
49       s += p.to_string ();
50     }
51   if (s.length ())
52     {
53       Item * t = make_item ("NoteName", events_[0]->self_scm () );
54       t->set_property ("text", scm_makfrom0str (s.to_str0 ()));
55       texts_.push (t);
56     }
57 }
58
59 void
60 Note_name_engraver::stop_translation_timestep ()
61 {
62   texts_.clear () ;
63   events_.clear ();
64 }
65
66
67 Note_name_engraver::Note_name_engraver ()
68 {
69 }
70
71 ENTER_DESCRIPTION (Note_name_engraver,
72 /* descr */       "",
73 /* creats*/       "NoteName",
74 /* accepts */     "note-event",
75 /* acks  */      "",
76 /* reads */       "printOctaveNames",
77 /* write */       "");