]> git.donarmstrong.com Git - lilypond.git/blob - lily/slash-repeat-engraver.cc
Issue 5024: Rework the Preinit framework into something simpler
[lilypond.git] / lily / slash-repeat-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>, Erik Sandberg
5   <mandolaerik@gmail.com>
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "item.hh"
22 #include "engraver.hh"
23 #include "stream-event.hh"
24
25 #include "translator.icc"
26
27 /*
28   This acknowledges repeated music with "percent" style.  It typesets
29   a slash sign or double percent sign.
30 */
31 class Slash_repeat_engraver : public Engraver
32 {
33 public:
34   TRANSLATOR_DECLARATIONS (Slash_repeat_engraver);
35 protected:
36   Stream_event *slash_;
37 protected:
38   void listen_repeat_slash (Stream_event *);
39   void process_music ();
40 };
41
42 Slash_repeat_engraver::Slash_repeat_engraver ()
43 {
44   slash_ = 0;
45 }
46
47 void
48 Slash_repeat_engraver::listen_repeat_slash (Stream_event *ev)
49 {
50   ASSIGN_EVENT_ONCE (slash_, ev);
51 }
52
53 void
54 Slash_repeat_engraver::process_music ()
55 {
56   if (slash_)
57     {
58       SCM count = slash_->get_property ("slash-count");
59       if (scm_to_int (count) == 0)
60         make_item ("DoubleRepeatSlash", slash_->self_scm ());
61       else
62         make_item ("RepeatSlash", slash_->self_scm ());
63       slash_ = 0;
64     }
65 }
66
67 void
68 Slash_repeat_engraver::boot ()
69 {
70   ADD_LISTENER (Slash_repeat_engraver, repeat_slash);
71 }
72
73 ADD_TRANSLATOR (Slash_repeat_engraver,
74                 /* doc */
75                 "Make beat repeats.",
76
77                 /* create */
78                 "DoubleRepeatSlash "
79                 "RepeatSlash ",
80
81                 /* read */
82                 "",
83
84                 /* write */
85                 ""
86                );