]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
2003 -> 2004
[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   if (rest_)
52     {
53       typeset_grob (rest_);
54       rest_ =0;
55     }
56   if (dot_)
57     {
58       typeset_grob (dot_);
59       dot_ =0;
60     }    
61 }
62
63 void
64 Rest_engraver::process_music ()
65 {
66   if (rest_req_ && !rest_) 
67     {
68       rest_ = make_item ("Rest");
69
70       int durlog  = unsmob_duration (rest_req_->get_mus_property ("duration"))-> duration_log ();
71       
72       rest_->set_grob_property ("duration-log",
73                                   gh_int2scm (durlog));
74
75       int dots =unsmob_duration (rest_req_->get_mus_property ("duration"))->dot_count ();
76       
77       if (dots)
78         {
79           dot_ = make_item ("Dots");
80
81           Rhythmic_head::set_dots (rest_, dot_);
82           dot_->set_parent (rest_, Y_AXIS);
83           dot_->set_grob_property ("dot-count", gh_int2scm (dots));
84           announce_grob (dot_, SCM_EOL);
85         }
86
87       Pitch *p = unsmob_pitch (rest_req_->get_mus_property ("pitch"));
88
89       /*
90         This is ridiculous -- rests don't have pitch, but we act as if
91         our nose is bleeding.
92        */
93       if (p)
94         {
95           int pos= p->steps ();
96           SCM c0 = get_property ("centralCPosition");
97           if (gh_number_p (c0))
98             pos += gh_scm2int (c0);
99           
100           rest_->set_grob_property ("staff-position", gh_int2scm (pos));
101         }
102       
103       announce_grob(rest_, rest_req_->self_scm());
104     }
105 }
106
107 bool
108 Rest_engraver::try_music (Music *m)
109 {
110   if (m->is_mus_type ("rest-event"))
111     {
112       rest_req_ = m;
113       return true;
114     }
115   return false;
116 }
117
118 ENTER_DESCRIPTION(Rest_engraver,
119 /* descr */       "",
120 /* creats*/       "Rest Dots",
121 /* accepts */     "rest-event",
122 /* acks  */      "",
123 /* reads */       "centralCPosition",
124 /* write */       "");