]> git.donarmstrong.com Git - lilypond.git/blob - lily/score.cc
ae6cf4173db1bfed7ef604a0dd868fb0ae33dcb7
[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 Score::Score (Score const &s)
39   : Input (s)
40 {
41   music_ = SCM_EOL;
42   header_p_ = 0;
43   smobify_self ();
44   
45   Music * m =unsmob_music (s.music_);
46   music_ =  m?m->clone ()->self_scm () : SCM_EOL;
47   scm_gc_unprotect_object (music_);
48   
49   for (int i=0; i < s.def_p_arr_.size (); i++)
50     def_p_arr_.push (s.def_p_arr_[i]->clone ());
51   errorlevel_i_ = s.errorlevel_i_;
52   if (s.header_p_)
53         {
54           header_p_ = (s.header_p_) ? new Scheme_hash_table (*s.header_p_): 0;
55
56           scm_gc_unprotect_object (header_p_->self_scm ());
57         }
58  
59 }
60
61 Score::~Score ()
62 {
63   
64 }
65
66 void
67 Score::run_translator (Music_output_def *odef_l)
68 {
69   Cpu_timer timer;
70
71   
72   Global_translator * trans_p = odef_l->get_global_translator_p ();
73   if (!trans_p)
74     {
75       programming_error ("no toplevel translator");
76       return ;
77     }
78   progress_indication (_ ("Interpreting music..."));
79   Music * music = unsmob_music (music_);
80   
81   trans_p->final_mom_ = music->length_mom ();
82
83
84   Music_iterator * iter = Music_iterator::static_get_iterator_p (music);
85   iter->init_translator (music, trans_p);
86
87   iter->construct_children ();
88
89   if (! iter->ok ())
90     {
91       delete iter;
92       warning (_ ("Need music in a score"));
93       errorlevel_i_ =1;
94       return ;
95     }
96
97   trans_p->start ();
98   trans_p->run_iterator_on_me (iter);
99   delete iter;
100   trans_p->finish ();
101
102   if (errorlevel_i_)
103     {
104       // should we? hampers debugging.
105       warning (_ ("Errors found/*, not processing score*/"));
106     }
107
108   Music_output * output = trans_p->get_output_p ();
109   scm_gc_unprotect_object (trans_p->self_scm ());
110   
111   if (verbose_global_b)
112     progress_indication (_f ("elapsed time: %.2f seconds",  timer.read ()));
113
114   if (!header_p_)
115     header_p_ = new Scheme_hash_table; // ugh
116   Scope bla (header_p_);
117   output->header_l_ = &bla;
118   output->origin_str_ =  location_str ();
119
120   progress_indication ("\n");
121   output->process ();
122   delete output ;
123
124   /*
125     force GC. At this point, GUILE may give back mallocated area to
126     the system.
127   */
128     
129   scm_gc ();
130 }
131
132 void
133 Score::process ()
134 {
135   if (!unsmob_music (music_))
136     return;
137
138
139   for (int i=0; i < def_p_arr_.size (); i++)
140     {
141       if (no_paper_global_b 
142           && dynamic_cast<Paper_def*> (def_p_arr_[i]))
143         continue;
144       run_translator (def_p_arr_[i]);
145     }
146 }
147
148
149
150
151 void
152 Score::add_output (Music_output_def *pap_p)
153 {
154   def_p_arr_.push (pap_p);
155 }
156
157 IMPLEMENT_SMOBS (Score);
158 IMPLEMENT_DEFAULT_EQUAL_P (Score);
159 IMPLEMENT_UNSMOB (Score, score);
160
161 SCM
162 Score::mark_smob (SCM s)
163 {
164   Score * sc = (Score*) SCM_CELL_WORD_1 (s);
165   if (sc->header_p_)
166     scm_gc_mark (sc->header_p_->self_scm ());
167   for (int i = sc->def_p_arr_.size (); i--;)
168     scm_gc_mark (sc->def_p_arr_[i]->self_scm ());
169   
170   return sc->music_;
171 }
172
173 int
174 Score::print_smob (SCM s, SCM p, scm_print_state*)
175 {
176   scm_puts ("#<Score>", p);
177
178   return 1;
179 }