]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-performer.cc
Issue 4464/2: include hygiene: break cycles, remove duplicate includes etc.
[lilypond.git] / lily / score-performer.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2015 Jan Nieuwenhuizen <janneke@gnu.org>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "score-performer.hh"
21
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
34 ADD_TRANSLATOR_GROUP (Score_performer,
35                       /* doc */
36                       "",
37
38                       /* create */
39                       "",
40
41                       /* read */
42                       "",
43
44                       /* write */
45                       ""
46                      );
47
48 Score_performer::Score_performer ()
49 {
50   performance_ = 0;
51   skipping_ = false;
52   audio_column_ = 0;
53 }
54
55 Score_performer::~Score_performer ()
56 {
57 }
58
59 void
60 Score_performer::announce_element (Audio_element_info info)
61 {
62   announce_infos_.push_back (info);
63   if (Audio_staff *s = dynamic_cast<Audio_staff *> (info.elem_))
64     {
65       performance_->audio_staffs_.push_back (s);
66     }
67
68   performance_->add_element (info.elem_);
69 }
70
71 void
72 Score_performer::acknowledge_audio_elements ()
73 {
74   for (vsize i = 0; i < announce_infos_.size (); i++)
75     {
76       if (Audio_item *ai = dynamic_cast<Audio_item *> (announce_infos_[i].elem_))
77         audio_column_->add_audio_item (ai);
78     }
79   Performer_group::acknowledge_audio_elements ();
80 }
81
82 void
83 Score_performer::connect_to_context (Context *c)
84 {
85   Performer_group::connect_to_context (c);
86
87   Dispatcher *d = c->get_global_context ()->event_source ();
88   d->add_listener (GET_LISTENER (Score_performer, one_time_step), ly_symbol2scm ("OneTimeStep"));
89   d->add_listener (GET_LISTENER (Score_performer, prepare), ly_symbol2scm ("Prepare"));
90   d->add_listener (GET_LISTENER (Score_performer, finish), ly_symbol2scm ("Finish"));
91 }
92
93 void
94 Score_performer::disconnect_from_context ()
95 {
96   Dispatcher *d = context ()->get_global_context ()->event_source ();
97   d->remove_listener (GET_LISTENER (Score_performer, one_time_step), ly_symbol2scm ("OneTimeStep"));
98   d->remove_listener (GET_LISTENER (Score_performer, prepare), ly_symbol2scm ("Prepare"));
99   d->remove_listener (GET_LISTENER (Score_performer, finish), ly_symbol2scm ("Finish"));
100
101   Performer_group::disconnect_from_context ();
102 }
103
104 void
105 Score_performer::prepare (SCM sev)
106 {
107   Stream_event *ev = unsmob<Stream_event> (sev);
108   SCM sm = ev->get_property ("moment");
109   Moment *m = unsmob<Moment> (sm);
110   audio_column_ = new Audio_column (*m);
111   announce_element (Audio_element_info (audio_column_, 0));
112   precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, UP);
113 }
114
115 void
116 Score_performer::finish (SCM)
117 {
118   SCM channel_mapping = context ()->get_property ("midiChannelMapping");
119   bool use_ports = scm_is_eq (channel_mapping, ly_symbol2scm ("voice"));
120   performance_->ports_ = use_ports;
121   recurse_over_translators (context (),
122                             &Translator::finalize,
123                             &Translator_group::finalize,
124                             UP);
125 }
126
127 void
128 Score_performer::one_time_step (SCM)
129 {
130   // audio_column_ can be 0 when prepare has not been called.  The
131   // condition is triggered when Simple_music_iterator implicitly
132   // creates a Score context, like when writing
133   //
134   // \score { { | c4 c c c } \midi { } }
135   //
136   // The same situation happens with the Score_engraver group, but it
137   // would appear not to suffer any bad side effects.
138
139   if (!audio_column_)
140     audio_column_ = new Audio_column (context ()->now_mom ());
141   if (to_boolean (context ()->get_property ("skipTypesetting")))
142     {
143       if (!skipping_)
144         {
145           skip_start_mom_ = audio_column_->when ();
146           skipping_ = true;
147         }
148     }
149   else
150     {
151       if (skipping_)
152         {
153           offset_mom_ -= audio_column_->when () - skip_start_mom_;
154           skipping_ = false;
155         }
156
157       audio_column_->offset_when (offset_mom_);
158       precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
159       do_announces ();
160     }
161
162   precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
163 }
164
165 void
166 Score_performer::derived_mark () const
167 {
168   if (performance_)
169     scm_gc_mark (performance_->self_scm ());
170
171   Performer_group::derived_mark ();
172 }
173
174 void
175 Score_performer::initialize ()
176 {
177   performance_ = new Performance;
178   performance_->unprotect ();
179   context ()->set_property ("output", performance_->self_scm ());
180   performance_->midi_ = context ()->get_output_def ();
181
182   Translator_group::initialize ();
183 }