]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeat-acknowledge-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / repeat-acknowledge-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>
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 #include "translator-group.hh"
22 #include "context.hh"
23 #include "repeated-music.hh"
24
25 #include "translator.icc"
26
27 using std::string;
28
29 /*
30   Objective:
31
32   -- set and reset repeatCommands, so Unfolded_repeat_iterator knows
33   where to set variables.
34
35   -- collect information passed by Unfolded_repeat_iterator for
36   Bar_engraver: writes whichBar property. (TODO: check for
37   interactions with timing engraver.)
38 */
39 class Repeat_acknowledge_engraver : public Engraver
40 {
41 public:
42
43   TRANSLATOR_DECLARATIONS (Repeat_acknowledge_engraver);
44 protected:
45   void start_translation_timestep ();
46   void process_music ();
47   virtual void initialize ();
48 };
49
50 void
51 Repeat_acknowledge_engraver::initialize ()
52 {
53   context ()->set_property ("repeatCommands", SCM_EOL);
54 }
55
56 Repeat_acknowledge_engraver::Repeat_acknowledge_engraver ()
57 {
58 }
59
60 void
61 Repeat_acknowledge_engraver::start_translation_timestep ()
62 {
63   SCM rc;
64   Context *tr = context ()->where_defined (ly_symbol2scm ("repeatCommands"), &rc);
65   if (!tr)
66     tr = context ();
67
68   tr->set_property ("repeatCommands", SCM_EOL);
69 }
70
71 void
72 Repeat_acknowledge_engraver::process_music ()
73 {
74   /*
75     At the start of a piece, we don't print any repeat bars.
76   */
77   if (!now_mom ().main_part_)
78     return;
79
80   SCM cs = get_property ("repeatCommands");
81
82   string s = "";
83   bool start = false;
84   bool end = false;
85   bool segno = false;
86   bool volta_found = false;
87   while (scm_is_pair (cs))
88     {
89       SCM command = scm_car (cs);
90       if (scm_is_eq (command, ly_symbol2scm ("start-repeat")))
91         start = true;
92       else if (scm_is_eq (command, ly_symbol2scm ("end-repeat")))
93         end = true;
94       else if (scm_is_eq (command, ly_symbol2scm ("segno-display")))
95         segno = true;
96       else if (scm_is_pair (command)
97                && scm_is_eq (scm_car (command), ly_symbol2scm ("volta")))
98         volta_found = true;
99       cs = scm_cdr (cs);
100     }
101
102   /*
103     Select which bar type to set
104   */
105   if (segno)
106     if (start)
107       if (end) // { segno, start, end }
108         s = robust_scm2string (get_property ("doubleRepeatSegnoType"), ":|.S.|:");
109       else // { segno, start }
110         s = robust_scm2string (get_property ("startRepeatSegnoType"), "S.|:");
111     else if (end) // { segno, end }
112       s = robust_scm2string (get_property ("endRepeatSegnoType"), ":|.S");
113     else // { segno }
114       s = robust_scm2string (get_property ("segnoType"), "S");
115   else if (start)
116     if (end) // { start, end }
117       s = robust_scm2string (get_property ("doubleRepeatType"), ":|.|:");
118     else // { start }
119       s = robust_scm2string (get_property ("startRepeatType"), ".|:");
120   else if (end) // { end }
121     s = robust_scm2string (get_property ("endRepeatType"), ":|.");
122
123   /*
124     TODO: line breaks might be allowed if we set whichBar to "".
125   */
126
127   /*
128     We only set the barline if we wouldn't overwrite a previously set
129     barline.
130   */
131   SCM wb = get_property ("whichBar");
132   SCM db = get_property ("defaultBarType");
133   if (!scm_is_string (wb) || ly_is_equal (db, wb))
134     {
135       if (s != "" || (volta_found && !scm_is_string (wb)))
136         context ()->set_property ("whichBar", ly_string2scm (s));
137     }
138 }
139
140 ADD_TRANSLATOR (Repeat_acknowledge_engraver,
141                 /* doc */
142                 "Acknowledge repeated music, and convert the contents of"
143                 " @code{repeatCommands} into an appropriate setting for"
144                 " @code{whichBar}.",
145
146                 /* create */
147                 "",
148
149                 /* read */
150                 "doubleRepeatType "
151                 "startRepeatType "
152                 "endRepeatType "
153                 "doubleRepeatSegnoType "
154                 "startRepeatSegnoType "
155                 "endRepeatSegnoType "
156                 "segnoType "
157                 "repeatCommands "
158                 "whichBar ",
159
160                 /* write */
161                 ""
162                );