2 Simultaneous_music-iterator.cc -- implement Simultaneous_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 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"
16 Simultaneous_music_iterator::Simultaneous_music_iterator ()
18 separate_contexts_b_ = false;
19 children_list_ = SCM_EOL;
22 Simultaneous_music_iterator::Simultaneous_music_iterator (Simultaneous_music_iterator const& src)
23 : Music_iterator (src)
26 = src.separate_contexts_b_;
27 children_list_ = SCM_EOL;
29 SCM children_list = SCM_EOL;
30 SCM *tail = &children_list;
31 for (SCM s = src.children_list_; gh_pair_p (s); s = gh_cdr(s))
33 Music_iterator *i = unsmob_iterator (gh_car (s));
34 SCM cl = i->clone ()->self_scm();
35 *tail = scm_cons (cl, *tail);
36 tail = SCM_CDRLOC (*tail);
37 scm_gc_unprotect_object (cl);
40 children_list_ = children_list;
41 scm_remember_upto_here_1 (children_list);
45 Simultaneous_music_iterator::derived_mark()const
47 scm_gc_mark (children_list_);
51 Simultaneous_music_iterator::get_pending_events (Moment m)const
54 for (SCM s = children_list_; gh_pair_p (s); s = gh_cdr(s))
56 l = gh_append2 (unsmob_iterator (gh_car (s))->get_pending_events (m), l);
62 Simultaneous_music_iterator::construct_children ()
66 SCM i = get_music ()->get_mus_property ("elements");
68 children_list_ = SCM_EOL;
69 SCM * tail = &children_list_;
70 for (; gh_pair_p (i); i = ly_cdr (i), j++)
72 Music *mus = unsmob_music (ly_car (i));
74 SCM scm_iter = get_static_get_iterator (mus);
75 Music_iterator * mi = unsmob_iterator (scm_iter);
77 /* if separate_contexts_b_ is set, create a new context with the
78 number number as name */
80 Translator_group * t = (j && separate_contexts_b_)
81 ? report_to ()->find_create_translator (report_to ()->type_string_,
88 mi->init_translator (mus, t);
89 mi->construct_children ();
93 *tail = scm_cons (scm_iter, *tail);
94 tail = SCM_CDRLOC (*tail);
97 mi->set_translator (0);
102 Simultaneous_music_iterator::process (Moment until)
104 SCM *proc = &children_list_;
105 while(gh_pair_p (*proc))
107 Music_iterator * i = unsmob_iterator (gh_car (*proc));
108 if (i->pending_moment () == until)
115 *proc = gh_cdr (*proc);
119 proc = SCM_CDRLOC(*proc);
125 Simultaneous_music_iterator::skip (Moment until)
127 SCM *proc = &children_list_;
128 while(gh_pair_p (*proc))
130 Music_iterator * i = unsmob_iterator (gh_car (*proc));
131 if (i->pending_moment () <= until)
138 *proc = gh_cdr (*proc);
142 proc = SCM_CDRLOC(*proc);
148 Simultaneous_music_iterator::pending_moment () const
151 next.set_infinite (1);
153 for (SCM s = children_list_; gh_pair_p (s); s = gh_cdr(s))
154 next = next <? unsmob_iterator (gh_car (s))->pending_moment () ;
161 Simultaneous_music_iterator::ok () const
163 return gh_pair_p (children_list_);
167 Simultaneous_music_iterator::try_music_in_children (Music *m) const
169 Music_iterator * b=0;
170 for (SCM s = children_list_; !b && gh_pair_p (s); s = gh_cdr(s))
171 b =unsmob_iterator (gh_car (s))->try_music (m);
176 Simultaneous_music_iterator::do_quit ()
178 for (SCM s = children_list_; gh_pair_p (s); s = gh_cdr(s))
179 unsmob_iterator (gh_car (s))->quit();
183 IMPLEMENT_CTOR_CALLBACK (Simultaneous_music_iterator);