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