lilypond-1.3.28
[lilypond.git] / lily / simultaneous-music-iterator.cc
blob7e60780cc941bb50f8429953ab0e3f6b13ae74cf
1 /*
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>
7 */
9 #include "translator-group.hh"
10 #include "debug.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 ();
25 void
26 Simultaneous_music_iterator::construct_children()
28 int j = 0;
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_,
41 to_str (j))
42 : report_to_l ();
44 if (!t)
45 t = report_to_l ();
47 mi->init_translator (i->car_, t);
48 mi->construct_children ();
50 if (mi->ok())
52 children_p_list_.append (new Killing_cons<Music_iterator> (mi,0));
54 else
55 delete mi;
59 void
60 Simultaneous_music_iterator::do_print() const
62 #ifndef NPRINT
63 for (Cons<Music_iterator> *p = children_p_list_.head_; p; p = p->next_)
64 p->car_->print();
65 #endif
68 void
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);
78 if (!i->ok())
79 delete children_p_list_.remove_cons (pp);
80 else
81 pp = &(*pp)->next_;
83 Music_iterator::do_process_and_next (until);
89 Moment
90 Simultaneous_music_iterator::next_moment() const
92 Moment next;
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() ;
97 return next;
102 bool
103 Simultaneous_music_iterator::ok() const
105 return children_p_list_.head_;
108 Music_iterator*
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);
114 return b;