]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
* lily/include/translator.icc: new file.
[lilypond.git] / lily / rest-engraver.cc
1 /*
2   rest-engraver.cc -- implement Rest_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "engraver.hh"
10
11 #include "duration.hh"
12 #include "item.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "dots.hh"
15 #include "rhythmic-head.hh"
16 #include "music.hh"
17
18
19 class Rest_engraver : public Engraver
20 {
21   Music *rest_req_;
22   Item *dot_;
23   Grob *rest_;
24 protected:
25   virtual bool try_music (Music *);
26   PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
27   PRECOMPUTED_VIRTUAL void start_translation_timestep ();
28   PRECOMPUTED_VIRTUAL void process_music ();
29
30 public:
31   TRANSLATOR_DECLARATIONS (Rest_engraver);
32 };
33
34 /*
35   Should merge with Note_head_engraver
36 */
37 Rest_engraver::Rest_engraver ()
38 {
39   rest_req_ = 0;
40   rest_ = 0;
41   dot_ = 0;
42 }
43
44 void
45 Rest_engraver::start_translation_timestep ()
46 {
47   rest_req_ = 0;
48 }
49
50 void
51 Rest_engraver::stop_translation_timestep ()
52 {
53   rest_ = 0;
54   dot_ = 0;
55 }
56
57 void
58 Rest_engraver::process_music ()
59 {
60   if (rest_req_ && !rest_)
61     {
62       rest_ = make_item ("Rest", rest_req_->self_scm ());
63
64       int durlog = unsmob_duration (rest_req_->get_property ("duration"))->duration_log ();
65
66       rest_->set_property ("duration-log",
67                            scm_int2num (durlog));
68
69       int dots = unsmob_duration (rest_req_->get_property ("duration"))->dot_count ();
70
71       if (dots)
72         {
73           dot_ = make_item ("Dots", SCM_EOL);
74
75           Rhythmic_head::set_dots (rest_, dot_);
76           dot_->set_parent (rest_, Y_AXIS);
77           dot_->set_property ("dot-count", scm_int2num (dots));
78         }
79
80       Pitch *p = unsmob_pitch (rest_req_->get_property ("pitch"));
81
82       /*
83         This is ridiculous -- rests don't have pitch, but we act as if
84         our nose is bleeding.
85       */
86       if (p)
87         {
88           int pos = p->steps ();
89           SCM c0 = get_property ("middleCPosition");
90           if (scm_is_number (c0))
91             pos += scm_to_int (c0);
92
93           rest_->set_property ("staff-position", scm_int2num (pos));
94         }
95     }
96 }
97
98 bool
99 Rest_engraver::try_music (Music *m)
100 {
101   if (m->is_mus_type ("rest-event"))
102     {
103       rest_req_ = m;
104       return true;
105     }
106   return false;
107 }
108
109 #include "translator.icc"
110
111 ADD_TRANSLATOR (Rest_engraver,
112                 /* descr */ "",
113                 /* creats*/ "Rest Dots",
114                 /* accepts */ "rest-event",
115                 /* acks  */ "",
116                 /* reads */ "middleCPosition",
117                 /* write */ "");