lilypond-1.1.67
[lilypond.git] / lily / score.cc
blobbda4e464dff910ffa9ddd293f9095a12f7fcf467
1 /*
2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.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 "scope.hh"
19 #include "cpu-timer.hh"
20 #include "main.hh"
21 #include "paper-def.hh"
24 Score::Score()
25 : Input()
27 header_p_ = 0;
28 music_p_ = 0;
29 errorlevel_i_ = 0;
32 Score::Score (Score const &s)
33 : Input (s)
35 music_p_ = (s.music_p_) ? s.music_p_->clone() : 0;
36 for (int i=0; i < s.def_p_arr_.size (); i++)
37 def_p_arr_.push(s.def_p_arr_[i]->clone());
38 errorlevel_i_ = s.errorlevel_i_;
39 header_p_ = (s.header_p_) ? new Header (*s.header_p_): 0;
42 Score::~Score()
44 delete header_p_;
45 junk_pointer_array (def_p_arr_);
46 delete music_p_;
49 void
50 Score::run_translator (Music_output_def *odef_l)
52 Cpu_timer timer;
53 Global_translator * trans_p = odef_l->get_global_translator_p();
54 if (!trans_p)
56 non_fatal_error (_("no toplevel translator"));
57 return ;
59 *mlog << '\n' << _("Interpreting music...") << flush;
60 trans_p->last_mom_ = music_p_->length_mom ();
62 Music_iterator * iter = Music_iterator::static_get_iterator_p (music_p_);
63 iter->init_translator(music_p_, trans_p);
65 iter->construct_children();
67 if (! iter->ok())
69 delete iter;
70 warning (_("need music in a score"));
71 errorlevel_i_ =1;
72 return ;
75 trans_p->start ();
76 trans_p->run_iterator_on_me (iter);
77 delete iter;
78 trans_p->finish ();
80 if (errorlevel_i_)
82 // should we? hampers debugging.
83 warning (_ ("errors found, /*not processing score*/"));
86 Music_output * output = trans_p->get_output_p();
87 delete trans_p;
88 *mlog << endl << _f ("time: %.2f seconds", timer.read ()) << flush;
90 output->header_l_ = header_p_;
91 output->origin_str_ = location_str();
93 *mlog << endl;
94 output->process();
95 delete output ;
98 void
99 Score::process()
101 if (!music_p_)
102 return;
104 print();
105 for (int i=0; i < def_p_arr_.size (); i++)
107 if (no_paper_global_b
108 && dynamic_cast<Paper_def*>(def_p_arr_[i]))
109 continue;
110 run_translator (def_p_arr_[i]);
116 void
117 Score::print() const
119 #ifndef NPRINT
120 DOUT << "score {\n";
121 music_p_ -> print ();
122 for (int i=0; i < def_p_arr_.size (); i++)
123 def_p_arr_[i]->print();
124 DOUT << "}\n";
125 #endif
128 void
129 Score::add_output (Music_output_def *pap_p)
131 def_p_arr_.push(pap_p);