2 head-grav.cc -- part of GNU LilyPond
4 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "rhythmic-head.hh"
9 #include "paper-def.hh"
10 #include "musical-request.hh"
12 #include "dot-column.hh"
13 #include "staff-symbol-referencer.hh"
15 #include "score-engraver.hh"
21 class Note_heads_engraver : public Engraver
23 Link_array<Item> note_p_arr_;
24 Link_array<Item> dot_p_arr_;
25 Link_array<Note_req> note_req_l_arr_;
28 VIRTUAL_COPY_CONS (Translator);
31 virtual void start_translation_timestep ();
32 virtual bool try_music (Music *req_l) ;
33 virtual void create_grobs ();
34 virtual void acknowledge_grob (Grob_info) ;
35 virtual void stop_translation_timestep ();
39 Note_heads_engraver::try_music (Music *m)
41 if (Note_req * n =dynamic_cast <Note_req *> (m))
43 note_req_l_arr_.push (n);
44 note_end_mom_ = note_end_mom_ >? now_mom () + m->length_mom ();
48 else if (dynamic_cast<Busy_playing_req*> (m))
50 return now_mom () < note_end_mom_;
57 Note_heads_engraver::acknowledge_grob (Grob_info)
63 Note_heads_engraver::create_grobs ()
65 if (note_p_arr_.size ())
68 for (int i=0; i < note_req_l_arr_.size (); i++)
70 Item *note_p = new Item (get_property ("NoteHead"));
72 Staff_symbol_referencer::set_interface (note_p);
76 Music * req = note_req_l_arr_[i];
78 Duration dur = *unsmob_duration (req->get_mus_property ("duration"));
79 note_p->set_grob_property ("duration-log",
80 gh_int2scm (dur.duration_log () <? 2));
84 Item * d = new Item (get_property ("Dots"));
85 Rhythmic_head::set_dots (note_p, d);
88 != gh_scm2int (d->get_grob_property ("dot-count")))
89 d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
91 d->set_parent (note_p, Y_AXIS);
96 Pitch *pit =unsmob_pitch (req->get_mus_property ("pitch"));
97 note_p->set_grob_property ("staff-position", gh_int2scm (pit->steps ()));
99 if (to_boolean (get_property ("easyPlay")))
102 s[0] = (pit->notename_i_ + 2)%7 + 'a';
104 s[0] = toupper (s[0]);
105 note_p->set_grob_property ("note-character", ly_str02scm (s));
108 announce_grob (note_p,req);
109 note_p_arr_.push (note_p);
114 Note_heads_engraver::stop_translation_timestep ()
116 for (int i=0; i < note_p_arr_.size (); i++)
118 typeset_grob (note_p_arr_[i]);
120 note_p_arr_.clear ();
121 for (int i=0; i < dot_p_arr_.size (); i++)
123 typeset_grob (dot_p_arr_[i]);
127 note_req_l_arr_.clear ();
131 Note_heads_engraver::start_translation_timestep ()
134 /* TODO:make this settable?
136 if (note_end_mom_ > now_mom ())
138 Score_engraver * e = 0;
139 Translator * t = daddy_grav_l ();
140 for (; !e && t; t = t->daddy_trans_l_)
142 e = dynamic_cast<Score_engraver*> (t);
146 programming_error ("No score engraver!");
148 e->forbid_breaks (); // guh. Use properties!
156 ADD_THIS_TRANSLATOR (Note_heads_engraver);