]> git.donarmstrong.com Git - lilypond.git/blob - lily/score.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[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 void
76 Score::run_translator (Music_output_def *odef)
77 {
78   /*
79     We want to know if we want to store locations, since they take a
80     lot of overhead.
81   */
82   store_locations_global_b = (gh_eval_str ("point-and-click") !=  SCM_BOOL_F);
83   
84   Cpu_timer timer;
85   Global_translator * trans = odef->get_global_translator ();
86   if (!trans)
87     {
88       programming_error ("no toplevel translator");
89       return ;
90     }
91   progress_indication (_ ("Interpreting music..."));
92   Music * music = unsmob_music (music_);
93   
94   trans->final_mom_ = music->length_mom ();
95   SCM protected_iter =  Music_iterator::get_static_get_iterator (music);
96   Music_iterator * iter = unsmob_iterator (protected_iter);
97   iter->init_translator (music, trans);
98
99   iter->construct_children ();
100
101   if (! iter->ok ())
102     {
103       warning (_ ("Need music in a score"));
104       errorlevel_ =1;
105       return ;
106     }
107
108   trans->start ();
109   trans->run_iterator_on_me (iter);
110   iter->quit();
111   scm_remember_upto_here_1 (protected_iter);
112   trans->finish ();
113
114   if (errorlevel_)
115     {
116       // should we? hampers debugging.
117       warning (_ ("Errors found/*, not processing score*/"));
118     }
119
120   Music_output * output = trans->get_output ();
121   scm_gc_unprotect_object (trans->self_scm ());
122   
123   if (verbose_global_b)
124     progress_indication (_f ("elapsed time: %.2f seconds",  timer.read ()));
125
126   if (!header_)
127     header_ = new Scheme_hash_table; // ugh
128
129   output->header_ = header_;
130   output->origin_string_ =  location_string ();
131
132   progress_indication ("\n");
133   output->process ();
134   
135   delete output ;
136 }
137
138 void
139 Score::process ()
140 {
141   if (!unsmob_music (music_))
142     return;
143
144   for (int i=0; i < defs_.size (); i++)
145     {
146       if (no_paper_global_b 
147           && dynamic_cast<Paper_def*> (defs_[i]))
148         continue;
149       run_translator (defs_[i]);
150     }
151 }
152
153
154 void
155 Score::add_output (Music_output_def *pap)
156 {
157   defs_.push (pap);
158 }
159
160 IMPLEMENT_SMOBS (Score);
161 IMPLEMENT_DEFAULT_EQUAL_P (Score);
162
163
164 SCM
165 Score::mark_smob (SCM s)
166 {
167   Score * sc = (Score*) SCM_CELL_WORD_1 (s);
168   if (sc->header_)
169     scm_gc_mark (sc->header_->self_scm ());
170   for (int i = sc->defs_.size (); i--;)
171     scm_gc_mark (sc->defs_[i]->self_scm ());
172   
173   return sc->music_;
174 }
175
176 int
177 Score::print_smob (SCM , SCM p, scm_print_state*)
178 {
179   scm_puts ("#<Score>", p);
180
181   return 1;
182 }