lilypond-0.1.12
[lilypond.git] / lily / score.cc
blob3da46e2c235f9e9318aa47616e0f0bbde2a93d25
1 /*
2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "score.hh"
10 #include "debug.hh"
11 #include "music-output-def.hh"
12 #include "music-output.hh"
13 #include "source.hh"
14 #include "source-file.hh"
15 #include "music-iterator.hh"
16 #include "music.hh"
17 #include "global-translator.hh"
18 #include "header.hh"
20 extern String default_out_fn;
22 Score::Score()
24 header_p_ = 0;
25 music_p_ = 0;
26 errorlevel_i_ = 0;
29 Score::Score (Score const &s)
31 music_p_ = s.music_p_->clone();
32 for (int i=0; i < s.def_p_arr_.size (); i++)
33 def_p_arr_.push(s.def_p_arr_[i]->clone());
34 header_p_ = new Header (*s.header_p_);
37 Score::~Score()
39 delete header_p_;
40 for (int i=0; i < def_p_arr_.size (); i++)
41 delete def_p_arr_[i];
42 delete music_p_;
45 void
46 Score::run_translator (Music_output_def *odef_l)
48 Global_translator * trans_p = odef_l->get_global_translator_p();
49 if (!trans_p)
50 return ;
52 *mlog << "\nInterpreting music ...";
53 trans_p->last_mom_ = music_p_->time_int().max ();
55 Music_iterator * iter = Music_iterator::static_get_iterator_p (music_p_,
56 trans_p);
57 iter->construct_children();
59 if (! iter->ok())
61 delete iter;
62 warning ("Need music in a score");
63 errorlevel_i_ =1;
64 return ;
67 trans_p->start();
69 while (iter->ok() || trans_p->moments_left_i ())
71 Moment w = infinity_mom;
72 if (iter->ok())
74 w = iter->next_moment();
75 DOUT << "proccing: " << w <<"\n";
76 iter->print();
78 trans_p->modify_next (w);
79 trans_p->prepare (w);
80 trans_p->print();
82 iter->process_and_next (w);
83 trans_p->process();
85 delete iter;
86 trans_p->finish();
89 if (errorlevel_i_)
91 // should we? hampers debugging.
92 warning ("Errors found, /*not processing score*/");
95 Music_output * output = trans_p->get_output_p();
96 delete trans_p;
98 output->header_l_ = header_p_;
99 output->default_out_str_ = default_out_fn;
100 output->origin_str_ = location_str();
102 *mlog << endl;
103 output->process();
104 delete output ;
107 void
108 Score::process()
110 if (!music_p_)
111 return;
113 print();
114 for (int i=0; i < def_p_arr_.size (); i++)
115 run_translator (def_p_arr_[i]);
121 void
122 Score::print() const
124 #ifndef NPRINT
125 DOUT << "score {\n";
126 for (int i=0; i < def_p_arr_.size (); i++)
127 def_p_arr_[i]->print();
128 DOUT << "}\n";
129 #endif
132 void
133 Score::add (Music_output_def *pap_p)
135 def_p_arr_.push(pap_p);