* scripts/lilypond-book.py (option_definitions): typo
[lilypond.git] / lily / volta-engraver.cc
blobe95718b12156e896dcb099de6bea87095dd9e991
1 /*
2 volta-engraver.cc -- implement Volta_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "engraver.hh"
11 #include "translator-group.hh"
12 #include "volta-bracket.hh"
13 #include "item.hh"
14 #include "note-column.hh"
15 #include "bar-line.hh"
16 #include "side-position-interface.hh"
17 #include "warn.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
26 public:
27 TRANSLATOR_DECLARATIONS(Volta_engraver);
28 protected:
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 ();
36 Moment started_mom_;
37 Spanner *volta_span_;
38 Spanner *end_volta_span_;
39 SCM staff_;
40 SCM start_string_;
43 Volta_engraver::Volta_engraver ()
45 staff_ = SCM_EOL;
46 volta_span_ = 0;
47 end_volta_span_ = 0;
51 void
52 Volta_engraver::process_music ()
54 if (unsmob_grob (staff_)
55 && !to_boolean (get_property ("voltaOnThisStaff")))
58 TODO: this does weird things when you open a piece with a
59 volta spanner.
62 SCM staffs = get_property ("stavesFound");
65 only put a volta on the top staff.
67 May be this is a bit convoluted, and we should have a single
68 volta engraver in score context or somesuch.
71 if (!gh_pair_p (staffs))
72 programming_error ("Huh? Volta engraver can't find staffs?");
73 else if (ly_car (scm_last_pair (staffs)) != staff_)
74 return ;
78 SCM cs = get_property ("repeatCommands");
80 bool end = false;
81 start_string_ = SCM_EOL;
82 while (gh_pair_p (cs))
84 SCM c = ly_car (cs);
86 if (gh_pair_p (c)
87 && ly_car (c) == ly_symbol2scm ("volta")
88 && gh_pair_p (ly_cdr (c)))
90 if (ly_cadr (c) == SCM_BOOL_F)
91 end = true;
92 else
93 start_string_ = ly_cadr (c);
96 cs = ly_cdr (cs);
99 if (volta_span_)
101 SCM l (get_property ("voltaSpannerDuration"));
102 Moment now = now_mom ();
104 bool early_stop = unsmob_moment (l)
105 && *unsmob_moment (l) <= now - started_mom_;
107 end = end || early_stop;
111 if (end && !volta_span_)
113 warning (_ ("No volta spanner to end")); // fixme: be more verbose.
115 else if (end)
117 end_volta_span_ = volta_span_;
118 volta_span_ =0;
121 if (volta_span_ &&
122 (gh_string_p (start_string_) || gh_pair_p (start_string_)))
124 warning (_ ("Already have a volta spanner. Stopping that one prematurely."));
126 if (end_volta_span_)
128 warning (_ ("Also have a stopped spanner. Giving up."));
129 return ;
132 end_volta_span_ = volta_span_;
133 volta_span_ = 0;
138 this could just as well be done in process_music (), but what the hack.
140 void
141 Volta_engraver::process_acknowledged_grobs ()
143 if (!volta_span_ &&
144 (gh_string_p (start_string_) || gh_pair_p (start_string_)))
146 started_mom_ = now_mom () ;
148 volta_span_ = new Spanner (get_property ("VoltaBracket"));
150 announce_grob (volta_span_, SCM_EOL);
151 volta_span_->set_grob_property ("text", start_string_);
155 void
156 Volta_engraver::acknowledge_grob (Grob_info i)
158 if (Item* item = dynamic_cast<Item*> (i.grob_))
160 if (Note_column::has_interface (item))
162 if (volta_span_)
163 Volta_bracket_interface::add_column (volta_span_,item);
165 if (Bar_line::has_interface (item))
167 if (volta_span_)
168 Volta_bracket_interface::add_bar (volta_span_, item);
169 if (end_volta_span_)
170 Volta_bracket_interface::add_bar (end_volta_span_ , item);
173 else if (Staff_symbol::has_interface (i.grob_))
176 We only want to know about a single staff: then we add to the
177 support. */
178 if (staff_ != SCM_EOL)
179 staff_ = SCM_UNDEFINED;
181 if (staff_ != SCM_UNDEFINED)
182 staff_ = i.grob_->self_scm();
186 void
187 Volta_engraver::finalize ()
189 if (volta_span_)
191 typeset_grob (volta_span_);
193 if (end_volta_span_)
195 typeset_grob (end_volta_span_);
201 void
202 Volta_engraver::stop_translation_timestep ()
204 if (end_volta_span_)
206 typeset_grob (end_volta_span_);
207 end_volta_span_ =0;
212 TODO: should attach volta to paper-column if no bar is found.
215 ENTER_DESCRIPTION(Volta_engraver,
216 /* descr */ "Make volta brackets",
217 /* creats*/ "VoltaBracket",
218 /* accepts */ "",
219 /* acks */ "bar-line-interface staff-symbol-interface note-column-interface",
220 /* reads */ "repeatCommands voltaSpannerDuration stavesFound",
221 /* write */ "");