2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
16 #include "cpu-timer.hh"
17 #include "global-context.hh"
18 #include "international.hh"
19 #include "lily-parser.hh"
20 #include "lilypond-key.hh"
24 #include "output-def.hh"
25 #include "paper-book.hh"
26 #include "paper-score.hh"
29 #include "ly-smobs.icc"
32 Score::origin () const
34 return unsmob_input (input_location_);
42 input_location_ = SCM_EOL;
47 input_location_ = make_input (Input ());
54 IMPLEMENT_SMOBS (Score);
55 IMPLEMENT_DEFAULT_EQUAL_P (Score);
56 IMPLEMENT_TYPE_P (Score, "ly:score?");
59 Score::mark_smob (SCM s)
61 Score *sc = (Score *) SCM_CELL_WORD_1 (s);
63 scm_gc_mark (sc->header_);
64 for (vsize i = sc->defs_.size (); i--;)
65 scm_gc_mark (sc->defs_[i]->self_scm ());
67 scm_gc_mark (sc->input_location_);
72 Score::print_smob (SCM, SCM p, scm_print_state*)
74 scm_puts ("#<Score>", p);
79 Score::Score (Score const &s)
83 input_location_ = SCM_EOL;
84 error_found_ = s.error_found_;
87 input_location_ = make_input (*s.origin ());
89 Music *m = unsmob_music (s.music_);
92 Music *mclone = m->clone ();
93 music_ = mclone->unprotect ();
98 for (vsize i = 0, n = s.defs_.size (); i < n; i++)
100 Output_def *copy = s.defs_[i]->clone ();
101 defs_.push_back (copy);
104 header_ = ly_make_anonymous_module (false);
105 if (ly_is_module (s.header_))
106 ly_module_copy (header_, s.header_);
110 default_rendering (SCM music, SCM outdef,
116 SCM scaled_def = outdef;
117 SCM scaled_bookdef = book_outputdef;
119 Output_def *bpd = unsmob_output_def (book_outputdef);
122 if (bpd->c_variable ("is-paper") == SCM_BOOL_T)
124 Real scale = scm_to_double (bpd->c_variable ("output-scale"));
126 Output_def *def = scale_output_def (unsmob_output_def (outdef), scale);
127 Output_def *bdef = scale_output_def (bpd, scale);
130 scaled_def = def->self_scm ();
131 scaled_bookdef = bdef->self_scm ();
137 SCM context = ly_run_translator (music, scaled_def, key);
139 SCM output_as_scm = ly_format_output (context);
140 Music_output *output = unsmob_music_output (output_as_scm);
142 if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
144 /* ugh, this is strange, Paper_book without a Book object. */
145 Paper_book *paper_book = new Paper_book ();
146 paper_book->header_ = header;
147 paper_book->paper_ = unsmob_output_def (scaled_bookdef);
149 if (ly_is_module (header))
150 paper_book->add_score (header);
152 paper_book->add_score (pscore->self_scm ());
153 paper_book->classic_output (outname);
154 paper_book->unprotect ();
157 scm_remember_upto_here_1 (scaled_def);
158 scm_remember_upto_here_1 (output_as_scm);
159 scm_remember_upto_here_1 (scaled_bookdef);
163 Format score, return list of Music_output objects.
165 LAYOUTBOOK should be scaled already.
168 Score::book_rendering (Output_def *layoutbook,
169 Output_def *default_def,
170 Object_key *book_key)
175 SCM scaled_bookdef = SCM_EOL;
178 if (layoutbook && layoutbook->c_variable ("is-paper") == SCM_BOOL_T)
179 scale = scm_to_double (layoutbook->c_variable ("output-scale"));
181 SCM outputs = SCM_EOL;
182 SCM *tail = &outputs;
184 int outdef_count = defs_.size ();
186 Object_key *key = new Lilypond_general_key (book_key, user_key_, 0);
187 SCM scm_key = key->unprotect ();
189 for (int i = 0; !i || i < outdef_count; i++)
191 Output_def *def = outdef_count ? defs_[i] : default_def;
192 SCM scaled = SCM_EOL;
194 if (def->c_variable ("is-layout") == SCM_BOOL_T)
196 def = scale_output_def (def, scale);
197 def->parent_ = layoutbook;
199 scaled = def->unprotect ();
202 /* TODO: fix or junk --no-layout. */
203 SCM context = ly_run_translator (music_, def->self_scm (), scm_key);
204 if (dynamic_cast<Global_context *> (unsmob_context (context)))
206 SCM s = ly_format_output (context);
208 *tail = scm_cons (s, SCM_EOL);
209 tail = SCM_CDRLOC (*tail);
212 scm_remember_upto_here_1 (scaled);
215 scm_remember_upto_here_1 (scm_key);
216 scm_remember_upto_here_1 (scaled_bookdef);
221 Score::set_music (SCM music)
223 if (unsmob_music (music_))
225 unsmob_music (music)->origin ()->error (_ ("already have music in score"));
226 unsmob_music (music_)->origin ()->error (_ ("this is the previous music"));
228 Music *m = unsmob_music (music);
229 if (m && to_boolean (m->get_property ("error-found")))
231 m->origin ()->error (_ ("errors found, ignoring music expression"));
233 this->error_found_ = this->error_found_
234 || to_boolean (m->get_property ("error-found"));
237 if (this->error_found_)
238 this->music_ = SCM_EOL;
240 this->music_ = music;
244 Score::get_music () const
250 Score::add_output_def (Output_def *def)
252 defs_.push_back (def);