]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
702b98b5aa96f868b6e646c553c5155673bcb1fc
[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--2001 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 create_grobs ();
26
27 public:
28   
29   VIRTUAL_COPY_CONS (Translator);
30   Rest_engraver ();
31 };
32
33
34 /*
35   Should merge with Note_head_engraver
36  */
37 Rest_engraver::Rest_engraver ()
38 {
39   rest_req_l_ =0;
40   rest_p_ =0;
41   dot_p_ =0;
42 }
43
44 void
45 Rest_engraver::start_translation_timestep ()
46 {
47   rest_req_l_ =0;
48 }
49
50 void
51 Rest_engraver::stop_translation_timestep ()
52 {
53   if (rest_p_)
54     {
55       typeset_grob (rest_p_);
56       rest_p_ =0;
57     }
58   if (dot_p_)
59     {
60       typeset_grob (dot_p_);
61       dot_p_ =0;
62     }    
63 }
64
65 void
66 Rest_engraver::create_grobs ()
67 {
68   if (rest_req_l_ && !rest_p_) 
69     {
70       rest_p_ = new Item (get_property ("Rest"));
71       Rhythmic_head::set_interface (rest_p_);
72       Staff_symbol_referencer::set_interface (rest_p_);
73       
74       int durlog  = unsmob_duration (rest_req_l_->get_mus_property ("duration"))-> duration_log ();
75       
76       rest_p_->set_grob_property ("duration-log",
77                                  gh_int2scm (durlog));
78
79       int dots =unsmob_duration (rest_req_l_->get_mus_property ("duration"))->dot_count ();
80       
81       if (dots)
82         {
83           dot_p_ = new Item (get_property ("Dots"));
84
85           Rhythmic_head::set_dots (rest_p_, dot_p_);
86           dot_p_->set_parent (rest_p_, Y_AXIS);
87           dot_p_->set_grob_property ("dot-count", gh_int2scm (dots));
88           announce_grob (dot_p_,0);
89         }
90
91       announce_grob (rest_p_, rest_req_l_);
92     }
93 }
94
95 bool
96 Rest_engraver::try_music (Music *m)
97 {
98   if (Rest_req *r = dynamic_cast <Rest_req *> (m))
99     {
100       rest_req_l_ = r;
101       return true;
102     }  
103   return false;
104 }
105
106
107 ADD_THIS_TRANSLATOR (Rest_engraver);