]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-heads-engraver.cc
* lily/engraver.cc (internal_make_item): centralize item/spanner
[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 bool try_music (Music *req) ;
34   virtual void process_music ();
35
36   virtual void stop_translation_timestep ();
37 };
38
39 Note_heads_engraver::Note_heads_engraver()
40 {
41 }
42
43 bool
44 Note_heads_engraver::try_music (Music *m) 
45 {
46   if (m->is_mus_type ("note-event"))
47     {
48       note_reqs_.push (m);
49       return true;
50     }
51   else if (m->is_mus_type ("busy-playing-event"))
52     return note_reqs_.size ();
53   else if (m->is_mus_type ("start-playing-event"))
54     return note_reqs_.size ();
55   
56   return false;
57 }
58
59
60 void
61 Note_heads_engraver::process_music ()
62 {
63   for (int i=0; i < note_reqs_.size (); i++)
64     {
65       Item *note = make_item ("NoteHead");
66
67       Music * req = note_reqs_[i];
68       
69       Duration dur = *unsmob_duration (req->get_mus_property ("duration"));
70
71       note->set_grob_property ("duration-log", gh_int2scm (dur.duration_log ()));
72
73       if (dur.dot_count ())
74         {
75           Item * d = make_item ("Dots");
76           Rhythmic_head::set_dots (note, d);
77           
78           if (dur.dot_count ()
79               != gh_scm2int (d->get_grob_property ("dot-count")))
80             d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
81
82           d->set_parent (note, Y_AXIS);
83           announce_grob (d, SCM_EOL);
84           dots_.push (d);
85         }
86
87       Pitch *pit =unsmob_pitch (req->get_mus_property ("pitch"));
88
89       int pos = pit->steps ();
90       SCM c0 = get_property ("centralCPosition");
91       if (gh_number_p (c0))
92         pos += gh_scm2int (c0);
93
94       note->set_grob_property ("staff-position",   gh_int2scm (pos));
95       announce_grob (note,req->self_scm());
96       notes_.push (note);
97     }
98 }
99
100 void
101 Note_heads_engraver::stop_translation_timestep ()
102 {
103   for (int i=0; i < notes_.size (); i++)
104     {
105       typeset_grob (notes_[i]);
106     }
107
108   notes_.clear ();
109   for (int i=0; i < dots_.size (); i++)
110     {
111       typeset_grob (dots_[i]);
112     }
113   dots_.clear ();
114   note_reqs_.clear ();
115 }
116
117
118
119 ENTER_DESCRIPTION(Note_heads_engraver,
120 /* descr */       "Generate noteheads.",
121 /* creats*/       "NoteHead Dots",
122 /* accepts */     "note-event busy-playing-event ligature-event abort-event",
123 /* acks  */      "",
124 /* reads */       "centralCPosition",
125 /* write */       "");