]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
release: 1.5.34
[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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "item.hh"
9 #include "staff-symbol-referencer.hh"
10 #include "musical-request.hh"
11 #include "dots.hh"
12 #include "rhythmic-head.hh"
13 #include "engraver.hh"
14
15
16 class Rest_engraver : public Engraver
17 {
18   Rest_req *rest_req_l_;
19   Item * dot_p_;
20   Grob* rest_p_;
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_l_ =0;
38   rest_p_ =0;
39   dot_p_ =0;
40 }
41
42 void
43 Rest_engraver::start_translation_timestep ()
44 {
45   rest_req_l_ =0;
46 }
47
48 void
49 Rest_engraver::stop_translation_timestep ()
50 {
51   if (rest_p_)
52     {
53       typeset_grob (rest_p_);
54       rest_p_ =0;
55     }
56   if (dot_p_)
57     {
58       typeset_grob (dot_p_);
59       dot_p_ =0;
60     }    
61 }
62
63 void
64 Rest_engraver::process_music ()
65 {
66   if (rest_req_l_ && !rest_p_) 
67     {
68       rest_p_ = new Item (get_property ("Rest"));
69       Rhythmic_head::set_interface (rest_p_);
70
71       
72       int durlog  = unsmob_duration (rest_req_l_->get_mus_property ("duration"))-> duration_log ();
73       
74       rest_p_->set_grob_property ("duration-log",
75                                   gh_int2scm (durlog));
76
77       int dots =unsmob_duration (rest_req_l_->get_mus_property ("duration"))->dot_count ();
78       
79       if (dots)
80         {
81           dot_p_ = new Item (get_property ("Dots"));
82
83           Rhythmic_head::set_dots (rest_p_, dot_p_);
84           dot_p_->set_parent (rest_p_, Y_AXIS);
85           dot_p_->set_grob_property ("dot-count", gh_int2scm (dots));
86           announce_grob (dot_p_, SCM_EOL);
87         }
88
89       Pitch *p = unsmob_pitch (rest_req_l_->get_mus_property ("pitch"));
90
91       /*
92         This is ridiculous -- rests don't have pitch, but we act as if
93         our nose is bleeding.
94        */
95       if (p)
96         {
97           int pos= p->steps ();
98           SCM c0 = get_property ("centralCPosition");
99           if (gh_number_p (c0))
100             pos += gh_scm2int (c0);
101           
102           rest_p_->set_grob_property ("staff-position", gh_int2scm (pos));
103         }
104       
105       announce_grob(rest_p_, rest_req_l_->self_scm());
106     }
107 }
108
109 bool
110 Rest_engraver::try_music (Music *m)
111 {
112   if (Rest_req *r = dynamic_cast <Rest_req *> (m))
113     {
114       rest_req_l_ = r;
115       return true;
116     }  
117   return false;
118 }
119
120
121
122 ENTER_DESCRIPTION(Rest_engraver,
123 /* descr */       "",
124 /* creats*/       "Rest Dots",
125 /* acks  */       "",
126 /* reads */       "centralCPosition",
127 /* write */       "");