lilypond-1.3.145
[lilypond.git] / lily / note-heads-engraver.cc
blob87a5bff3f2d5a82fbe03c311aa907eef9b08a692
1 /*
2 head-grav.cc -- part of GNU LilyPond
4 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
6 #include <ctype.h>
8 #include "rhythmic-head.hh"
9 #include "paper-def.hh"
10 #include "musical-request.hh"
11 #include "dots.hh"
12 #include "dot-column.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "item.hh"
15 #include "score-engraver.hh"
16 #include "warn.hh"
18 /**
19 make balls and rests
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_;
26 Moment note_end_mom_;
27 public:
28 VIRTUAL_COPY_CONS (Translator);
30 protected:
31 virtual void start_translation_timestep ();
32 virtual bool try_music (Music *req_l) ;
33 virtual void process_music ();
35 virtual void stop_translation_timestep ();
38 bool
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 ();
46 return true;
48 else if (dynamic_cast<Busy_playing_req*> (m))
50 return now_mom () < note_end_mom_;
52 return false;
57 void
58 Note_heads_engraver::process_music ()
60 for (int i=0; i < note_req_l_arr_.size (); i++)
62 Item *note_p = new Item (get_property ("NoteHead"));
64 Staff_symbol_referencer::set_interface (note_p);
68 Music * req = note_req_l_arr_[i];
70 Duration dur = *unsmob_duration (req->get_mus_property ("duration"));
71 note_p->set_grob_property ("duration-log",
72 gh_int2scm (dur.duration_log () <? 2));
74 if (dur.dot_count ())
76 Item * d = new Item (get_property ("Dots"));
77 Rhythmic_head::set_dots (note_p, d);
79 if (dur.dot_count ()
80 != gh_scm2int (d->get_grob_property ("dot-count")))
81 d->set_grob_property ("dot-count", gh_int2scm (dur.dot_count ()));
83 d->set_parent (note_p, Y_AXIS);
84 announce_grob (d,0);
85 dot_p_arr_.push (d);
88 Pitch *pit =unsmob_pitch (req->get_mus_property ("pitch"));
90 int pos = pit->steps ();
91 SCM c0 = get_property ("centralCPosition");
92 if (gh_number_p (c0))
93 pos += gh_scm2int (c0);
95 note_p->set_grob_property ("staff-position", gh_int2scm (pos));
96 if (to_boolean (get_property ("easyPlay")))
98 char s[2] = "a";
99 s[0] = (pit->notename_i_ + 2)%7 + 'a';
101 s[0] = toupper (s[0]);
102 note_p->set_grob_property ("note-character", ly_str02scm (s));
105 announce_grob (note_p,req);
106 note_p_arr_.push (note_p);
110 void
111 Note_heads_engraver::stop_translation_timestep ()
113 for (int i=0; i < note_p_arr_.size (); i++)
115 typeset_grob (note_p_arr_[i]);
117 note_p_arr_.clear ();
118 for (int i=0; i < dot_p_arr_.size (); i++)
120 typeset_grob (dot_p_arr_[i]);
122 dot_p_arr_.clear ();
124 note_req_l_arr_.clear ();
127 void
128 Note_heads_engraver::start_translation_timestep ()
131 /* TODO:make this settable?
133 if (note_end_mom_ > now_mom ())
135 Score_engraver * e = 0;
136 Translator * t = daddy_grav_l ();
137 for (; !e && t; t = t->daddy_trans_l_)
139 e = dynamic_cast<Score_engraver*> (t);
142 if (!e)
143 programming_error ("No score engraver!");
144 else
145 e->forbid_breaks (); // guh. Use properties!
151 ADD_THIS_TRANSLATOR (Note_heads_engraver);