]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
release: 1.3.68
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "staff-symbol-referencer.hh"
9 #include "musical-request.hh"
10 #include "dots.hh"
11 #include "rhythmic-head.hh"
12 #include "engraver.hh"
13
14 class Rest_engraver : public Engraver
15 {
16   Rest_req *rest_req_l_;
17   Item * dot_p_;
18   Rhythmic_head * rest_p_;
19 protected:
20   virtual bool do_try_music (Music *);
21   virtual void do_pre_move_processing ();
22   virtual void do_post_move_processing ();
23   virtual void do_process_music ();
24 public:
25   
26   VIRTUAL_COPY_CONS(Translator);
27   Rest_engraver ();
28 };
29
30
31 /*
32   Should merge with Note_head_engraver
33  */
34 Rest_engraver::Rest_engraver ()
35 {
36   rest_req_l_ =0;
37   rest_p_ =0;
38   dot_p_ =0;
39 }
40
41 void
42 Rest_engraver::do_post_move_processing ()
43 {
44   rest_req_l_ =0;
45 }
46
47 void
48 Rest_engraver::do_pre_move_processing ()
49 {
50   if (rest_p_)
51     {
52       typeset_element (rest_p_);
53       rest_p_ =0;
54     }
55   if (dot_p_)
56     {
57       typeset_element (dot_p_);
58       dot_p_ =0;
59     }    
60 }
61
62 void
63 Rest_engraver::do_process_music ()
64 {
65   if (rest_req_l_ && !rest_p_) 
66     {
67       rest_p_ = new Rhythmic_head (get_property ("basicRestProperties"));
68       Staff_symbol_referencer_interface::set_interface (rest_p_);
69
70       
71       rest_p_->set_elt_property ("duration-log",
72                                  gh_int2scm (rest_req_l_->duration_.durlog_i_)); 
73       
74       if (rest_req_l_->duration_.dots_i_)
75         {
76           dot_p_ = new Item (get_property ("basicDotsProperties"));
77
78           Staff_symbol_referencer_interface::set_interface (dot_p_);
79
80           
81           rest_p_->set_dots (dot_p_);
82           dot_p_->set_parent (rest_p_, Y_AXIS);
83           dot_p_->add_offset_callback (Dots::quantised_position_callback, Y_AXIS);
84           dot_p_->set_elt_property ("dot-count",
85                                     gh_int2scm (rest_req_l_->duration_.dots_i_));
86           announce_element (Score_element_info (dot_p_,0));
87         }
88
89       announce_element (Score_element_info (rest_p_, rest_req_l_));
90     }
91 }
92
93 bool
94 Rest_engraver::do_try_music (Music *req)
95 {
96   if (Rest_req *r = dynamic_cast <Rest_req *> (req))
97     {
98       rest_req_l_ = r;
99       return true;
100     }  
101   return false;
102 }
103
104
105 ADD_THIS_TRANSLATOR(Rest_engraver);