]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-performer.cc
* lily/*.cc, lily/include/*.hh: eliminate dummy arguments from
[lilypond.git] / lily / score-performer.cc
1 /*
2   score-performer.cc -- implement Score_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "score-performer.hh"
10
11 #include "audio-column.hh"
12 #include "audio-item.hh"
13 #include "context-def.hh"
14 #include "context.hh"
15 #include "dispatcher.hh"
16 #include "global-context.hh"
17 #include "performance.hh"
18 #include "midi-stream.hh"
19 #include "moment.hh"
20 #include "output-def.hh"
21 #include "string-convert.hh"
22 #include "warn.hh"
23 #include "audio-staff.hh"
24 #include "audio-item.hh"
25
26 ADD_TRANSLATOR_GROUP (Score_performer,
27                       /* doc */ "",
28                       /* create */ "",
29                       /* read */ "",
30                       /* write */ "");
31
32 Score_performer::Score_performer ()
33 {
34   performance_ = 0;
35   skipping_ = false;
36   audio_column_ = 0;
37 }
38
39 Score_performer::~Score_performer ()
40 {
41 }
42
43 void
44 Score_performer::announce_element (Audio_element_info info)
45 {
46   announce_infos_.push_back (info);
47   if (Audio_staff *s = dynamic_cast<Audio_staff*> (info.elem_))
48     {
49       performance_->audio_staffs_.push_back (s);
50     }
51
52   performance_->add_element (info.elem_);
53 }
54
55 void
56 Score_performer::acknowledge_audio_elements ()
57 {
58   for (vsize i = 0; i < announce_infos_.size (); i++)
59     {
60       if (Audio_item *ai = dynamic_cast<Audio_item *> (announce_infos_[i].elem_))
61         audio_column_->add_audio_item (ai);
62     }
63   Performer_group::acknowledge_audio_elements ();
64 }
65
66
67 void
68 Score_performer::connect_to_context (Context *c)
69 {
70   Performer_group::connect_to_context (c);
71   
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"));
76 }
77
78 void
79 Score_performer::disconnect_from_context ()
80 {
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"));
85
86   Performer_group::disconnect_from_context ();
87 }
88
89 IMPLEMENT_LISTENER (Score_performer, prepare);
90 void
91 Score_performer::prepare (SCM sev)
92 {
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);
98 }
99
100 IMPLEMENT_LISTENER (Score_performer, finish);
101 void
102 Score_performer::finish (SCM)
103 {
104   recurse_over_translators (context (),
105                             &Translator::finalize,
106                             &Translator_group::finalize,
107                             UP);
108 }
109
110 IMPLEMENT_LISTENER (Score_performer, one_time_step);
111 void
112 Score_performer::one_time_step (SCM)
113 {
114   if (to_boolean (context ()->get_property ("skipTypesetting")))
115     {
116       if (!skipping_)
117         {
118           skip_start_mom_ = audio_column_->at_mom ();
119           skipping_ = true;
120         }
121     }
122   else
123     {
124       if (skipping_)
125         {
126           offset_mom_ -= audio_column_->at_mom () - skip_start_mom_;
127           skipping_ = false;
128         }
129
130       audio_column_->offset_at_mom (offset_mom_);
131       precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
132       do_announces ();
133     }
134
135   precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
136 }
137
138 void
139 Score_performer::derived_mark () const
140 {
141   if (performance_)
142     scm_gc_mark (performance_->self_scm ());
143
144   Performer_group::derived_mark ();
145 }
146
147 void
148 Score_performer::initialize ()
149 {
150   performance_ = new Performance;
151   performance_->unprotect ();
152   context ()->set_property ("output", performance_->self_scm ()); 
153   performance_->midi_ = context ()->get_output_def ();
154
155
156   Translator_group::initialize ();
157 }
158
159