]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
* lily/coherent-ligature-engraver.cc: fixed typo
[lilypond.git] / lily / note-heads-engraver.cc
1 /*
2   head-grav.cc -- part of GNU LilyPond
3
4   (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
6 #include <ctype.h>
7
8 #include "rhythmic-head.hh"
9 #include "paper-def.hh"
10 #include "event.hh"
11 #include "dots.hh"
12 #include "dot-column.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "item.hh"
15 #include "engraver.hh"
16 #include "warn.hh"
17
18 /**
19   make balls and rests
20  */
21
22 class Note_heads_engraver : public Engraver
23 {
24   Link_array<Item> notes_;
25   
26   Link_array<Item> dots_;
27   Link_array<Music> note_reqs_;
28
29 public:
30   TRANSLATOR_DECLARATIONS(Note_heads_engraver);
31
32 protected:
33   virtual void start_translation_timestep ();
34   virtual bool try_music (Music *req) ;
35   virtual void process_music ();
36
37   virtual void stop_translation_timestep ();
38 };
39
40 Note_heads_engraver::Note_heads_engraver()
41 {
42 }
43
44 bool
45 Note_heads_engraver::try_music (Music *m) 
46 {
47   if (m->is_mus_type ("note-event"))
48     {
49       note_reqs_.push (m);
50       return true;
51     }
52   else if (m->is_mus_type ("busy-playing-event"))
53     return note_reqs_.size ();
54   
55   return false;
56 }
57
58
59 void
60 Note_heads_engraver::process_music ()
61 {
62   for (int i=0; i < note_reqs_.size (); i++)
63     {
64       Item *note = new Item (get_property ("NoteHead"));
65
66       Music * req = note_reqs_[i];
67       
68       Duration dur = *unsmob_duration (req->get_mus_property ("duration"));
69
70       note->set_grob_property ("duration-log", gh_int2scm (dur.duration_log ()));
71
72       if (dur.dot_count ())
73         {
74           Item * d = new Item (get_property ("Dots"));
75           Rhythmic_head::set_dots (note, d);
76           
77           if (dur.dot_count ()
78               != gh_scm2int (d->get_grob_property ("dot-count")))
79             d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
80
81           d->set_parent (note, Y_AXIS);
82           announce_grob (d, SCM_EOL);
83           dots_.push (d);
84         }
85
86       Pitch *pit =unsmob_pitch (req->get_mus_property ("pitch"));
87
88       int pos = pit->steps ();
89       SCM c0 = get_property ("centralCPosition");
90       if (gh_number_p (c0))
91         pos += gh_scm2int (c0);
92
93       note->set_grob_property ("staff-position",   gh_int2scm (pos));
94       announce_grob (note,req->self_scm());
95       notes_.push (note);
96     }
97 }
98
99 void
100 Note_heads_engraver::stop_translation_timestep ()
101 {
102   for (int i=0; i < notes_.size (); i++)
103     {
104       typeset_grob (notes_[i]);
105     }
106
107   notes_.clear ();
108   for (int i=0; i < dots_.size (); i++)
109     {
110       typeset_grob (dots_[i]);
111     }
112   dots_.clear ();
113   note_reqs_.clear ();
114 }
115
116 void
117 Note_heads_engraver::start_translation_timestep ()
118 {
119 }
120
121
122 ENTER_DESCRIPTION(Note_heads_engraver,
123 /* descr */       "Generate noteheads.",
124 /* creats*/       "NoteHead Dots",
125 /* accepts */     "note-event busy-playing-event ligature-event abort-event",
126 /* acks  */      "",
127 /* reads */       "centralCPosition",
128 /* write */       "");