]> git.donarmstrong.com Git - lilypond.git/blob - lily/score.cc
release: 1.3.62
[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   if(verbose_global_b)
98     progress_indication (_f ("elapsed time: %.2f seconds",  timer.read ()));
99
100   output->header_l_ = header_p_;
101   output->origin_str_ =  location_str();
102
103   progress_indication ("\n");
104   output->process();
105   delete output ;
106
107   /*
108     force GC. At this point, GUILE may give back mallocated area to
109     the system.
110   */
111     
112   scm_gc();
113 }
114
115 void
116 Score::process()
117 {
118   if (!music_p_)
119     return;
120
121   print();
122   for (int i=0; i < def_p_arr_.size (); i++)
123     {
124       if (no_paper_global_b 
125           && dynamic_cast<Paper_def*>(def_p_arr_[i]))
126         continue;
127       run_translator (def_p_arr_[i]);
128     }
129 }
130
131
132
133 void
134 Score::print() const
135 {
136 #ifndef NPRINT
137   DEBUG_OUT << "score {\n";
138   music_p_ -> print ();
139   for (int i=0; i < def_p_arr_.size (); i++)
140     def_p_arr_[i]->print();
141   DEBUG_OUT << "}\n";
142 #endif
143 }
144
145 void
146 Score::add_output (Music_output_def *pap_p)
147 {
148   def_p_arr_.push(pap_p);
149 }