2 Simultaneous_music-iterator.cc -- implement Simultaneous_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 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 (Simultaneous_music_iterator
const& src
)
21 : Music_iterator (src
)
23 separate_contexts_b_
= src
.separate_contexts_b_
;
24 for (Cons
<Music_iterator
> *p
= src
.children_p_list_
.head_
; p
; p
= p
->next_
)
26 Music_iterator
*i
= p
->car_
;
27 children_p_list_
.append (new Killing_cons
<Music_iterator
> (i
->clone (), 0));
31 Simultaneous_music_iterator::~Simultaneous_music_iterator ()
33 children_p_list_
.junk ();
37 Simultaneous_music_iterator::get_music (Moment m
)const
40 for (Cons
<Music_iterator
> *p
= children_p_list_
.head_
; p
; p
= p
->next_
)
42 s
= gh_append2 (p
->car_
->get_music (m
), s
);
48 Simultaneous_music_iterator::construct_children ()
51 Music_sequence
const *sim
= dynamic_cast<Music_sequence
const*> (music_l_
);
53 SCM i
= sim
->music_list ();
54 for (; gh_pair_p (i
); i
= gh_cdr (i
), j
++)
56 Music
*mus
= unsmob_music (gh_car (i
));
57 Music_iterator
* mi
= static_get_iterator_p (mus
);
59 /* if separate_contexts_b_ is set, create a new context with the
60 number number as name */
62 Translator_group
* t
= (j
&& separate_contexts_b_
)
63 ? report_to_l ()->find_create_translator_l (report_to_l ()->type_str_
,
70 mi
->init_translator (mus
, t
);
71 mi
->construct_children ();
75 children_p_list_
.append (new Killing_cons
<Music_iterator
> (mi
,0));
84 Simultaneous_music_iterator::process (Moment until
)
86 for (Cons
<Music_iterator
> **pp
= &children_p_list_
.head_
; *pp
;)
88 Music_iterator
* i
= (*pp
)->car_
;
89 if (i
->pending_moment () == until
)
94 delete children_p_list_
.remove_cons (pp
);
101 Simultaneous_music_iterator::skip (Moment until
)
103 for (Cons
<Music_iterator
> **pp
= &children_p_list_
.head_
; *pp
;)
105 Music_iterator
* i
= (*pp
)->car_
;
106 if (i
->pending_moment () <= until
)
111 delete children_p_list_
.remove_cons (pp
);
118 Simultaneous_music_iterator::pending_moment () const
121 next
.set_infinite (1);
123 for (Cons
<Music_iterator
> *p
= children_p_list_
.head_
; p
; p
= p
->next_
)
124 next
= next
<? p
->car_
->pending_moment () ;
131 Simultaneous_music_iterator::ok () const
133 return children_p_list_
.head_
;
137 Simultaneous_music_iterator::try_music_in_children (Music
*m
) const
139 Music_iterator
* b
=0;
140 for (Cons
<Music_iterator
> *p
= children_p_list_
.head_
; !b
&& p
; p
= p
->next_
)
141 b
=p
->car_
->try_music (m
);
147 IMPLEMENT_CTOR_CALLBACK (Simultaneous_music_iterator
);