]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
402f412d2a516ae10e1d53e22c7a95445f156856
[lilypond.git] / lily / rest-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21
22 #include "dots.hh"
23 #include "duration.hh"
24 #include "item.hh"
25 #include "pitch.hh"
26 #include "rhythmic-head.hh"
27 #include "staff-symbol-referencer.hh"
28 #include "stream-event.hh"
29
30 #include "translator.icc"
31
32 class Rest_engraver : public Engraver
33 {
34   Stream_event *rest_event_;
35   Item *dot_;
36   Grob *rest_;
37 protected:
38   void start_translation_timestep ();
39   void process_music ();
40   DECLARE_TRANSLATOR_LISTENER (rest);
41 public:
42   TRANSLATOR_DECLARATIONS (Rest_engraver);
43 };
44
45 /*
46   Should merge with Note_head_engraver
47 */
48 Rest_engraver::Rest_engraver ()
49 {
50   rest_event_ = 0;
51   rest_ = 0;
52   dot_ = 0;
53 }
54
55 void
56 Rest_engraver::start_translation_timestep ()
57 {
58   rest_event_ = 0;
59   rest_ = 0;
60   dot_ = 0;
61 }
62
63 void
64 Rest_engraver::process_music ()
65 {
66   if (rest_event_ && !rest_)
67     {
68       rest_ = make_item ("Rest", rest_event_->self_scm ());
69       Pitch *p = unsmob_pitch (rest_event_->get_property ("pitch"));
70
71       if (p)
72         {
73           int pos = p->steps ();
74           SCM c0 = get_property ("middleCPosition");
75           if (scm_is_number (c0))
76             pos += scm_to_int (c0);
77
78           rest_->set_property ("staff-position", scm_from_int (pos));
79         }
80     }
81 }
82
83 IMPLEMENT_TRANSLATOR_LISTENER (Rest_engraver, rest);
84 void
85 Rest_engraver::listen_rest (Stream_event *ev)
86 {
87   ASSIGN_EVENT_ONCE (rest_event_, ev);
88 }
89
90 ADD_TRANSLATOR (Rest_engraver,
91                 /* doc */
92                 "Engrave rests.",
93
94                 /* create */
95                 "Rest ",
96
97                 /* read */
98                 "middleCPosition ",
99
100                 /* write */
101                 ""
102                );