2 Simultaneous_music-iterator.cc -- implement Simultaneous_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "translator-group.hh"
11 #include "simultaneous-music-iterator.hh"
12 #include "music-list.hh"
13 #include "killing-cons.tcc"
15 Simultaneous_music_iterator::Simultaneous_music_iterator ()
17 separate_contexts_b_
= false;
20 Simultaneous_music_iterator::~Simultaneous_music_iterator ()
22 children_p_list_
.junk ();
26 Simultaneous_music_iterator::construct_children()
29 Music_sequence
const *sim
= dynamic_cast<Music_sequence
const*> (music_l_
);
31 Cons
<Music
> *i
= (sim
->music_p_list_p_
) ? sim
->music_p_list_p_
->head_
: 0;
32 for (; i
; i
= i
->next_
, j
++)
34 Music_iterator
* mi
= static_get_iterator_p (i
->car_
);
36 /* if separate_contexts_b_ is set, create a new context with the
37 number number as name */
39 Translator_group
* t
= (j
&& separate_contexts_b_
)
40 ? report_to_l ()->find_create_translator_l (report_to_l()->type_str_
,
47 mi
->init_translator (i
->car_
, t
);
48 mi
->construct_children ();
52 children_p_list_
.append (new Killing_cons
<Music_iterator
> (mi
,0));
60 Simultaneous_music_iterator::do_print() const
63 for (Cons
<Music_iterator
> *p
= children_p_list_
.head_
; p
; p
= p
->next_
)
69 Simultaneous_music_iterator::do_process_and_next (Moment until
)
71 for (Cons
<Music_iterator
> **pp
= &children_p_list_
.head_
; *pp
; )
73 Music_iterator
* i
= (*pp
)->car_
;
74 if (i
->next_moment() == until
)
76 i
->process_and_next (until
);
79 delete children_p_list_
.remove_cons (pp
);
83 Music_iterator::do_process_and_next (until
);
90 Simultaneous_music_iterator::next_moment() const
93 next
.set_infinite (1);
95 for (Cons
<Music_iterator
> *p
= children_p_list_
.head_
; p
; p
= p
->next_
)
96 next
= next
<? p
->car_
->next_moment() ;
103 Simultaneous_music_iterator::ok() const
105 return children_p_list_
.head_
;
109 Simultaneous_music_iterator::try_music_in_children (Music
const*m
) const
111 Music_iterator
* b
=0;
112 for (Cons
<Music_iterator
> *p
= children_p_list_
.head_
; !b
&& p
; p
= p
->next_
)
113 b
=p
->car_
->try_music (m
);