2 volta-engraver.cc -- implement Volta_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "engraver.hh"
11 #include "translator-group.hh"
12 #include "volta-spanner.hh"
14 #include "note-column.hh"
15 #include "bar-line.hh"
16 #include "side-position-interface.hh"
17 #include "staff-symbol.hh"
20 Create Volta spanners, by reading repeatCommands property, usually
21 set by Unfolded_repeat_iterator.
23 class Volta_engraver
: public Engraver
26 TRANSLATOR_DECLARATIONS(Volta_engraver
);
29 virtual void acknowledge_grob (Grob_info
);
30 virtual void finalize ();
31 virtual void stop_translation_timestep ();
32 virtual void process_music ();
33 virtual void create_grobs ();
36 Spanner
*volta_span_p_
;
37 Spanner
*end_volta_span_p_
;
42 Volta_engraver::Volta_engraver ()
46 end_volta_span_p_
= 0;
51 Volta_engraver::process_music ()
53 if (unsmob_grob (staff_
))
56 TODO: this does weird things when you open a piece with a
60 SCM staffs
= get_property ("stavesFound");
63 only put a volta on the top staff.
65 May be this is a bit convoluted, and we should have a single
66 volta engraver in score context or somesuch.
69 if (ly_car (scm_last_pair (staffs
)) != staff_
)
74 SCM cs
= get_property ("repeatCommands");
78 while (gh_pair_p (cs
))
82 if (gh_pair_p (c
) && ly_car (c
) == ly_symbol2scm ("volta")
83 && gh_pair_p (ly_cdr (c
)))
85 if (ly_cadr (c
) == SCM_BOOL_F
)
88 start_str_
= ly_cadr (c
);
96 SCM
l (get_property ("voltaSpannerDuration"));
97 Moment now
= now_mom ();
99 bool early_stop
= unsmob_moment (l
)
100 && *unsmob_moment (l
) <= now
- started_mom_
;
102 end
= end
|| early_stop
;
106 if (end
&& !volta_span_p_
)
108 warning (_ ("No volta spanner to end")); // fixme: be more verbose.
112 end_volta_span_p_
= volta_span_p_
;
116 if (gh_string_p (start_str_
) && volta_span_p_
)
118 warning (_ ("Already have a volta spanner. Stopping that one prematurely."));
120 if (end_volta_span_p_
)
122 warning (_ ("Also have a stopped spanner. Giving up."));
126 end_volta_span_p_
= volta_span_p_
;
132 this could just as well be done in process_music (), but what the hack.
135 Volta_engraver::create_grobs ()
137 if (!volta_span_p_
&& gh_string_p (start_str_
))
139 started_mom_
= now_mom () ;
141 volta_span_p_
= new Spanner (get_property ("VoltaBracket"));
142 Volta_spanner::set_interface (volta_span_p_
);
143 announce_grob (volta_span_p_
, SCM_EOL
);
144 volta_span_p_
->set_grob_property ("text", start_str_
);
149 Volta_engraver::acknowledge_grob (Grob_info i
)
151 if (Item
* item
= dynamic_cast<Item
*> (i
.grob_l_
))
153 if (Note_column::has_interface (item
))
156 Volta_spanner::add_column (volta_span_p_
,item
);
158 if (Bar_line::has_interface (item
))
161 Volta_spanner::add_bar (volta_span_p_
, item
);
162 if (end_volta_span_p_
)
163 Volta_spanner::add_bar (end_volta_span_p_
, item
);
166 else if (Staff_symbol::has_interface (i
.grob_l_
))
169 We only want to know about a single staff: then we add to the
171 if (staff_
!= SCM_EOL
)
172 staff_
= SCM_UNDEFINED
;
174 if (staff_
!= SCM_UNDEFINED
)
175 staff_
= i
.grob_l_
->self_scm();
180 Volta_engraver::finalize ()
184 typeset_grob (volta_span_p_
);
186 if (end_volta_span_p_
)
188 typeset_grob (end_volta_span_p_
);
195 Volta_engraver::stop_translation_timestep ()
197 if (end_volta_span_p_
)
199 typeset_grob (end_volta_span_p_
);
200 end_volta_span_p_
=0;
205 TODO: should attach volta to paper-column if no bar is found.
208 ENTER_DESCRIPTION(Volta_engraver
,
209 /* descr */ "Make volta brackets",
210 /* creats*/ "VoltaBracket",
211 /* acks */ "bar-line-interface staff-symbol-interface note-column-interface",
212 /* reads */ "repeatCommands voltaSpannerDuration stavesFound",