Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / score-performer.cc
blob9e5db10e88d7c374669423fc2fcac9aebbc11f5c
1 /*
2 score-performer.cc -- implement Score_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2009 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
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"
20 #include "warn.hh"
21 #include "audio-staff.hh"
22 #include "audio-item.hh"
24 ADD_TRANSLATOR_GROUP (Score_performer,
25 /* doc */
26 "",
28 /* create */
29 "",
31 /* read */
32 "",
34 /* write */
38 Score_performer::Score_performer ()
40 performance_ = 0;
41 skipping_ = false;
42 audio_column_ = 0;
45 Score_performer::~Score_performer ()
49 void
50 Score_performer::announce_element (Audio_element_info info)
52 announce_infos_.push_back (info);
53 if (Audio_staff *s = dynamic_cast<Audio_staff*> (info.elem_))
55 performance_->audio_staffs_.push_back (s);
58 performance_->add_element (info.elem_);
61 void
62 Score_performer::acknowledge_audio_elements ()
64 for (vsize i = 0; i < announce_infos_.size (); i++)
66 if (Audio_item *ai = dynamic_cast<Audio_item *> (announce_infos_[i].elem_))
67 audio_column_->add_audio_item (ai);
69 Performer_group::acknowledge_audio_elements ();
73 void
74 Score_performer::connect_to_context (Context *c)
76 Performer_group::connect_to_context (c);
78 Dispatcher *d = c->get_global_context ()->event_source ();
79 d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
80 d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
81 d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
84 void
85 Score_performer::disconnect_from_context ()
87 Dispatcher *d = context ()->get_global_context ()->event_source ();
88 d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
89 d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
90 d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
92 Performer_group::disconnect_from_context ();
95 IMPLEMENT_LISTENER (Score_performer, prepare);
96 void
97 Score_performer::prepare (SCM sev)
99 Stream_event *ev = unsmob_stream_event (sev);
100 SCM sm = ev->get_property ("moment");
101 Moment *m = unsmob_moment (sm);
102 audio_column_ = new Audio_column (*m);
103 announce_element (Audio_element_info (audio_column_, 0));
104 precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, UP);
107 IMPLEMENT_LISTENER (Score_performer, finish);
108 void
109 Score_performer::finish (SCM)
111 recurse_over_translators (context (),
112 &Translator::finalize,
113 &Translator_group::finalize,
114 UP);
117 IMPLEMENT_LISTENER (Score_performer, one_time_step);
118 void
119 Score_performer::one_time_step (SCM)
121 if (to_boolean (context ()->get_property ("skipTypesetting")))
123 if (!skipping_)
125 skip_start_mom_ = audio_column_->when ();
126 skipping_ = true;
129 else
131 if (skipping_)
133 offset_mom_ -= audio_column_->when () - skip_start_mom_;
134 skipping_ = false;
137 audio_column_->offset_when (offset_mom_);
138 precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
139 do_announces ();
142 precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
145 void
146 Score_performer::derived_mark () const
148 if (performance_)
149 scm_gc_mark (performance_->self_scm ());
151 Performer_group::derived_mark ();
154 void
155 Score_performer::initialize ()
157 performance_ = new Performance;
158 performance_->unprotect ();
159 context ()->set_property ("output", performance_->self_scm ());
160 performance_->midi_ = context ()->get_output_def ();
163 Translator_group::initialize ();