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