Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / simultaneous-music-iterator.cc
blob3723c2695fe238ecf31a8d2f00e35df621e8d7e5
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "simultaneous-music-iterator.hh"
21 #include "music.hh"
22 #include "context.hh"
23 #include "warn.hh"
24 #include "context-def.hh"
26 Simultaneous_music_iterator::Simultaneous_music_iterator ()
28 create_separate_contexts_ = false;
29 children_list_ = SCM_EOL;
32 void
33 Simultaneous_music_iterator::derived_mark () const
35 scm_gc_mark (children_list_);
38 void
39 Simultaneous_music_iterator::derived_substitute (Context *f, Context *t)
41 for (SCM s = children_list_; scm_is_pair (s); s = scm_cdr (s))
42 unsmob_iterator (scm_car (s))->substitute_outlet (f, t);
45 void
46 Simultaneous_music_iterator::construct_children ()
48 int j = 0;
50 SCM i = get_music ()->get_property ("elements");
52 children_list_ = SCM_EOL;
53 SCM *tail = &children_list_;
54 for (; scm_is_pair (i); i = scm_cdr (i), j++)
56 Music *mus = unsmob_music (scm_car (i));
58 SCM scm_iter = get_static_get_iterator (mus);
59 Music_iterator *mi = unsmob_iterator (scm_iter);
61 /* if create_separate_contexts_ is set, create a new context with the
62 number number as name */
64 SCM name = ly_symbol2scm (get_outlet ()->context_name ().c_str ());
65 Context *c = (j && create_separate_contexts_)
66 ? get_outlet ()->find_create_context (name, to_string (j), SCM_EOL)
67 : get_outlet ();
69 if (!c)
70 c = get_outlet ();
72 mi->init_context (mus, c);
73 mi->construct_children ();
75 if (mi->ok ())
77 *tail = scm_cons (scm_iter, *tail);
78 tail = SCM_CDRLOC (*tail);
80 else
81 mi->quit ();
85 void
86 Simultaneous_music_iterator::process (Moment until)
88 SCM *proc = &children_list_;
89 while (scm_is_pair (*proc))
91 Music_iterator *i = unsmob_iterator (scm_car (*proc));
92 if (i->run_always ()
93 || i->pending_moment () == until)
94 i->process (until);
95 if (!i->ok ())
97 i->quit ();
98 *proc = scm_cdr (*proc);
100 else
101 proc = SCM_CDRLOC (*proc);
105 Moment
106 Simultaneous_music_iterator::pending_moment () const
108 Moment next;
109 next.set_infinite (1);
111 for (SCM s = children_list_; scm_is_pair (s); s = scm_cdr (s))
113 Music_iterator *it = unsmob_iterator (scm_car (s));
114 next = min (next, it->pending_moment ());
117 return next;
120 bool
121 Simultaneous_music_iterator::ok () const
123 bool run_always_ok = false;
124 for (SCM s = children_list_; scm_is_pair (s); s = scm_cdr (s))
126 Music_iterator *it = unsmob_iterator (scm_car (s));
127 if (!it->run_always ())
128 return true;
129 else
130 run_always_ok = run_always_ok || it->ok ();
132 return run_always_ok;
135 bool
136 Simultaneous_music_iterator::run_always () const
138 for (SCM s = children_list_; scm_is_pair (s); s = scm_cdr (s))
140 Music_iterator *it = unsmob_iterator (scm_car (s));
141 if (it->run_always ())
142 return true;
144 return false;
147 void
148 Simultaneous_music_iterator::do_quit ()
150 for (SCM s = children_list_; scm_is_pair (s); s = scm_cdr (s))
151 unsmob_iterator (scm_car (s))->quit ();
154 IMPLEMENT_CTOR_CALLBACK (Simultaneous_music_iterator);