]> git.donarmstrong.com Git - lilypond.git/blob - lily/score.cc
patch::: 0.1.9.jcn2: pats
[lilypond.git] / lily / score.cc
1 /*
2   score.cc -- implement Score
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "tex-stream.hh"
10 #include "score.hh"
11 #include "score-column.hh"
12 #include "p-score.hh"
13 #include "debug.hh"
14 #include "paper-def.hh"
15 #include "main.hh"
16 #include "source.hh"
17 #include "source-file.hh"
18 #include "midi-def.hh"
19 #include "midi-stream.hh"
20 #include "audio-score.hh"
21 #include "p-col.hh"
22 #include "music-iterator.hh"
23 #include "music.hh"
24 #include "global-translator.hh"
25 #include "header.hh"
26
27 extern String default_out_fn;
28
29 Score::Score()
30 {
31   header_p_ = 0;
32   music_p_ = 0;
33   pscore_p_ = 0;
34   audio_score_p_ = 0;
35   paper_p_ = 0;
36   midi_p_ = 0;
37   errorlevel_i_ = 0;
38 }
39
40 Score::Score (Score const &s)
41 {
42   assert (!pscore_p_);
43   music_p_ = s.music_p_->clone();
44   midi_p_ = new Midi_def (*s.midi_p_);
45   paper_p_ = new Paper_def (*s.paper_p_);
46   header_p_ = new Header (*s.header_p_);
47 }
48
49 Score::~Score()
50 {
51   delete header_p_;
52   delete music_p_;
53   delete pscore_p_;
54   delete audio_score_p_;
55   delete paper_p_;
56   delete midi_p_;
57 }
58
59 void
60 Score::run_translator (Global_translator * trans_l)
61 {
62   trans_l->set_score (this);
63   Music_iterator * iter = Music_iterator::static_get_iterator_p (music_p_, 
64                                                                   trans_l);
65   iter->construct_children();
66
67   if ( ! iter->ok()) 
68     {
69         delete iter;
70         warning ("Need music in a score");
71         errorlevel_i_ =1;
72         return ;
73     }
74   
75   trans_l->start();
76   
77   while ( iter->ok() || trans_l->moments_left_i ()) 
78     {
79         Moment w = infinity_mom;
80         if (iter->ok()) 
81           {
82             w = iter->next_moment();
83             DOUT << w;
84             iter->print();
85           }
86         trans_l->modify_next (w);
87         trans_l->prepare (w);
88         trans_l->print();
89
90         iter->process_and_next (w);
91         trans_l->process();
92     }
93   delete iter;
94   trans_l->finish();
95 }
96
97 void
98 Score::process()
99 {
100   print();
101   paper();
102   midi();
103 }
104
105 void
106 Score::midi()
107 {
108   if ( !midi_p_)
109         return;
110   
111   *mlog << "\nCreating MIDI elements ..." << flush;
112   audio_score_p_ = new Audio_score (this);
113   
114   Global_translator* score_trans=  midi_p_->get_global_translator_p();
115   run_translator (score_trans);
116   delete score_trans;
117   
118   if (errorlevel_i_)
119     {
120         // should we? hampers debugging. 
121         warning ("Errors found, /*not processing score*/");
122 //      return;
123     }
124   *mlog << endl;
125
126   midi_output();
127 }
128   
129 void
130 Score::paper()
131 {
132   if (!paper_p_)
133         return;
134   
135   *mlog << "\nCreating elements ..." << flush;
136   pscore_p_ = new Paper_score (paper_p_);
137   
138   Global_translator * score_trans=  paper_p_->get_global_translator_p();
139   run_translator (score_trans);
140   delete score_trans;
141   
142   if (errorlevel_i_) 
143     {
144         // should we? hampers debugging. 
145         warning ("Errors found, /*not processing score*/");
146 //      return;
147     }
148   
149   *mlog << endl;
150   pscore_p_->process();
151
152   // output
153   paper_output();
154 }
155
156 void
157 Score::midi_output()
158 {
159   if ( midi_p_->outfile_str_ == "")
160         midi_p_->outfile_str_ = default_out_fn + ".midi";
161
162   Midi_stream midi_stream (midi_p_->outfile_str_);    
163   *mlog << "MIDI output to " << midi_p_->outfile_str_ << " ..." << endl;    
164
165   audio_score_p_->output (midi_stream);
166   *mlog << endl;
167 }
168
169 void
170 Score::paper_output()
171 {
172   if (paper_p_->outfile_str_=="")
173         paper_p_->outfile_str_ = default_out_fn + ".tex";
174
175   if ( errorlevel_i_) 
176     {
177         *mlog << "lilypond: warning: no output to: " << paper_p_->outfile_str_ 
178         << " (errorlevel=" << errorlevel_i_ << ")" << endl;
179       return;
180     }
181
182   *mlog << "TeX output to " << paper_p_->outfile_str_ << " ...\n";
183   
184   Tex_stream the_output (paper_p_->outfile_str_);
185   
186   the_output << "% outputting Score, defined at: " <<
187         location_str() << "\n";
188   pscore_p_->output (the_output);
189 }
190
191 void
192 Score::print() const
193 {
194 #ifndef NPRINT
195   DOUT << "score {\n"; 
196   music_p_->print();
197   if (midi_p_)
198         midi_p_->print();
199   
200   DOUT << "}\n";
201 #endif
202 }
203
204 void
205 Score::set (Paper_def *pap_p)
206 {
207   delete paper_p_;
208   paper_p_ = pap_p;
209 }
210
211 void
212 Score::set (Midi_def* midi_p)
213 {    
214   delete midi_p_;
215   midi_p_ = midi_p;
216 }
217