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>
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
,
38 Score_performer::Score_performer ()
45 Score_performer::~Score_performer ()
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_
);
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 ();
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"));
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
);
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
);
109 Score_performer::finish (SCM
)
111 recurse_over_translators (context (),
112 &Translator::finalize
,
113 &Translator_group::finalize
,
117 IMPLEMENT_LISTENER (Score_performer
, one_time_step
);
119 Score_performer::one_time_step (SCM
)
121 if (to_boolean (context ()->get_property ("skipTypesetting")))
125 skip_start_mom_
= audio_column_
->when ();
133 offset_mom_
-= audio_column_
->when () - skip_start_mom_
;
137 audio_column_
->offset_when (offset_mom_
);
138 precomputed_recurse_over_translators (context (), PROCESS_MUSIC
, UP
);
142 precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP
, UP
);
146 Score_performer::derived_mark () const
149 scm_gc_mark (performance_
->self_scm ());
151 Performer_group::derived_mark ();
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 ();