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"
23 #include "audio-staff.hh"
24 #include "audio-item.hh"
26 ADD_TRANSLATOR_GROUP (Score_performer,
32 Score_performer::Score_performer ()
39 Score_performer::~Score_performer ()
44 Score_performer::announce_element (Audio_element_info info)
46 announce_infos_.push_back (info);
47 if (Audio_staff *s = dynamic_cast<Audio_staff*> (info.elem_))
49 performance_->audio_staffs_.push_back (s);
52 performance_->add_element (info.elem_);
56 Score_performer::acknowledge_audio_elements ()
58 for (vsize i = 0; i < announce_infos_.size (); i++)
60 if (Audio_item *ai = dynamic_cast<Audio_item *> (announce_infos_[i].elem_))
61 audio_column_->add_audio_item (ai);
63 Performer_group::acknowledge_audio_elements ();
68 Score_performer::connect_to_context (Context *c)
70 Performer_group::connect_to_context (c);
72 Dispatcher *d = c->get_global_context ()->event_source ();
73 d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
74 d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
75 d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
79 Score_performer::disconnect_from_context ()
81 Dispatcher *d = context ()->get_global_context ()->event_source ();
82 d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
83 d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
84 d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
86 Performer_group::disconnect_from_context ();
89 IMPLEMENT_LISTENER (Score_performer, prepare);
91 Score_performer::prepare (SCM sev)
93 Stream_event *ev = unsmob_stream_event (sev);
94 SCM sm = ev->get_property ("moment");
95 Moment *m = unsmob_moment (sm);
96 audio_column_ = new Audio_column (*m);
97 precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, UP);
100 IMPLEMENT_LISTENER (Score_performer, finish);
102 Score_performer::finish (SCM)
104 recurse_over_translators (context (),
105 &Translator::finalize,
106 &Translator_group::finalize,
110 IMPLEMENT_LISTENER (Score_performer, one_time_step);
112 Score_performer::one_time_step (SCM)
114 if (to_boolean (context ()->get_property ("skipTypesetting")))
118 skip_start_mom_ = audio_column_->at_mom ();
126 offset_mom_ -= audio_column_->at_mom () - skip_start_mom_;
130 audio_column_->offset_at_mom (offset_mom_);
131 precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
135 precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
139 Score_performer::derived_mark () const
142 scm_gc_mark (performance_->self_scm ());
144 Performer_group::derived_mark ();
148 Score_performer::initialize ()
150 performance_ = new Performance;
151 performance_->unprotect ();
152 context ()->set_property ("output", performance_->self_scm ());
153 performance_->midi_ = context ()->get_output_def ();
156 Translator_group::initialize ();