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