]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-performer.cc
* lily/smobs.cc (protect_smob): switch off fancy smob protection
[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
24 ADD_TRANSLATOR_GROUP (Score_performer,
25                       /* doc */ "",
26                       /* create */ "",
27                       /* accept */ "",
28                       /* read */ "",
29                       /* write */ "");
30
31 Score_performer::Score_performer ()
32 {
33   performance_ = 0;
34   skipping_ = false;
35 }
36
37 Score_performer::~Score_performer ()
38 {
39 }
40
41 void
42 Score_performer::play_element (Audio_element *p)
43 {
44   if (Audio_item *i = dynamic_cast<Audio_item *> (p))
45     audio_column_->add_audio_item (i);
46   performance_->add_element (p);
47 }
48
49 void
50 Score_performer::announce_element (Audio_element_info info)
51 {
52   announce_infos_.push_back (info);
53 }
54
55 void
56 Score_performer::connect_to_context (Context *c)
57 {
58   Performer_group::connect_to_context (c);
59   
60   Dispatcher *d = c->get_global_context ()->event_source ();
61   d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
62   d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
63   d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
64 }
65
66 void
67 Score_performer::disconnect_from_context ()
68 {
69   Dispatcher *d = context ()->get_global_context ()->event_source ();
70   d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
71   d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
72   d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
73
74   Performer_group::disconnect_from_context ();
75 }
76
77 IMPLEMENT_LISTENER (Score_performer, prepare);
78 void
79 Score_performer::prepare (SCM sev)
80 {
81   Stream_event *ev = unsmob_stream_event (sev);
82   SCM sm = ev->get_property ("moment");
83   Moment *m = unsmob_moment (sm);
84   audio_column_ = new Audio_column (*m);
85   play_element (audio_column_);
86   precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, UP);
87 }
88
89 IMPLEMENT_LISTENER (Score_performer, finish);
90 void
91 Score_performer::finish (SCM)
92 {
93   recurse_over_translators (context (),
94                             &Translator::finalize,
95                             &Translator_group::finalize,
96                             UP);
97 }
98
99 IMPLEMENT_LISTENER (Score_performer, one_time_step);
100 void
101 Score_performer::one_time_step (SCM)
102 {
103   if (to_boolean (context ()->get_property ("skipTypesetting")))
104     {
105       if (!skipping_)
106         {
107           skip_start_mom_ = audio_column_->at_mom ();
108           skipping_ = true;
109         }
110     }
111   else
112     {
113       if (skipping_)
114         {
115           offset_mom_ -= audio_column_->at_mom () - skip_start_mom_;
116           skipping_ = false;
117         }
118
119       audio_column_->offset_at_mom (offset_mom_);
120       precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
121       do_announces ();
122     }
123
124   precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
125 }
126
127 void
128 Score_performer::derived_mark () const
129 {
130   if (performance_)
131     scm_gc_mark (performance_->self_scm ());
132
133   Performer_group::derived_mark ();
134 }
135
136 void
137 Score_performer::initialize ()
138 {
139   performance_ = new Performance;
140   performance_->unprotect ();
141   context ()->set_property ("output", performance_->self_scm ()); 
142   performance_->midi_ = context ()->get_output_def ();
143
144   Translator_group::initialize ();
145 }