release commit
[lilypond.git] / lily / rest-engraver.cc
blob169664db574d730eb92b09eea58c2005940f62de
1 /*
2 rest-grav.cc -- implement Rest_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "item.hh"
9 #include "staff-symbol-referencer.hh"
10 #include "event.hh"
11 #include "dots.hh"
12 #include "rhythmic-head.hh"
13 #include "engraver.hh"
16 class Rest_engraver : public Engraver
18 Music *rest_req_;
19 Item * dot_;
20 Grob* rest_;
21 protected:
22 virtual bool try_music (Music *);
23 virtual void stop_translation_timestep ();
24 virtual void start_translation_timestep ();
25 virtual void process_music ();
27 public:
28 TRANSLATOR_DECLARATIONS(Rest_engraver);
33 Should merge with Note_head_engraver
35 Rest_engraver::Rest_engraver ()
37 rest_req_ =0;
38 rest_ =0;
39 dot_ =0;
42 void
43 Rest_engraver::start_translation_timestep ()
45 rest_req_ =0;
48 void
49 Rest_engraver::stop_translation_timestep ()
51 if (rest_)
53 typeset_grob (rest_);
54 rest_ =0;
56 if (dot_)
58 typeset_grob (dot_);
59 dot_ =0;
63 void
64 Rest_engraver::process_music ()
66 if (rest_req_ && !rest_)
68 rest_ = new Item (get_property ("Rest"));
70 int durlog = unsmob_duration (rest_req_->get_mus_property ("duration"))-> duration_log ();
72 rest_->set_grob_property ("duration-log",
73 gh_int2scm (durlog));
75 int dots =unsmob_duration (rest_req_->get_mus_property ("duration"))->dot_count ();
77 if (dots)
79 dot_ = new Item (get_property ("Dots"));
81 Rhythmic_head::set_dots (rest_, dot_);
82 dot_->set_parent (rest_, Y_AXIS);
83 dot_->set_grob_property ("dot-count", gh_int2scm (dots));
84 announce_grob (dot_, SCM_EOL);
87 Pitch *p = unsmob_pitch (rest_req_->get_mus_property ("pitch"));
90 This is ridiculous -- rests don't have pitch, but we act as if
91 our nose is bleeding.
93 if (p)
95 int pos= p->steps ();
96 SCM c0 = get_property ("centralCPosition");
97 if (gh_number_p (c0))
98 pos += gh_scm2int (c0);
100 rest_->set_grob_property ("staff-position", gh_int2scm (pos));
103 announce_grob(rest_, rest_req_->self_scm());
107 bool
108 Rest_engraver::try_music (Music *m)
110 if (m->is_mus_type ("rest-event"))
112 rest_req_ = m;
113 return true;
115 return false;
118 ENTER_DESCRIPTION(Rest_engraver,
119 /* descr */ "",
120 /* creats*/ "Rest Dots",
121 /* accepts */ "rest-event",
122 /* acks */ "",
123 /* reads */ "centralCPosition",
124 /* write */ "");