Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / score.cc
blobac79dd103fc656988ca26906a7ee2ae2b5f17e83
1 /*
2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "score.hh"
11 #include <cstdio>
13 using namespace std;
15 #include "book.hh"
16 #include "cpu-timer.hh"
17 #include "global-context.hh"
18 #include "international.hh"
19 #include "lily-parser.hh"
20 #include "main.hh"
21 #include "music.hh"
22 #include "music.hh"
23 #include "output-def.hh"
24 #include "paper-book.hh"
25 #include "paper-score.hh"
26 #include "warn.hh"
28 #include "ly-smobs.icc"
30 Input *
31 Score::origin () const
33 return unsmob_input (input_location_);
37 Score::Score ()
39 header_ = SCM_EOL;
40 music_ = SCM_EOL;
41 input_location_ = SCM_EOL;
43 error_found_ = false;
45 smobify_self ();
46 input_location_ = make_input (Input ());
49 Score::~Score ()
53 IMPLEMENT_SMOBS (Score);
54 IMPLEMENT_DEFAULT_EQUAL_P (Score);
55 IMPLEMENT_TYPE_P (Score, "ly:score?");
57 SCM
58 Score::mark_smob (SCM s)
60 Score *sc = (Score *) SCM_CELL_WORD_1 (s);
62 scm_gc_mark (sc->header_);
63 for (vsize i = sc->defs_.size (); i--;)
64 scm_gc_mark (sc->defs_[i]->self_scm ());
66 scm_gc_mark (sc->input_location_);
67 return sc->music_;
70 int
71 Score::print_smob (SCM, SCM p, scm_print_state*)
73 scm_puts ("#<Score>", p);
75 return 1;
78 Score::Score (Score const &s)
80 header_ = SCM_EOL;
81 music_ = SCM_EOL;
82 input_location_ = SCM_EOL;
83 error_found_ = s.error_found_;
85 smobify_self ();
86 input_location_ = make_input (*s.origin ());
88 Music *m = unsmob_music (s.music_);
89 if (m)
91 Music *mclone = m->clone ();
92 music_ = mclone->unprotect ();
94 else
95 music_ = SCM_EOL;
97 for (vsize i = 0, n = s.defs_.size (); i < n; i++)
99 Output_def *copy = s.defs_[i]->clone ();
100 defs_.push_back (copy);
101 copy->unprotect ();
103 header_ = ly_make_anonymous_module (false);
104 if (ly_is_module (s.header_))
105 ly_module_copy (header_, s.header_);
110 Format score, return list of Music_output objects.
112 LAYOUTBOOK should be scaled already.
115 Score::book_rendering (Output_def *layoutbook,
116 Output_def *default_def)
118 if (error_found_)
119 return SCM_EOL;
121 SCM scaled_bookdef = SCM_EOL;
122 Real scale = 1.0;
124 if (layoutbook && layoutbook->c_variable ("is-paper") == SCM_BOOL_T)
125 scale = scm_to_double (layoutbook->c_variable ("output-scale"));
127 SCM outputs = SCM_EOL;
128 SCM *tail = &outputs;
130 int outdef_count = defs_.size ();
132 for (int i = 0; !i || i < outdef_count; i++)
134 Output_def *def = outdef_count ? defs_[i] : default_def;
135 SCM scaled = SCM_EOL;
137 if (def->c_variable ("is-layout") == SCM_BOOL_T)
139 def = scale_output_def (def, scale);
140 def->parent_ = layoutbook;
142 scaled = def->unprotect ();
145 /* TODO: fix or junk --no-layout. */
146 SCM context = ly_run_translator (music_, def->self_scm ());
147 if (dynamic_cast<Global_context *> (unsmob_context (context)))
149 SCM s = ly_format_output (context);
151 *tail = scm_cons (s, SCM_EOL);
152 tail = SCM_CDRLOC (*tail);
155 scm_remember_upto_here_1 (scaled);
158 scm_remember_upto_here_1 (scaled_bookdef);
159 return outputs;
162 void
163 Score::set_music (SCM music)
165 if (unsmob_music (music_))
167 unsmob_music (music)->origin ()->error (_ ("already have music in score"));
168 unsmob_music (music_)->origin ()->error (_ ("this is the previous music"));
170 Music *m = unsmob_music (music);
171 if (m && to_boolean (m->get_property ("error-found")))
173 m->origin ()->error (_ ("errors found, ignoring music expression"));
175 this->error_found_ = this->error_found_
176 || to_boolean (m->get_property ("error-found"));
179 if (this->error_found_)
180 this->music_ = SCM_EOL;
181 else
182 this->music_ = music;
186 Score::get_music () const
188 return music_;
191 void
192 Score::add_output_def (Output_def *def)
194 defs_.push_back (def);
198 Score::get_header () const
200 return header_;
203 void
204 Score::set_header (SCM module)
206 assert (ly_is_module (module));
207 header_ = module;