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