LSR: Update.
[lilypond/mpolesky.git] / lily / repeat-acknowledge-engraver.cc
blobf8507b9285189df282c00672d550188b020e206b
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "engraver.hh"
21 #include "translator-group.hh"
22 #include "context.hh"
23 #include "repeated-music.hh"
25 #include "translator.icc"
28 Objective:
30 -- set and reset repeatCommands, so Unfolded_repeat_iterator knows
31 where to set variables.
33 -- collect information passed by Unfolded_repeat_iterator for
34 Bar_engraver: writes whichBar property. (TODO: check for
35 interactions with timing engraver.)
37 class Repeat_acknowledge_engraver : public Engraver
39 public:
41 TRANSLATOR_DECLARATIONS (Repeat_acknowledge_engraver);
42 protected:
43 void start_translation_timestep ();
44 void process_music ();
45 virtual void initialize ();
48 void
49 Repeat_acknowledge_engraver::initialize ()
51 context ()->set_property ("repeatCommands", SCM_EOL);
54 Repeat_acknowledge_engraver::Repeat_acknowledge_engraver ()
58 void
59 Repeat_acknowledge_engraver::start_translation_timestep ()
61 SCM rc;
62 Context *tr = context ()->where_defined (ly_symbol2scm ("repeatCommands"), &rc);
63 if (!tr)
64 tr = context ();
66 tr->set_property ("repeatCommands", SCM_EOL);
69 void
70 Repeat_acknowledge_engraver::process_music ()
73 At the start of a piece, we don't print any repeat bars.
75 if (!now_mom ().main_part_)
76 return;
78 SCM cs = get_property ("repeatCommands");
80 string s = "";
81 bool start = false;
82 bool end = false;
83 bool volta_found = false;
84 while (scm_is_pair (cs))
86 SCM command = scm_car (cs);
87 if (command == ly_symbol2scm ("start-repeat"))
88 start = true;
89 else if (command == ly_symbol2scm ("end-repeat"))
90 end = true;
91 else if (scm_is_pair (command) && scm_car (command) == ly_symbol2scm ("volta"))
92 volta_found = true;
93 cs = scm_cdr (cs);
96 if (start && end)
97 s = robust_scm2string (get_property ("doubleRepeatType"), ":|:");
98 else if (start)
99 s = "|:";
100 else if (end)
101 s = ":|";
104 TODO: line breaks might be allowed if we set whichBar to "".
108 We only set the barline if we wouldn't overwrite a previously set
109 barline.
111 SCM wb = get_property ("whichBar");
112 SCM db = get_property ("defaultBarType");
113 if (!scm_is_string (wb) || ly_is_equal (db, wb))
115 if (s != "" || (volta_found && !scm_is_string (wb)))
116 context ()->set_property ("whichBar", ly_string2scm (s));
120 ADD_TRANSLATOR (Repeat_acknowledge_engraver,
121 /* doc */
122 "Acknowledge repeated music, and convert the contents of"
123 " @code{repeatCommands} into an appropriate setting for"
124 " @code{whichBar}.",
126 /* create */
129 /* read */
130 "doubleRepeatType "
131 "repeatCommands "
132 "whichBar ",
134 /* write */