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