]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-performer.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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 "moment.hh"
10 #include "score-performer.hh"
11
12 #include "audio-column.hh"
13 #include "audio-item.hh"
14 #include "performance.hh"
15 #include "midi-stream.hh"
16 #include "string-convert.hh"
17 #include "warn.hh"
18 #include "context-def.hh"
19 #include "output-def.hh"
20 #include "context.hh"
21
22 ADD_TRANSLATOR_GROUP (Score_performer,
23                       /* doc */ "",
24                       /* create */ "",
25                       /* accept */ "",
26                       /* read */ "",
27                       /* write */ "");
28
29 Score_performer::Score_performer ()
30 {
31   performance_ = 0;
32   skipping_ = false;
33 }
34
35 Score_performer::~Score_performer ()
36 {
37 }
38
39 void
40 Score_performer::play_element (Audio_element *p)
41 {
42   if (Audio_item *i = dynamic_cast<Audio_item *> (p))
43     audio_column_->add_audio_item (i);
44   performance_->add_element (p);
45 }
46
47 void
48 Score_performer::announce_element (Audio_element_info info)
49 {
50   announce_infos_.push_back (info);
51 }
52
53 void
54 Score_performer::prepare (Moment m)
55 {
56   audio_column_ = new Audio_column (m);
57   play_element (audio_column_);
58   precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, UP);
59 }
60
61 void
62 Score_performer::finish ()
63 {
64   recurse_over_translators (context (),
65                             &Translator::finalize,
66                             &Translator_group::finalize,
67                             UP);
68 }
69
70 void
71 Score_performer::one_time_step ()
72 {
73   if (to_boolean (context ()->get_property ("skipTypesetting")))
74     {
75       if (!skipping_)
76         {
77           skip_start_mom_ = audio_column_->at_mom ();
78           skipping_ = true;
79         }
80     }
81   else
82     {
83       if (skipping_)
84         {
85           offset_mom_ -= audio_column_->at_mom () - skip_start_mom_;
86           skipping_ = false;
87         }
88
89       audio_column_->offset_at_mom (offset_mom_);
90       precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
91       do_announces ();
92     }
93
94   precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
95 }
96
97 int
98 Score_performer::get_tempo () const
99 {
100   return ::get_tempo (performance_->midi_, Moment (Rational (1, 4)));
101 }
102
103 SCM
104 Score_performer::get_output ()
105 {
106   Music_output *o = performance_;
107   performance_ = 0;
108   return o->self_scm ();
109 }
110
111 void
112 Score_performer::derived_mark () const
113 {
114   if (performance_)
115     scm_gc_mark (performance_->self_scm ());
116
117   Score_translator::derived_mark ();
118   Performer_group::derived_mark ();
119 }
120
121 void
122 Score_performer::initialize ()
123 {
124   performance_ = new Performance;
125   performance_->unprotect ();
126   performance_->midi_ = context ()->get_output_def ();
127
128   Translator_group::initialize ();
129 }