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