]> git.donarmstrong.com Git - lilypond.git/blob - lily/score.cc
(mark_smob): bugfix.
[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--2003 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 #include "ly-modules.hh"
25
26
27
28 /*
29   TODO: junkme.
30  */
31 Score::Score ()
32   : Input ()
33 {
34   input_file_ = 0;
35   header_ = SCM_EOL;
36   music_ = SCM_EOL;
37   errorlevel_ = 0;
38
39   smobify_self ();
40 }
41
42 /*
43   store point & click locations.
44   Global to save some time. (Sue us!)
45  */
46 bool store_locations_global_b;
47
48 Score::Score (Score const &s)
49   : Input (s)
50 {
51   music_ = SCM_EOL;
52   header_ = 0;
53   smobify_self ();
54
55   Music * m =unsmob_music (s.music_);
56   music_ =  m?m->clone ()->self_scm () : SCM_EOL;
57   scm_gc_unprotect_object (music_);
58   
59   for (int i=0; i < s.defs_.size (); i++)
60     defs_.push (s.defs_[i]->clone ());
61   errorlevel_ = s.errorlevel_;
62
63   header_ = ly_make_anonymous_module ();
64   if (ly_module_p (s.header_))
65     ly_copy_module_variables (header_, s.header_);
66 }
67
68 Score::~Score ()
69 {
70   
71 }
72
73
74
75 void
76 Score::run_translator (Music_output_def *odef)
77 {
78    Cpu_timer timer;
79   Global_translator * trans = odef->get_global_translator ();
80   if (!trans)
81     {
82       programming_error ("no toplevel translator");
83       return ;
84     }
85   progress_indication (_ ("Interpreting music..."));
86   Music * music = unsmob_music (music_);
87   
88   trans->final_mom_ = music->get_length ();
89   SCM protected_iter =  Music_iterator::get_static_get_iterator (music);
90   Music_iterator * iter = unsmob_iterator (protected_iter);
91   iter->init_translator (music, trans);
92
93   iter->construct_children ();
94
95   if (! iter->ok ())
96     {
97       warning (_ ("Need music in a score"));
98       errorlevel_ =1;
99       return ;
100     }
101
102   trans->start ();
103   trans->run_iterator_on_me (iter);
104   iter->quit();
105   scm_remember_upto_here_1 (protected_iter);
106   trans->finish ();
107
108   if (errorlevel_)
109     {
110       // should we? hampers debugging.
111       warning (_ ("Errors found/*, not processing score*/"));
112     }
113
114   Music_output * output = trans->get_output ();
115   scm_gc_unprotect_object (trans->self_scm ());
116   
117   if (verbose_global_b)
118     progress_indication (_f ("elapsed time: %.2f seconds",  timer.read ()));
119
120   if (!header_)
121     header_ = ly_make_anonymous_module(); // ug.h
122
123   output->header_ = header_;
124   output->origin_string_ =  location_string ();
125
126   progress_indication ("\n");
127   output->process ();
128   
129   delete output ;
130 }
131
132 void
133 Score::process ()
134 {
135   if (!unsmob_music (music_))
136     return;
137
138   for (int i=0; i < defs_.size (); i++)
139     {
140       if (no_paper_global_b 
141           && dynamic_cast<Paper_def*> (defs_[i]))
142         continue;
143       run_translator (defs_[i]);
144     }
145 }
146
147
148 void
149 Score::add_output (Music_output_def *pap)
150 {
151   defs_.push (pap);
152 }
153
154 IMPLEMENT_SMOBS (Score);
155 IMPLEMENT_DEFAULT_EQUAL_P (Score);
156
157
158 SCM
159 Score::mark_smob (SCM s)
160 {
161   Score * sc = (Score*) SCM_CELL_WORD_1 (s);
162
163   if (sc->header_)
164     scm_gc_mark (sc->header_);
165   for (int i = sc->defs_.size (); i--;)
166     scm_gc_mark (sc->defs_[i]->self_scm ());
167   
168   return sc->music_;
169 }
170
171 int
172 Score::print_smob (SCM , SCM p, scm_print_state*)
173 {
174   scm_puts ("#<Score>", p);
175
176   return 1;
177 }