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"
14 #include "dispatcher.hh"
15 #include "global-context.hh"
16 #include "performance.hh"
17 #include "midi-stream.hh"
18 #include "output-def.hh"
19 #include "string-convert.hh"
21 #include "audio-staff.hh"
22 #include "audio-item.hh"
24 ADD_TRANSLATOR_GROUP (Score_performer,
30 Score_performer::Score_performer ()
37 Score_performer::~Score_performer ()
42 Score_performer::announce_element (Audio_element_info info)
44 announce_infos_.push_back (info);
45 if (Audio_staff *s = dynamic_cast<Audio_staff*> (info.elem_))
47 performance_->audio_staffs_.push_back (s);
50 performance_->add_element (info.elem_);
54 Score_performer::acknowledge_audio_elements ()
56 for (vsize i = 0; i < announce_infos_.size (); i++)
58 if (Audio_item *ai = dynamic_cast<Audio_item *> (announce_infos_[i].elem_))
59 audio_column_->add_audio_item (ai);
61 Performer_group::acknowledge_audio_elements ();
66 Score_performer::connect_to_context (Context *c)
68 Performer_group::connect_to_context (c);
70 Dispatcher *d = c->get_global_context ()->event_source ();
71 d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
72 d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
73 d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
77 Score_performer::disconnect_from_context ()
79 Dispatcher *d = context ()->get_global_context ()->event_source ();
80 d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
81 d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
82 d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
84 Performer_group::disconnect_from_context ();
87 IMPLEMENT_LISTENER (Score_performer, prepare);
89 Score_performer::prepare (SCM sev)
91 Stream_event *ev = unsmob_stream_event (sev);
92 SCM sm = ev->get_property ("moment");
93 Moment *m = unsmob_moment (sm);
94 audio_column_ = new Audio_column (*m);
95 precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, UP);
98 IMPLEMENT_LISTENER (Score_performer, finish);
100 Score_performer::finish (SCM)
102 recurse_over_translators (context (),
103 &Translator::finalize,
104 &Translator_group::finalize,
108 IMPLEMENT_LISTENER (Score_performer, one_time_step);
110 Score_performer::one_time_step (SCM)
112 if (to_boolean (context ()->get_property ("skipTypesetting")))
116 skip_start_mom_ = audio_column_->at_mom ();
124 offset_mom_ -= audio_column_->at_mom () - skip_start_mom_;
128 audio_column_->offset_at_mom (offset_mom_);
129 precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
133 precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
137 Score_performer::derived_mark () const
140 scm_gc_mark (performance_->self_scm ());
142 Performer_group::derived_mark ();
146 Score_performer::initialize ()
148 performance_ = new Performance;
149 performance_->unprotect ();
150 context ()->set_property ("output", performance_->self_scm ());
151 performance_->midi_ = context ()->get_output_def ();
154 Translator_group::initialize ();