source file of the GNU LilyPond music typesetter
- (c) 2004--2005 Han-Wen Nienhuys
+ (c) 2004--2006 Han-Wen Nienhuys
*/
#include "context.hh"
-#include "event.hh"
-#include "music-sequence.hh"
+#include "dispatcher.hh"
#include "lily-guile.hh"
-#include "warn.hh"
+#include "listener.hh"
+#include "music.hh"
#include "music-iterator.hh"
+#include "music-sequence.hh"
+#include "warn.hh"
class Part_combine_iterator : public Music_iterator
{
virtual void do_quit ();
virtual void process (Moment);
- virtual Music_iterator *try_music_in_children (Music *) const;
-
virtual bool ok () const;
private:
+ /* used by try_process */
+ DECLARE_LISTENER (set_busy);
+ bool busy_;
+ bool notice_busy_;
+
+ bool try_process (Music_iterator *i, Moment m);
+
Music_iterator *first_iter_;
Music_iterator *second_iter_;
Moment start_moment_;
/*
TODO: this is getting of hand...
*/
- Interpretation_context_handle one_;
- Interpretation_context_handle two_;
- Interpretation_context_handle null_;
- Interpretation_context_handle shared_;
- Interpretation_context_handle solo_;
+ Context_handle one_;
+ Context_handle two_;
+ Context_handle null_;
+ Context_handle shared_;
+ Context_handle solo_;
void substitute_both (Context *to1,
Context *to2);
void unisono (bool silent);
};
-static Music *busy_playing_event;
-
void
Part_combine_iterator::do_quit ()
{
second_iter_->quit ();
null_.set_context (0);
- one_ .set_context (0);
+ one_.set_context (0);
two_.set_context (0);
shared_.set_context (0);
solo_.set_context (0);
-
}
Part_combine_iterator::Part_combine_iterator ()
split_list_ = SCM_EOL;
state_ = APART;
playing_state_ = APART;
-
- if (!busy_playing_event)
- {
- busy_playing_event
- = make_music_by_name (ly_symbol2scm ("BusyPlayingEvent"));
- }
}
void
{
if (first_iter_)
first_iter_->substitute_outlet (f, t);
-
}
Moment
Moment p;
p.set_infinite (1);
if (first_iter_->ok ())
- p = p <? first_iter_->pending_moment ();
+ p = min (p, first_iter_->pending_moment ());
if (second_iter_->ok ())
- p = p <? second_iter_->pending_moment ();
+ p = min (p, second_iter_->pending_moment ());
return p;
}
mmrest->set_property ("duration", SCM_EOL);
}
- tg->try_music (mmrest);
+ mmrest->send_to_context (tg);
}
void
if (!event)
event = make_music_by_name (ly_symbol2scm ("SoloOneEvent"));
- first_iter_-> try_music_in_children (event);
+ event->send_to_context (first_iter_->get_outlet ());
}
playing_state_ = SOLO1;
}
{
Context *tos[] = {to1, to2};
Music_iterator *mis[] = {first_iter_, second_iter_};
- Interpretation_context_handle *hs[]
+ Context_handle *hs[]
= {
&null_,
&one_, &two_,
if (!event)
event = make_music_by_name (ly_symbol2scm ("UnisonoEvent"));
- (last_playing_ == SOLO2 ? second_iter_ : first_iter_)
- ->try_music_in_children (event);
+ Context *out = (last_playing_ == SOLO2 ? second_iter_ : first_iter_)
+ ->get_outlet ();
+ event->send_to_context (out);
playing_state_ = UNISONO;
}
state_ = newstate;
if (!event)
event = make_music_by_name (ly_symbol2scm ("SoloTwoEvent"));
- second_iter_-> try_music_in_children (event);
+ event->send_to_context (second_iter_->get_outlet ());
playing_state_ = SOLO2;
}
}
= get_outlet ()->find_create_context (ly_symbol2scm ("Voice"),
"solo", props);
- solo_ .set_context (solo_tr);
+ solo_.set_context (solo_tr);
Context *null
= get_outlet ()->find_create_context (ly_symbol2scm ("Devnull"),
"", SCM_EOL);
if (!null)
- programming_error ("No Devnull found?");
+ programming_error ("no Devnull found");
null_.set_context (null);
0
};
+ // Add listeners to all contexts except Devnull.
+ Context *contexts[] = {one, two, solo_tr, tr, 0};
+ for (int i = 0; contexts[i]; i++)
+ {
+ contexts[i]->event_source ()->add_listener (GET_LISTENER (set_busy), ly_symbol2scm ("MusicEvent"));
+ }
+
for (char const **p = syms; *p; p++)
{
SCM sym = ly_symbol2scm (*p);
execute_pushpop_property (one, sym,
- ly_symbol2scm ("direction"), scm_int2num (1));
+ ly_symbol2scm ("direction"), scm_from_int (1));
execute_pushpop_property (two, sym,
- ly_symbol2scm ("direction"), scm_int2num (-1));
+ ly_symbol2scm ("direction"), scm_from_int (-1));
}
+}
+
+IMPLEMENT_LISTENER (Part_combine_iterator, set_busy);
+void
+Part_combine_iterator::set_busy (SCM se)
+{
+ if (!notice_busy_)
+ return;
+
+ Stream_event *e = unsmob_stream_event (se);
+ SCM mus = e->get_property ("music");
+ Music *m = unsmob_music (mus);
+ assert (m);
+
+ if (m->is_mus_type ("note-event") || m->is_mus_type ("cluster-note-event"))
+ busy_ = true;
+}
+
+/*
+* Processes a moment in an iterator, and returns whether any new music was reported.
+*/
+bool
+Part_combine_iterator::try_process (Music_iterator *i, Moment m)
+{
+ busy_ = false;
+ notice_busy_ = true;
+ i->process (m);
+
+ notice_busy_ = false;
+ return busy_;
}
void
Moment now = get_outlet ()->now_mom ();
Moment *splitm = 0;
+ /* This is needed if construct_children was called before iteration
+ started */
+ if (start_moment_.main_part_.is_infinity () && start_moment_ < 0)
+ start_moment_ = now;
+
for (; scm_is_pair (split_list_); split_list_ = scm_cdr (split_list_))
{
splitm = unsmob_moment (scm_caar (split_list_));
solo2 ();
else if (scm_is_symbol (tag))
{
- String s = "Unknown split directive: "
- + (scm_is_symbol (tag) ? ly_symbol2string (tag) : String ("not a symbol"));
+ string s = "Unknown split directive: "
+ + (scm_is_symbol (tag) ? ly_symbol2string (tag) : string ("not a symbol"));
programming_error (s);
}
}
if (first_iter_->ok ())
{
- first_iter_->process (m);
- if (first_iter_->try_music_in_children (busy_playing_event))
- last_playing_ = SOLO1;
+ if (try_process (first_iter_, m))
+ last_playing_ = SOLO1;
}
if (second_iter_->ok ())
{
- second_iter_->process (m);
- if (first_iter_->try_music_in_children (busy_playing_event))
+ if (try_process (second_iter_, m))
last_playing_ = SOLO2;
}
}
-Music_iterator *
-Part_combine_iterator::try_music_in_children (Music *m) const
-{
- Music_iterator *i = first_iter_->try_music (m);
- if (i)
- return i;
- else
- return second_iter_->try_music (m);
-}
-
IMPLEMENT_CTOR_CALLBACK (Part_combine_iterator);