2 volta-engraver.cc -- implement Volta_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "axis-group-interface.hh"
12 #include "bar-line.hh"
14 #include "grob-array.hh"
15 #include "international.hh"
16 #include "note-column.hh"
18 #include "side-position-interface.hh"
19 #include "staff-symbol.hh"
20 #include "text-interface.hh"
21 #include "volta-bracket.hh"
24 #include "translator.icc"
27 Create Volta spanners, by reading repeatCommands property, usually
28 set by Volta_repeat_iterator.
30 class Volta_engraver
: public Engraver
33 TRANSLATOR_DECLARATIONS (Volta_engraver
);
36 DECLARE_ACKNOWLEDGER (bar_line
);
38 virtual void derived_mark () const;
39 void stop_translation_timestep ();
40 void process_music ();
43 Spanner
*volta_bracket_
;
44 Spanner
*end_volta_bracket_
;
45 Spanner
*volta_spanner_
;
50 Volta_engraver::derived_mark () const
52 scm_gc_mark (start_string_
);
55 Volta_engraver::Volta_engraver ()
57 start_string_
= SCM_EOL
;
59 end_volta_bracket_
= 0;
64 Volta_engraver::process_music ()
66 SCM cs
= get_property ("repeatCommands");
69 start_string_
= SCM_EOL
;
70 while (scm_is_pair (cs
))
75 && scm_car (c
) == ly_symbol2scm ("volta")
76 && scm_is_pair (scm_cdr (c
)))
78 if (scm_cadr (c
) == SCM_BOOL_F
)
81 start_string_
= scm_cadr (c
);
89 SCM
l (get_property ("voltaSpannerDuration"));
90 Moment now
= now_mom ();
92 bool early_stop
= unsmob_moment (l
)
93 && *unsmob_moment (l
) <= now
- started_mom_
;
95 end
= end
|| early_stop
;
98 if (end
&& !volta_bracket_
)
99 /* fixme: be more verbose. */
100 warning (_ ("cannot end volta spanner"));
103 end_volta_bracket_
= volta_bracket_
;
108 && (scm_is_string (start_string_
) || scm_is_pair (start_string_
)))
110 warning (_ ("already have a volta spanner, ending that one prematurely"));
112 if (end_volta_bracket_
)
114 warning (_ ("also already have an ended spanner"));
115 warning (_ ("giving up"));
119 end_volta_bracket_
= volta_bracket_
;
124 && Text_interface::is_markup (start_string_
))
126 started_mom_
= now_mom ();
128 volta_bracket_
= make_spanner ("VoltaBracket", SCM_EOL
);
130 volta_bracket_
->set_property ("text", start_string_
);
133 volta_spanner_
= make_spanner ("VoltaBracketSpanner", SCM_EOL
);
135 Axis_group_interface::add_element (volta_spanner_
, volta_bracket_
);
140 Volta_engraver::acknowledge_bar_line (Grob_info i
)
143 Volta_bracket_interface::add_bar (volta_bracket_
, i
.item ());
144 if (end_volta_bracket_
)
145 Volta_bracket_interface::add_bar (end_volta_bracket_
, i
.item ());
148 Side_position_interface::add_support (volta_spanner_
, i
.grob ());
152 Volta_engraver::stop_translation_timestep ()
154 Grob
*cc
= unsmob_grob (get_property ("currentCommandColumn"));
155 Item
*ci
= dynamic_cast<Item
*> (cc
);
157 if (end_volta_bracket_
&& !end_volta_bracket_
->get_bound (RIGHT
))
158 end_volta_bracket_
->set_bound (RIGHT
, ci
);
160 if (volta_spanner_
&& end_volta_bracket_
)
161 volta_spanner_
->set_bound (RIGHT
, end_volta_bracket_
->get_bound (RIGHT
));
163 if (end_volta_bracket_
&& !volta_bracket_
)
165 for (SCM s
= get_property ("stavesFound"); scm_is_pair (s
); s
= scm_cdr (s
))
166 Side_position_interface::add_support (volta_spanner_
, unsmob_grob (scm_car (s
)));
170 end_volta_bracket_
= 0;
172 if (volta_bracket_
&& !volta_bracket_
->get_bound (LEFT
))
173 volta_bracket_
->set_bound (LEFT
, ci
);
175 if (volta_spanner_
&& volta_bracket_
&& !volta_spanner_
->get_bound (LEFT
))
176 volta_spanner_
->set_bound (LEFT
, volta_bracket_
->get_bound (LEFT
));
180 TODO: should attach volta to paper-column if no bar is found.
182 ADD_ACKNOWLEDGER (Volta_engraver
, bar_line
);
183 ADD_TRANSLATOR (Volta_engraver
,
185 "Make volta brackets.",
189 "VoltaBracketSpanner ",
193 "voltaSpannerDuration "