2 repeat-engraver.cc -- implement Repeat_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
12 #include "bar-engraver.hh"
13 #include "musical-request.hh"
14 #include "multi-measure-rest.hh"
15 #include "command-request.hh"
16 #include "timing-translator.hh"
17 #include "engraver-group-engraver.hh"
18 #include "repeated-music.hh"
19 #include "timing-translator.hh"
20 #include "volta-spanner.hh"
21 #include "note-column.hh"
22 #include "paper-def.hh"
23 #include "music-list.hh"
24 #include "side-position-interface.hh"
26 #include "note-column.hh"
28 struct Bar_create_event
35 Bar_create_event (Moment w, String s);
36 Bar_create_event (Moment w, int i, int j);
39 int compare (Bar_create_event const & c1, Bar_create_event const &c2)
41 return (c1.when_ - c2.when_).sign();
45 Generate repeat-bars |: :| for repeated-music
47 class Repeat_engraver : public Engraver
50 VIRTUAL_COPY_CONS(Translator);
53 virtual void acknowledge_element (Score_element_info i);
54 virtual void do_removal_processing ();
55 virtual bool do_try_music (Music *req_l);
56 virtual void do_process_music();
57 virtual void do_pre_move_processing();
58 virtual void do_post_move_processing ();
62 Repeated_music *repeated_music_l_;
63 bool done_this_one_b_;
66 Royal_brackla_create_queue is only two Whiskies away. :-)
68 Cons<Bar_create_event> *create_barmoments_queue_;
70 Spanner * volta_span_p_;
71 Spanner* end_volta_span_p_;
77 ADD_THIS_TRANSLATOR (Repeat_engraver);
80 Repeat_engraver::do_try_music (Music* m)
82 if (Repeated_music* r = dynamic_cast<Repeated_music *> (m))
84 if (repeated_music_l_)
89 repeated_music_l_ = r;
93 We acknowledge other types of unfolded music as well, to
94 get auto context selection right.
96 if (r->type_ == "volta" || r->type_ == "unfolded")
104 Walk through repeat music, and generate events for appropriate times.
106 UGH. Should use Music_iteration for this.
108 Should also queue some event to get timing information reset during
109 2nd and following voltas.
112 Repeat_engraver::queue_events ()
114 Music_sequence* alt = repeated_music_l_->alternatives_p_;
115 Moment walk_mom = now_mom () + repeated_music_l_->repeat_body_p_->length_mom ();
117 SCM novolta = get_property ("noVoltaBraces");
118 bool create_volta = !to_boolean (novolta);
120 Cons_list<Bar_create_event> becel;
121 becel.append (new Bar_create_event (now_mom (), "|:"));
125 becel.append (new Bar_create_event (walk_mom, ":|"));
126 becel.append (new Bar_create_event (walk_mom, "stop"));
131 int volta_number = repeated_music_l_->repeats_i_ - alt->length_i () + 1;
134 all repeat alternatives, and generate events with
135 appropriate timestamps. The volta spanner event (a number string)
136 happens at the begin of the alt. The :| bar event at the ending.
138 for (Cons<Music> *i = alt->music_p_list_p_->head_; i; i = i->next_)
142 some idiot might typeset a repeat not starting on a
143 barline. Make sure there is one.
145 (todo: should try to avoid line breaks?)
147 if (last_number == 0)
149 becel.append (new Bar_create_event (walk_mom, ""));
155 Bar_create_event * c = new Bar_create_event (walk_mom, last_number+ 1,
162 last_number = volta_number;
164 SCM l (get_property ("voltaSpannerDuration"));
165 if (SMOB_IS_TYPE_B (Moment, l))
167 Moment vSD_mom = *SMOB_TO_TYPE (Moment,l);
168 if ( vSD_mom < i->car_->length_mom() ) // terminate volta early ?
172 becel.append (new Bar_create_event (vSD_mom, "stop"));
176 walk_mom += i->car_->length_mom();
179 becel.append (new Bar_create_event (walk_mom, ":|"));
181 becel.append (new Bar_create_event (walk_mom, "stop"));
185 Cons<Bar_create_event> *&tail = create_barmoments_queue_
186 ? last_cons (create_barmoments_queue_)->next_
187 : create_barmoments_queue_;
194 Repeat_engraver::do_process_music ()
196 if (repeated_music_l_ && !done_this_one_b_)
199 done_this_one_b_ = true;
203 Cons<Bar_create_event> * head = create_barmoments_queue_;
207 Bar_engraver* bar_engraver_l = dynamic_cast <Bar_engraver*>
208 (daddy_grav_l ()->get_simple_translator ("Bar_engraver"));
211 Do all the events that need to be done now.
213 while (head && now_mom () == head->car_->when_)
215 create_barmoments_queue_ = create_barmoments_queue_->next_;
219 String t = head->car_->type_;
220 if (head->car_->bar_b_)
222 if (t == "stop" || t == ":|")
224 end_volta_span_p_ = volta_span_p_;
229 bar_engraver_l->request_bar (t);
231 bar_engraver_l->request_bar ("");
235 assert (!volta_span_p_);
236 volta_span_p_ = new Spanner (get_property ("basicVoltaSpannerProperties"));
237 Volta_spanner::set_interface (volta_span_p_);
238 announce_element (Score_element_info (volta_span_p_,0));
239 volta_span_p_->set_elt_property ("text",
240 ly_str02scm (t.ch_C()));
241 volta_span_p_->set_elt_property ("last-volta",
242 gh_bool2scm (head->car_->last_b_));
243 // voltaSpannerDuration stuff here.
244 // other property stuff here.
250 warning (_ ("No bar engraver found. Ignoring repeats."));
256 head = create_barmoments_queue_;
259 assert (!head || head->car_->when_ > now_mom ());
264 Repeat_engraver::acknowledge_element (Score_element_info i)
266 if (Item* item = dynamic_cast<Item*> (i.elem_l_))
268 if (Note_column::has_interface (item))
271 Volta_spanner::add_column (volta_span_p_,item);
272 if (end_volta_span_p_)
273 Volta_spanner::add_column (end_volta_span_p_,item);
275 if (Bar::has_interface (item))
278 Volta_spanner::add_bar (volta_span_p_, item);
279 if (end_volta_span_p_)
280 Volta_spanner::add_bar(end_volta_span_p_ , item);
286 Repeat_engraver::do_removal_processing ()
290 typeset_element(volta_span_p_);
292 if (end_volta_span_p_)
294 typeset_element (end_volta_span_p_);
296 // todo: the paranoid may also delete create_barmoments_queue_
300 Repeat_engraver::do_post_move_processing ()
302 for (Cons<Bar_create_event> *p = create_barmoments_queue_;
303 p && p->car_->when_ == now_mom (); p = p->next_)
304 if (p->car_->type_ == "stop")
306 repeated_music_l_ = 0;
307 done_this_one_b_ = false;
312 Repeat_engraver::do_pre_move_processing ()
314 if (end_volta_span_p_)
316 Side_position::add_staff_support (end_volta_span_p_);
318 typeset_element (end_volta_span_p_ );
319 end_volta_span_p_ =0;
325 Repeat_engraver::Repeat_engraver()
327 repeated_music_l_ =0;
328 end_volta_span_p_ =0;
330 done_this_one_b_ = false;
331 create_barmoments_queue_ =0;
335 Bar_create_event::Bar_create_event()
341 Bar_create_event::Bar_create_event (Moment w, String s)
349 Bar_create_event::Bar_create_event (Moment w, int i, int j)
356 type_ = to_str (i) + ".-" ;
358 type_ += to_str(j) + ".";