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