2 score-performer.cc -- implement Score_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2006 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "score-performer.hh"
11 #include "audio-column.hh"
12 #include "audio-item.hh"
13 #include "context-def.hh"
15 #include "dispatcher.hh"
16 #include "global-context.hh"
17 #include "performance.hh"
18 #include "midi-stream.hh"
20 #include "output-def.hh"
21 #include "string-convert.hh"
24 ADD_TRANSLATOR_GROUP (Score_performer,
31 Score_performer::Score_performer ()
37 Score_performer::~Score_performer ()
42 Score_performer::play_element (Audio_element *p)
44 if (Audio_item *i = dynamic_cast<Audio_item *> (p))
45 audio_column_->add_audio_item (i);
46 performance_->add_element (p);
50 Score_performer::announce_element (Audio_element_info info)
52 announce_infos_.push_back (info);
56 Score_performer::connect_to_context (Context *c)
58 Performer_group::connect_to_context (c);
60 Dispatcher *d = c->get_global_context ()->event_source ();
61 d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
62 d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
63 d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
67 Score_performer::disconnect_from_context ()
69 Dispatcher *d = context ()->get_global_context ()->event_source ();
70 d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
71 d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
72 d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
74 Performer_group::disconnect_from_context ();
77 IMPLEMENT_LISTENER (Score_performer, prepare);
79 Score_performer::prepare (SCM sev)
81 Stream_event *ev = unsmob_stream_event (sev);
82 SCM sm = ev->get_property ("moment");
83 Moment *m = unsmob_moment (sm);
84 audio_column_ = new Audio_column (*m);
85 play_element (audio_column_);
86 precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, UP);
89 IMPLEMENT_LISTENER (Score_performer, finish);
91 Score_performer::finish (SCM)
93 recurse_over_translators (context (),
94 &Translator::finalize,
95 &Translator_group::finalize,
99 IMPLEMENT_LISTENER (Score_performer, one_time_step);
101 Score_performer::one_time_step (SCM)
103 if (to_boolean (context ()->get_property ("skipTypesetting")))
107 skip_start_mom_ = audio_column_->at_mom ();
115 offset_mom_ -= audio_column_->at_mom () - skip_start_mom_;
119 audio_column_->offset_at_mom (offset_mom_);
120 precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
124 precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
128 Score_performer::get_tempo () const
130 return ::get_tempo (performance_->midi_, Moment (Rational (1, 4)));
134 Score_performer::derived_mark () const
137 scm_gc_mark (performance_->self_scm ());
139 Performer_group::derived_mark ();
143 Score_performer::initialize ()
145 performance_ = new Performance;
146 performance_->unprotect ();
147 context ()->set_property ("output", performance_->self_scm ());
148 performance_->midi_ = context ()->get_output_def ();
150 Translator_group::initialize ();