]> git.donarmstrong.com Git - lilypond.git/blob - lily/score.cc
release: 1.5.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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "ly-smobs.icc"
10
11 #include "score.hh"
12 #include "debug.hh"
13 #include "music-output-def.hh"
14 #include "music-output.hh"
15 #include "music-iterator.hh"
16 #include "music.hh"
17 #include "global-translator.hh"
18 #include "scm-hash.hh"
19 #include "cpu-timer.hh"
20 #include "main.hh"
21 #include "paper-def.hh"
22
23
24 /*
25   TODO: junkme.
26  */
27
28 Score::Score ()
29   : Input ()
30 {
31   header_p_ = 0;
32   music_ = SCM_EOL;
33   errorlevel_i_ = 0;
34
35   smobify_self ();
36 }
37
38 /*
39   store point & click locations.
40   Global to save some time. (Sue us!)
41  */
42 bool store_locations_global_b;
43
44 Score::Score (Score const &s)
45   : Input (s)
46 {
47   music_ = SCM_EOL;
48   header_p_ = 0;
49   smobify_self ();
50
51   Music * m =unsmob_music (s.music_);
52   music_ =  m?m->clone ()->self_scm () : SCM_EOL;
53   scm_gc_unprotect_object (music_);
54   
55   for (int i=0; i < s.def_p_arr_.size (); i++)
56     def_p_arr_.push (s.def_p_arr_[i]->clone ());
57   errorlevel_i_ = s.errorlevel_i_;
58   if (s.header_p_)
59     {
60       header_p_ = (s.header_p_) ? new Scheme_hash_table (*s.header_p_): 0;
61
62       scm_gc_unprotect_object (header_p_->self_scm ());
63     }
64 }
65
66 Score::~Score ()
67 {
68   
69 }
70
71 void
72 Score::run_translator (Music_output_def *odef_l)
73 {
74   /*
75     We want to know if we want to store locations, since they take a
76     lot of overhead.
77     
78    */
79   store_locations_global_b = (gh_eval_str ("point-and-click") !=  SCM_BOOL_F);
80
81   
82   Cpu_timer timer;
83
84   
85   Global_translator * trans_p = odef_l->get_global_translator_p ();
86   if (!trans_p)
87     {
88       programming_error ("no toplevel translator");
89       return ;
90     }
91   progress_indication (_ ("Interpreting music..."));
92   Music * music = unsmob_music (music_);
93   
94   trans_p->final_mom_ = music->length_mom ();
95
96
97   Music_iterator * iter = Music_iterator::static_get_iterator_p (music);
98   iter->init_translator (music, trans_p);
99
100   iter->construct_children ();
101
102   if (! iter->ok ())
103     {
104       delete iter;
105       warning (_ ("Need music in a score"));
106       errorlevel_i_ =1;
107       return ;
108     }
109
110   trans_p->start ();
111   trans_p->run_iterator_on_me (iter);
112   delete iter;
113   trans_p->finish ();
114
115   if (errorlevel_i_)
116     {
117       // should we? hampers debugging.
118       warning (_ ("Errors found/*, not processing score*/"));
119     }
120
121   Music_output * output = trans_p->get_output_p ();
122   scm_gc_unprotect_object (trans_p->self_scm ());
123   
124   if (verbose_global_b)
125     progress_indication (_f ("elapsed time: %.2f seconds",  timer.read ()));
126
127   if (!header_p_)
128     header_p_ = new Scheme_hash_table; // ugh
129
130   output->header_l_ = header_p_;
131   output->origin_str_ =  location_str ();
132
133   progress_indication ("\n");
134   output->process ();
135   delete output ;
136
137   /*
138     force GC. At this point, GUILE may give back mallocated area to
139     the system.
140   */
141     
142   scm_gc ();
143 }
144
145 void
146 Score::process ()
147 {
148   if (!unsmob_music (music_))
149     return;
150
151
152   for (int i=0; i < def_p_arr_.size (); i++)
153     {
154       if (no_paper_global_b 
155           && dynamic_cast<Paper_def*> (def_p_arr_[i]))
156         continue;
157       run_translator (def_p_arr_[i]);
158     }
159 }
160
161
162
163
164 void
165 Score::add_output (Music_output_def *pap_p)
166 {
167   def_p_arr_.push (pap_p);
168 }
169
170 IMPLEMENT_SMOBS (Score);
171 IMPLEMENT_DEFAULT_EQUAL_P (Score);
172
173
174 SCM
175 Score::mark_smob (SCM s)
176 {
177   Score * sc = (Score*) SCM_CELL_WORD_1 (s);
178   if (sc->header_p_)
179     scm_gc_mark (sc->header_p_->self_scm ());
180   for (int i = sc->def_p_arr_.size (); i--;)
181     scm_gc_mark (sc->def_p_arr_[i]->self_scm ());
182   
183   return sc->music_;
184 }
185
186 int
187 Score::print_smob (SCM , SCM p, scm_print_state*)
188 {
189   scm_puts ("#<Score>", p);
190
191   return 1;
192 }