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-bracket.hh"
14 #include "note-column.hh"
15 #include "bar-line.hh"
16 #include "side-position-interface.hh"
18 #include "staff-symbol.hh"
21 Create Volta spanners, by reading repeatCommands property, usually
22 set by Unfolded_repeat_iterator.
24 class Volta_engraver : public Engraver
27 TRANSLATOR_DECLARATIONS(Volta_engraver);
30 virtual void acknowledge_grob (Grob_info);
31 virtual void finalize ();
32 virtual void stop_translation_timestep ();
33 virtual void process_music ();
34 virtual void process_acknowledged_grobs ();
37 Spanner *volta_span_p_;
38 Spanner *end_volta_span_p_;
43 Volta_engraver::Volta_engraver ()
47 end_volta_span_p_ = 0;
52 Volta_engraver::process_music ()
54 if (unsmob_grob (staff_))
57 TODO: this does weird things when you open a piece with a
61 SCM staffs = get_property ("stavesFound");
64 only put a volta on the top staff.
66 May be this is a bit convoluted, and we should have a single
67 volta engraver in score context or somesuch.
70 if (ly_car (scm_last_pair (staffs)) != staff_)
75 SCM cs = get_property ("repeatCommands");
79 while (gh_pair_p (cs))
83 if (gh_pair_p (c) && ly_car (c) == ly_symbol2scm ("volta")
84 && gh_pair_p (ly_cdr (c)))
86 if (ly_cadr (c) == SCM_BOOL_F)
89 start_str_ = ly_cadr (c);
97 SCM l (get_property ("voltaSpannerDuration"));
98 Moment now = now_mom ();
100 bool early_stop = unsmob_moment (l)
101 && *unsmob_moment (l) <= now - started_mom_;
103 end = end || early_stop;
107 if (end && !volta_span_p_)
109 warning (_ ("No volta spanner to end")); // fixme: be more verbose.
113 end_volta_span_p_ = volta_span_p_;
117 if (gh_string_p (start_str_) && volta_span_p_)
119 warning (_ ("Already have a volta spanner. Stopping that one prematurely."));
121 if (end_volta_span_p_)
123 warning (_ ("Also have a stopped spanner. Giving up."));
127 end_volta_span_p_ = volta_span_p_;
133 this could just as well be done in process_music (), but what the hack.
136 Volta_engraver::process_acknowledged_grobs ()
138 if (!volta_span_p_ && gh_string_p (start_str_))
140 started_mom_ = now_mom () ;
142 volta_span_p_ = new Spanner (get_property ("VoltaBracket"));
144 announce_grob (volta_span_p_, SCM_EOL);
145 volta_span_p_->set_grob_property ("text", start_str_);
150 Volta_engraver::acknowledge_grob (Grob_info i)
152 if (Item* item = dynamic_cast<Item*> (i.grob_l_))
154 if (Note_column::has_interface (item))
157 Volta_bracket_interface::add_column (volta_span_p_,item);
159 if (Bar_line::has_interface (item))
162 Volta_bracket_interface::add_bar (volta_span_p_, item);
163 if (end_volta_span_p_)
164 Volta_bracket_interface::add_bar (end_volta_span_p_ , item);
167 else if (Staff_symbol::has_interface (i.grob_l_))
170 We only want to know about a single staff: then we add to the
172 if (staff_ != SCM_EOL)
173 staff_ = SCM_UNDEFINED;
175 if (staff_ != SCM_UNDEFINED)
176 staff_ = i.grob_l_->self_scm();
181 Volta_engraver::finalize ()
185 typeset_grob (volta_span_p_);
187 if (end_volta_span_p_)
189 typeset_grob (end_volta_span_p_);
196 Volta_engraver::stop_translation_timestep ()
198 if (end_volta_span_p_)
200 typeset_grob (end_volta_span_p_);
201 end_volta_span_p_ =0;
206 TODO: should attach volta to paper-column if no bar is found.
209 ENTER_DESCRIPTION(Volta_engraver,
210 /* descr */ "Make volta brackets",
211 /* creats*/ "VoltaBracket",
212 /* acks */ "bar-line-interface staff-symbol-interface note-column-interface",
213 /* reads */ "repeatCommands voltaSpannerDuration stavesFound",