Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / score-performer.cc
blob5257788df6b7969ad07ec12925bf5ea0beab0695
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1996--2011 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "score-performer.hh"
22 #include "audio-column.hh"
23 #include "audio-item.hh"
24 #include "context-def.hh"
25 #include "dispatcher.hh"
26 #include "global-context.hh"
27 #include "performance.hh"
28 #include "midi-stream.hh"
29 #include "output-def.hh"
30 #include "string-convert.hh"
31 #include "warn.hh"
32 #include "audio-staff.hh"
33 #include "audio-item.hh"
35 ADD_TRANSLATOR_GROUP (Score_performer,
36 /* doc */
37 "",
39 /* create */
40 "",
42 /* read */
43 "",
45 /* write */
49 Score_performer::Score_performer ()
51 performance_ = 0;
52 skipping_ = false;
53 audio_column_ = 0;
56 Score_performer::~Score_performer ()
60 void
61 Score_performer::announce_element (Audio_element_info info)
63 announce_infos_.push_back (info);
64 if (Audio_staff *s = dynamic_cast<Audio_staff*> (info.elem_))
66 performance_->audio_staffs_.push_back (s);
69 performance_->add_element (info.elem_);
72 void
73 Score_performer::acknowledge_audio_elements ()
75 for (vsize i = 0; i < announce_infos_.size (); i++)
77 if (Audio_item *ai = dynamic_cast<Audio_item *> (announce_infos_[i].elem_))
78 audio_column_->add_audio_item (ai);
80 Performer_group::acknowledge_audio_elements ();
84 void
85 Score_performer::connect_to_context (Context *c)
87 Performer_group::connect_to_context (c);
89 Dispatcher *d = c->get_global_context ()->event_source ();
90 d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
91 d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
92 d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
95 void
96 Score_performer::disconnect_from_context ()
98 Dispatcher *d = context ()->get_global_context ()->event_source ();
99 d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
100 d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
101 d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
103 Performer_group::disconnect_from_context ();
106 IMPLEMENT_LISTENER (Score_performer, prepare);
107 void
108 Score_performer::prepare (SCM sev)
110 Stream_event *ev = unsmob_stream_event (sev);
111 SCM sm = ev->get_property ("moment");
112 Moment *m = unsmob_moment (sm);
113 audio_column_ = new Audio_column (*m);
114 announce_element (Audio_element_info (audio_column_, 0));
115 precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, UP);
118 IMPLEMENT_LISTENER (Score_performer, finish);
119 void
120 Score_performer::finish (SCM)
122 SCM channel_mapping = context ()->get_property ("midiChannelMapping");
123 bool use_ports = channel_mapping == ly_symbol2scm ("voice");
124 performance_->ports_ = use_ports;
125 recurse_over_translators (context (),
126 &Translator::finalize,
127 &Translator_group::finalize,
128 UP);
131 IMPLEMENT_LISTENER (Score_performer, one_time_step);
132 void
133 Score_performer::one_time_step (SCM)
135 if (to_boolean (context ()->get_property ("skipTypesetting")))
137 if (!skipping_)
139 skip_start_mom_ = audio_column_->when ();
140 skipping_ = true;
143 else
145 if (skipping_)
147 offset_mom_ -= audio_column_->when () - skip_start_mom_;
148 skipping_ = false;
151 audio_column_->offset_when (offset_mom_);
152 precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
153 do_announces ();
156 precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
159 void
160 Score_performer::derived_mark () const
162 if (performance_)
163 scm_gc_mark (performance_->self_scm ());
165 Performer_group::derived_mark ();
168 void
169 Score_performer::initialize ()
171 performance_ = new Performance;
172 performance_->unprotect ();
173 context ()->set_property ("output", performance_->self_scm ());
174 performance_->midi_ = context ()->get_output_def ();
177 Translator_group::initialize ();