]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
(DECLARE_EVENT_SWALLOWER): ENTER_DESCRIPTION -> ADD_TRANSLATOR
[lilypond.git] / lily / rest-engraver.cc
1 /*
2   rest-grav.cc -- implement Rest_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 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 /*
32   Should merge with Note_head_engraver
33  */
34 Rest_engraver::Rest_engraver ()
35 {
36   rest_req_ = 0;
37   rest_ = 0;
38   dot_ = 0;
39 }
40
41 void
42 Rest_engraver::start_translation_timestep ()
43 {
44   rest_req_ = 0;
45 }
46
47 void
48 Rest_engraver::stop_translation_timestep ()
49 {
50   rest_ = 0;
51   dot_ = 0;
52 }
53
54 void
55 Rest_engraver::process_music ()
56 {
57   if (rest_req_ && !rest_) 
58     {
59       rest_ = make_item ("Rest", rest_req_->self_scm ());
60
61       int durlog  = unsmob_duration (rest_req_->get_property ("duration"))-> duration_log ();
62       
63       rest_->set_property ("duration-log",
64                                   scm_int2num (durlog));
65
66       int dots = unsmob_duration (rest_req_->get_property ("duration"))->dot_count ();
67       
68       if (dots)
69         {
70           dot_ = make_item ("Dots", SCM_EOL);
71
72           Rhythmic_head::set_dots (rest_, dot_);
73           dot_->set_parent (rest_, Y_AXIS);
74           dot_->set_property ("dot-count", scm_int2num (dots));
75           
76         }
77
78       Pitch *p = unsmob_pitch (rest_req_->get_property ("pitch"));
79
80       /*
81         This is ridiculous -- rests don't have pitch, but we act as if
82         our nose is bleeding.
83        */
84       if (p)
85         {
86           int pos = p->steps ();
87           SCM c0 = get_property ("middleCPosition");
88           if (scm_is_number (c0))
89             pos += scm_to_int (c0);
90           
91           rest_->set_property ("staff-position", scm_int2num (pos));
92         }
93       
94     }
95 }
96
97 bool
98 Rest_engraver::try_music (Music *m)
99 {
100   if (m->is_mus_type ("rest-event"))
101     {
102       rest_req_ = m;
103       return true;
104     }
105   return false;
106 }
107
108 ADD_TRANSLATOR (Rest_engraver,
109 /* descr */       "",
110 /* creats*/       "Rest Dots",
111 /* accepts */     "rest-event",
112 /* acks  */      "",
113 /* reads */       "middleCPosition",
114 /* write */       "");