2 score.cc -- implement Score
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
15 #include "paperdef.hh"
18 #include "sourcefile.hh"
19 #include "scorewalker.hh"
21 #include "midiitem.hh"
22 #include "midistream.hh"
23 #include "midicolumn.hh"
24 #include "midistaff.hh"
25 #include "midiwalker.hh"
30 *mlog << "\nSetting up music ..." << flush;
31 if (last() == Moment(0)) {
33 error("Need to have music in a score.", defined_ch_c_l_);
36 pscore_p_ = new PScore(paper_p_);
37 find_col(0, false)->set_breakable(); // ugh
38 find_col(last(), false)->set_breakable();
42 for (iter_top(staffs_,i); i.ok(); i++) {
43 i->set_output(pscore_p_);
50 Score::process_music()
52 *mlog << "Processing music ..." << flush;
53 for (Score_walker w(this); w.ok(); w++) {
65 // do this after processing, staffs first have to generate PCols.
77 Remove empty cols, preprocess other columns.
82 for (iter_top(staffs_,i); i.ok(); i++)
85 for (iter_top(cols_,c); c.ok(); ) {
86 if (!c->pcol_l_->used()) {
96 Create columns at time #w#.
97 this sux. We should have Score_column create the appropriate PCol.
98 Unfortunately, PCols don't know about their position.
100 @return cursor pointing to the nonmusical (first) column
102 PCursor<Score_column*>
103 Score::create_cols(Moment w)
105 Score_column* c1 = new Score_column(w);
106 Score_column* c2 = new Score_column(w);
108 c1->musical_b_ = false;
109 c2->musical_b_ = true;
113 for (; i.ok(); i++) {
114 assert(i->when() != w);
120 cols_.bottom().add(c1);
121 cols_.bottom().add(c2);
132 PCursor<Score_column*>
133 Score::find_col(Moment w, bool mus)
137 for (; i.ok(); i++) {
138 if (i->when() == w && i->musical_b_ == mus)
153 for (; i.ok(); i++) {
154 pscore_p_->add(i->pcol_l_);
156 clean_cols(); // can't move clean_cols() farther up.
163 for (iter_top(staffs_,i); i.ok(); i++) {
170 Score::set(Mididef* midi_p)
180 for (iter_top(staffs_,i); i.ok(); i++) {
182 assert(i->score_l_ == this);
186 for (iter_top(cols_,cc); cc.ok() && (cc+1).ok(); cc++) {
187 assert(cc->when() <= (cc+1)->when());
198 for (iter_top(staffs_,i); i.ok(); i++) {
201 for (iter_top(cols_,i); i.ok(); i++) {
211 Score::Score(Paperdef*paper_p)
228 Score::output(String s)
231 if (paper_p_->outfile=="")
232 paper_p_->outfile = s;
234 if ( errorlevel_i_ ) {
235 *mlog << "lilypond: warning: no output to: " << paper_p_->outfile
236 << " (errorlevel=" << errorlevel_i_ << ")" << endl;
240 *mlog << "output to " << paper_p_->outfile << "...\n";
242 Tex_stream the_output(paper_p_->outfile);
244 the_output << "% outputting Score, defined at: " <<
246 sourcefile_l (defined_ch_c_l_)->file_line_no_str(defined_ch_c_l_) << "\n";
247 pscore_p_->output(the_output);
256 *mlog << "midi output to " << midi_p_->outfile_str_ << "...\n";
259 for ( PCursor<Staff*> staff_l_pcur( staffs_.top() ); staff_l_pcur.ok(); staff_l_pcur++ ) {
260 Midi_staff* mstaff_l = (Midi_staff*)*staff_l_pcur;
261 if ( !mstaff_l->pscore_l_ ) // we _are_ a midi-staff, ugh
265 Midi_stream midi_stream( midi_p_->outfile_str_, track_i, midi_p_->get_tempo_i( Moment( 1, 4 ) ) );
268 for ( PCursor<Staff*> staff_l_pcur( staffs_.top() ); staff_l_pcur.ok(); staff_l_pcur++ ) {
269 Midi_staff* mstaff_l = (Midi_staff*)*staff_l_pcur;
270 if ( !mstaff_l->pscore_l_ ) // we _are_ a midi-staff, ugh
271 mstaff_l->midi( &midi_stream, track_i++ );
279 staffs_.bottom().add(s);