2 Simultaneous_music-iterator.cc -- implement Simultaneous_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 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 "context-def.hh"
16 Simultaneous_music_iterator::Simultaneous_music_iterator ()
18 separate_contexts_b_ = false;
19 children_list_ = SCM_EOL;
24 Simultaneous_music_iterator::derived_mark()const
26 scm_gc_mark (children_list_);
30 Simultaneous_music_iterator::derived_substitute(Translator_group*f,Translator_group*t)
32 for (SCM s = children_list_; gh_pair_p (s); s = gh_cdr(s))
33 unsmob_iterator (gh_car (s))-> substitute_outlet (f,t);
37 Simultaneous_music_iterator::construct_children ()
41 SCM i = get_music ()->get_mus_property ("elements");
43 children_list_ = SCM_EOL;
44 SCM * tail = &children_list_;
45 for (; gh_pair_p (i); i = ly_cdr (i), j++)
47 Music *mus = unsmob_music (ly_car (i));
49 SCM scm_iter = get_static_get_iterator (mus);
50 Music_iterator * mi = unsmob_iterator (scm_iter);
52 /* if separate_contexts_b_ is set, create a new context with the
53 number number as name */
55 SCM name = unsmob_context_def (get_outlet ()->definition_)->get_context_name ();
56 Translator_group * t = (j && separate_contexts_b_)
57 ? get_outlet ()->find_create_translator (name, to_string (j), SCM_EOL)
63 mi->init_translator (mus, t);
64 mi->construct_children ();
68 *tail = scm_cons (scm_iter, *tail);
69 tail = SCM_CDRLOC (*tail);
72 mi->set_translator (0);
77 Simultaneous_music_iterator::process (Moment until)
79 SCM *proc = &children_list_;
80 while(gh_pair_p (*proc))
82 Music_iterator * i = unsmob_iterator (gh_car (*proc));
84 || i->pending_moment () == until)
91 *proc = gh_cdr (*proc);
95 proc = SCM_CDRLOC(*proc);
101 Simultaneous_music_iterator::pending_moment () const
104 next.set_infinite (1);
106 for (SCM s = children_list_; gh_pair_p (s); s = gh_cdr(s))
108 Music_iterator * it = unsmob_iterator (gh_car (s));
109 next = next <? it->pending_moment ();
116 Simultaneous_music_iterator::ok () const
118 bool run_always_ok = false;
119 for (SCM s = children_list_; gh_pair_p (s); s = gh_cdr(s))
121 Music_iterator * it = unsmob_iterator (gh_car (s));
122 if (!it->run_always ())
125 run_always_ok = run_always_ok || it->ok ();
127 return run_always_ok;
131 Simultaneous_music_iterator::run_always () const
133 for (SCM s = children_list_; gh_pair_p (s); s = gh_cdr(s))
135 Music_iterator * it = unsmob_iterator (gh_car (s));
136 if (it->run_always ())
143 Simultaneous_music_iterator::try_music_in_children (Music *m) const
145 Music_iterator * b=0;
146 for (SCM s = children_list_; !b && gh_pair_p (s); s = gh_cdr(s))
147 b =unsmob_iterator (gh_car (s))->try_music (m);
152 Simultaneous_music_iterator::do_quit ()
154 for (SCM s = children_list_; gh_pair_p (s); s = gh_cdr(s))
155 unsmob_iterator (gh_car (s))->quit();
159 IMPLEMENT_CTOR_CALLBACK (Simultaneous_music_iterator);