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