lilypond-1.3.80
[lilypond.git] / lily / score.cc
blob75e397aab8a9686fdedfe48f88944e3b264a0a1a
1 /*
2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include <iostream.h>
11 #include "score.hh"
12 #include "debug.hh"
13 #include "music-output-def.hh"
14 #include "music-output.hh"
15 #include "source.hh"
16 #include "source-file.hh"
17 #include "music-iterator.hh"
18 #include "music.hh"
19 #include "global-translator.hh"
20 #include "scope.hh"
21 #include "cpu-timer.hh"
22 #include "main.hh"
23 #include "paper-def.hh"
27 TODO: junkme.
30 Score::Score()
31 : Input()
33 header_p_ = 0;
34 music_ = SCM_EOL;
35 errorlevel_i_ = 0;
38 Score::Score (Score const &s)
39 : Input (s)
41 Music * m =unsmob_music (s.music_);
42 music_ = m?m->clone()->self_scm () : SCM_EOL;
43 for (int i=0; i < s.def_p_arr_.size (); i++)
44 def_p_arr_.push(s.def_p_arr_[i]->clone());
45 errorlevel_i_ = s.errorlevel_i_;
46 header_p_ = (s.header_p_) ? new Scope (*s.header_p_): 0;
49 Score::~Score()
51 delete header_p_;
52 junk_pointer_array (def_p_arr_);
55 void
56 Score::run_translator (Music_output_def *odef_l)
58 Cpu_timer timer;
61 Global_translator * trans_p = odef_l->get_global_translator_p();
62 if (!trans_p)
64 programming_error ("no toplevel translator");
65 return ;
67 progress_indication ("\n" + _("Interpreting music..."));
68 Music * music = unsmob_music (music_);
70 trans_p->final_mom_ = music->length_mom ();
73 Music_iterator * iter = Music_iterator::static_get_iterator_p (music);
74 iter->init_translator(music, trans_p);
76 iter->construct_children();
78 if (! iter->ok())
80 delete iter;
81 warning (_("Need music in a score"));
82 errorlevel_i_ =1;
83 return ;
86 trans_p->start ();
87 trans_p->run_iterator_on_me (iter);
88 delete iter;
89 trans_p->finish ();
91 if (errorlevel_i_)
93 // should we? hampers debugging.
94 warning (_ ("Errors found/*, not processing score*/"));
97 Music_output * output = trans_p->get_output_p();
98 delete trans_p;
99 if(verbose_global_b)
100 progress_indication (_f ("elapsed time: %.2f seconds", timer.read ()));
102 output->header_l_ = header_p_;
103 output->origin_str_ = location_str();
105 progress_indication ("\n");
106 output->process();
107 delete output ;
110 force GC. At this point, GUILE may give back mallocated area to
111 the system.
114 scm_gc();
117 void
118 Score::process()
120 if (!unsmob_music (music_))
121 return;
123 print();
124 for (int i=0; i < def_p_arr_.size (); i++)
126 if (no_paper_global_b
127 && dynamic_cast<Paper_def*>(def_p_arr_[i]))
128 continue;
129 run_translator (def_p_arr_[i]);
135 void
136 Score::print() const
138 #ifndef NPRINT
139 DEBUG_OUT << "score {\n";
140 // music_p_ -> print ();
141 for (int i=0; i < def_p_arr_.size (); i++)
142 def_p_arr_[i]->print();
143 DEBUG_OUT << "}\n";
144 #endif
147 void
148 Score::add_output (Music_output_def *pap_p)
150 def_p_arr_.push(pap_p);