]> git.donarmstrong.com Git - lilypond.git/blob - lily/score.cc
da9c2d1da155c0fe206f45f8154f4319c1c35d34
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <iostream.h>
10
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"
24
25
26 Score::Score()
27   : Input()
28 {
29   header_p_ = 0;
30   music_p_ = 0;
31   errorlevel_i_ = 0;
32 }
33
34 Score::Score (Score const &s)
35   : Input (s)
36 {
37   music_p_ = (s.music_p_) ? s.music_p_->clone() : 0;
38   for (int i=0; i < s.def_p_arr_.size (); i++)
39     def_p_arr_.push(s.def_p_arr_[i]->clone());
40   errorlevel_i_ = s.errorlevel_i_;
41   header_p_ =  (s.header_p_) ? new Scope (*s.header_p_): 0;
42 }
43
44 Score::~Score()
45 {
46   delete header_p_;
47   junk_pointer_array (def_p_arr_);
48   delete music_p_;
49 }
50
51 void
52 Score::run_translator (Music_output_def *odef_l)
53 {
54   Cpu_timer timer;
55
56   
57   Global_translator * trans_p = odef_l->get_global_translator_p();
58   if (!trans_p)
59     {
60       non_fatal_error (_("no toplevel translator"));
61       return ;
62     }
63   progress_indication ("\n" + _("Interpreting music..."));
64   trans_p->final_mom_ = music_p_->length_mom ();
65
66
67   Music_iterator * iter = Music_iterator::static_get_iterator_p (music_p_);
68   iter->init_translator(music_p_, trans_p);
69
70   iter->construct_children();
71
72   if (! iter->ok())
73     {
74       delete iter;
75       warning (_("Need music in a score"));
76       errorlevel_i_ =1;
77       return ;
78     }
79
80   trans_p->start ();
81   trans_p->run_iterator_on_me (iter);
82   delete iter;
83   trans_p->finish ();
84
85   if (errorlevel_i_)
86     {
87       // should we? hampers debugging.
88       warning (_ ("Errors found/*, not processing score*/"));
89     }
90
91   Music_output * output = trans_p->get_output_p();
92   delete trans_p;
93   progress_indication (_f ("elapsed time: %.2f seconds",  timer.read ()));
94
95   output->header_l_ = header_p_;
96   output->origin_str_ =  location_str();
97
98   progress_indication ("\n");
99   output->process();
100   delete output ;
101
102   /*
103     force GC. At this point, GUILE may give back mallocated area to
104     the system.
105   */
106     
107   scm_gc();
108 }
109
110 void
111 Score::process()
112 {
113   if (!music_p_)
114     return;
115
116   print();
117   for (int i=0; i < def_p_arr_.size (); i++)
118     {
119       if (no_paper_global_b 
120           && dynamic_cast<Paper_def*>(def_p_arr_[i]))
121         continue;
122       run_translator (def_p_arr_[i]);
123     }
124 }
125
126
127
128 void
129 Score::print() const
130 {
131 #ifndef NPRINT
132   DEBUG_OUT << "score {\n";
133   music_p_ -> print ();
134   for (int i=0; i < def_p_arr_.size (); i++)
135     def_p_arr_[i]->print();
136   DEBUG_OUT << "}\n";
137 #endif
138 }
139
140 void
141 Score::add_output (Music_output_def *pap_p)
142 {
143   def_p_arr_.push(pap_p);
144 }