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