2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2015 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"
22 #include "axis-group-interface.hh"
24 #include "grob-array.hh"
25 #include "international.hh"
26 #include "note-column.hh"
28 #include "side-position-interface.hh"
29 #include "staff-symbol.hh"
30 #include "text-interface.hh"
31 #include "volta-bracket.hh"
34 #include "translator.icc"
37 Create Volta spanners, by reading repeatCommands property, usually
38 set by Volta_repeat_iterator.
40 class Volta_engraver : public Engraver
43 TRANSLATOR_DECLARATIONS (Volta_engraver);
46 void acknowledge_bar_line (Grob_info);
48 virtual void derived_mark () const;
49 void stop_translation_timestep ();
50 void process_music ();
53 Spanner *volta_bracket_;
54 Spanner *end_volta_bracket_;
55 Spanner *volta_spanner_;
60 Volta_engraver::derived_mark () const
62 scm_gc_mark (start_string_);
65 Volta_engraver::Volta_engraver (Context *c)
68 start_string_ = SCM_EOL;
70 end_volta_bracket_ = 0;
75 Volta_engraver::process_music ()
77 SCM cs = get_property ("repeatCommands");
80 start_string_ = SCM_EOL;
81 while (scm_is_pair (cs))
86 && scm_is_eq (scm_car (c), ly_symbol2scm ("volta"))
87 && scm_is_pair (scm_cdr (c)))
89 if (scm_is_false (scm_cadr (c)))
92 start_string_ = scm_cadr (c);
100 SCM l (get_property ("voltaSpannerDuration"));
101 Moment now = now_mom ();
103 bool early_stop = unsmob<Moment> (l)
104 && *unsmob<Moment> (l) <= now - started_mom_;
106 end = end || early_stop;
109 if (end && !volta_bracket_)
110 /* fixme: be more verbose. */
111 warning (_ ("cannot end volta spanner"));
114 end_volta_bracket_ = volta_bracket_;
119 && (scm_is_string (start_string_) || scm_is_pair (start_string_)))
121 warning (_ ("already have a volta spanner, ending that one prematurely"));
123 if (end_volta_bracket_)
125 warning (_ ("also already have an ended spanner"));
126 warning (_ ("giving up"));
130 end_volta_bracket_ = volta_bracket_;
135 && Text_interface::is_markup (start_string_))
137 started_mom_ = now_mom ();
139 volta_bracket_ = make_spanner ("VoltaBracket", SCM_EOL);
141 volta_bracket_->set_property ("text", start_string_);
144 volta_spanner_ = make_spanner ("VoltaBracketSpanner", SCM_EOL);
146 Axis_group_interface::add_element (volta_spanner_, volta_bracket_);
151 Volta_engraver::acknowledge_bar_line (Grob_info i)
154 Volta_bracket_interface::add_bar (volta_bracket_, i.item ());
155 if (end_volta_bracket_)
156 Volta_bracket_interface::add_bar (end_volta_bracket_, i.item ());
159 Side_position_interface::add_support (volta_spanner_, i.grob ());
163 Volta_engraver::stop_translation_timestep ()
165 Grob *cc = unsmob<Grob> (get_property ("currentCommandColumn"));
166 Item *ci = dynamic_cast<Item *> (cc);
168 if (end_volta_bracket_ && !end_volta_bracket_->get_bound (RIGHT))
169 end_volta_bracket_->set_bound (RIGHT, ci);
171 if (volta_spanner_ && end_volta_bracket_)
172 volta_spanner_->set_bound (RIGHT, end_volta_bracket_->get_bound (RIGHT));
174 if (end_volta_bracket_ && !volta_bracket_)
176 for (SCM s = get_property ("stavesFound"); scm_is_pair (s); s = scm_cdr (s))
177 Side_position_interface::add_support (volta_spanner_, unsmob<Grob> (scm_car (s)));
181 end_volta_bracket_ = 0;
183 if (volta_bracket_ && !volta_bracket_->get_bound (LEFT))
184 volta_bracket_->set_bound (LEFT, ci);
186 if (volta_spanner_ && volta_bracket_ && !volta_spanner_->get_bound (LEFT))
187 volta_spanner_->set_bound (LEFT, volta_bracket_->get_bound (LEFT));
191 TODO: should attach volta to paper-column if no bar is found.
194 Volta_engraver::boot ()
196 ADD_ACKNOWLEDGER (Volta_engraver, bar_line);
199 ADD_TRANSLATOR (Volta_engraver,
201 "Make volta brackets.",
205 "VoltaBracketSpanner ",
209 "voltaSpannerDuration "