]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
* flower
[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
77       Pitch *p = unsmob_pitch (rest_req_->get_property ("pitch"));
78
79       /*
80         This is ridiculous -- rests don't have pitch, but we act as if
81         our nose is bleeding.
82       */
83       if (p)
84         {
85           int pos = p->steps ();
86           SCM c0 = get_property ("middleCPosition");
87           if (scm_is_number (c0))
88             pos += scm_to_int (c0);
89
90           rest_->set_property ("staff-position", scm_int2num (pos));
91         }
92
93     }
94 }
95
96 bool
97 Rest_engraver::try_music (Music *m)
98 {
99   if (m->is_mus_type ("rest-event"))
100     {
101       rest_req_ = m;
102       return true;
103     }
104   return false;
105 }
106
107 ADD_TRANSLATOR (Rest_engraver,
108                 /* descr */ "",
109                 /* creats*/ "Rest Dots",
110                 /* accepts */ "rest-event",
111                 /* acks  */ "",
112                 /* reads */ "middleCPosition",
113                 /* write */ "");