]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
*** empty log message ***
[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 #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"
14
15
16 class Rest_engraver : public Engraver
17 {
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 ();
26
27 public:
28   TRANSLATOR_DECLARATIONS (Rest_engraver);
29 };
30
31
32 /*
33   Should merge with Note_head_engraver
34  */
35 Rest_engraver::Rest_engraver ()
36 {
37   rest_req_ =0;
38   rest_ =0;
39   dot_ =0;
40 }
41
42 void
43 Rest_engraver::start_translation_timestep ()
44 {
45   rest_req_ =0;
46 }
47
48 void
49 Rest_engraver::stop_translation_timestep ()
50 {
51   rest_ =0;
52   dot_ =0;
53 }
54
55 void
56 Rest_engraver::process_music ()
57 {
58   if (rest_req_ && !rest_) 
59     {
60       rest_ = make_item ("Rest", rest_req_->self_scm ());
61
62       int durlog  = unsmob_duration (rest_req_->get_property ("duration"))-> duration_log ();
63       
64       rest_->set_property ("duration-log",
65                                   scm_int2num (durlog));
66
67       int dots =unsmob_duration (rest_req_->get_property ("duration"))->dot_count ();
68       
69       if (dots)
70         {
71           dot_ = make_item ("Dots", SCM_EOL);
72
73           Rhythmic_head::set_dots (rest_, dot_);
74           dot_->set_parent (rest_, Y_AXIS);
75           dot_->set_property ("dot-count", scm_int2num (dots));
76           
77         }
78
79       Pitch *p = unsmob_pitch (rest_req_->get_property ("pitch"));
80
81       /*
82         This is ridiculous -- rests don't have pitch, but we act as if
83         our nose is bleeding.
84        */
85       if (p)
86         {
87           int pos= p->steps ();
88           SCM c0 = get_property ("middleCPosition");
89           if (ly_c_number_p (c0))
90             pos += scm_to_int (c0);
91           
92           rest_->set_property ("staff-position", scm_int2num (pos));
93         }
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 ENTER_DESCRIPTION (Rest_engraver,
110 /* descr */       "",
111 /* creats*/       "Rest Dots",
112 /* accepts */     "rest-event",
113 /* acks  */      "",
114 /* reads */       "middleCPosition",
115 /* write */       "");