]> git.donarmstrong.com Git - lilypond.git/blob - lily/rest-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / rest-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 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   void listen_rest (Stream_event *);
41 public:
42   TRANSLATOR_DECLARATIONS (Rest_engraver);
43 };
44
45 /*
46   Should merge with Note_head_engraver
47 */
48 Rest_engraver::Rest_engraver (Context *c)
49   : Engraver (c)
50 {
51   rest_event_ = 0;
52   rest_ = 0;
53   dot_ = 0;
54 }
55
56 void
57 Rest_engraver::start_translation_timestep ()
58 {
59   rest_event_ = 0;
60   rest_ = 0;
61   dot_ = 0;
62 }
63
64 void
65 Rest_engraver::process_music ()
66 {
67   if (rest_event_ && !rest_)
68     {
69       rest_ = make_item ("Rest", rest_event_->self_scm ());
70       Pitch *p = unsmob<Pitch> (rest_event_->get_property ("pitch"));
71
72       if (p)
73         {
74           int pos = p->steps ();
75           SCM c0 = get_property ("middleCPosition");
76           if (scm_is_number (c0))
77             pos += scm_to_int (c0);
78
79           rest_->set_property ("staff-position", scm_from_int (pos));
80         }
81     }
82 }
83
84 void
85 Rest_engraver::listen_rest (Stream_event *ev)
86 {
87   ASSIGN_EVENT_ONCE (rest_event_, ev);
88 }
89
90 void
91 Rest_engraver::boot ()
92 {
93   ADD_LISTENER (Rest_engraver, rest);
94 }
95
96 ADD_TRANSLATOR (Rest_engraver,
97                 /* doc */
98                 "Engrave rests.",
99
100                 /* create */
101                 "Rest ",
102
103                 /* read */
104                 "middleCPosition ",
105
106                 /* write */
107                 ""
108                );