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"
44 IMPLEMENT_SMOBS (Score);
45 IMPLEMENT_DEFAULT_EQUAL_P (Score);
46 IMPLEMENT_TYPE_P (Score, "ly:score?");
49 Score::mark_smob (SCM s)
51 Score *sc = (Score *) SCM_CELL_WORD_1 (s);
53 scm_gc_mark (sc->header_);
54 for (vsize i = sc->defs_.size (); i--;)
55 scm_gc_mark (sc->defs_[i]->self_scm ());
60 Score::print_smob (SCM, SCM p, scm_print_state*)
62 scm_puts ("#<Score>", p);
67 Score::Score (Score const &s)
72 error_found_ = s.error_found_;
75 Music *m = unsmob_music (s.music_);
78 Music *mclone = m->clone ();
79 music_ = mclone->unprotect ();
84 for (vsize i = 0, n = s.defs_.size (); i < n; i++)
86 Output_def *copy = s.defs_[i]->clone ();
87 defs_.push_back (copy);
90 header_ = ly_make_anonymous_module (false);
91 if (ly_is_module (s.header_))
92 ly_module_copy (header_, s.header_);
96 default_rendering (SCM music, SCM outdef,
102 SCM scaled_def = outdef;
103 SCM scaled_bookdef = book_outputdef;
105 Output_def *bpd = unsmob_output_def (book_outputdef);
108 if (bpd->c_variable ("is-paper") == SCM_BOOL_T)
110 Real scale = scm_to_double (bpd->c_variable ("output-scale"));
112 Output_def *def = scale_output_def (unsmob_output_def (outdef), scale);
113 Output_def *bdef = scale_output_def (bpd, scale);
116 scaled_def = def->self_scm ();
117 scaled_bookdef = bdef->self_scm ();
123 SCM context = ly_run_translator (music, scaled_def, key);
125 SCM output_as_scm = ly_format_output (context);
126 Music_output *output = unsmob_music_output (output_as_scm);
128 if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
130 /* ugh, this is strange, Paper_book without a Book object. */
131 Paper_book *paper_book = new Paper_book ();
132 paper_book->header_ = header;
133 paper_book->paper_ = unsmob_output_def (scaled_bookdef);
135 if (ly_is_module (header))
136 paper_book->add_score (header);
138 paper_book->add_score (pscore->self_scm ());
139 paper_book->classic_output (outname);
140 paper_book->unprotect ();
143 scm_remember_upto_here_1 (scaled_def);
144 scm_remember_upto_here_1 (output_as_scm);
145 scm_remember_upto_here_1 (scaled_bookdef);
149 Format score, return list of Music_output objects.
151 LAYOUTBOOK should be scaled already.
154 Score::book_rendering (Output_def *layoutbook,
155 Output_def *default_def,
156 Object_key *book_key)
161 SCM scaled_bookdef = SCM_EOL;
164 if (layoutbook && layoutbook->c_variable ("is-paper") == SCM_BOOL_T)
165 scale = scm_to_double (layoutbook->c_variable ("output-scale"));
167 SCM outputs = SCM_EOL;
168 SCM *tail = &outputs;
170 int outdef_count = defs_.size ();
172 Object_key *key = new Lilypond_general_key (book_key, user_key_, 0);
173 SCM scm_key = key->unprotect ();
175 for (int i = 0; !i || i < outdef_count; i++)
177 Output_def *def = outdef_count ? defs_[i] : default_def;
178 SCM scaled = SCM_EOL;
180 if (def->c_variable ("is-layout") == SCM_BOOL_T)
182 def = scale_output_def (def, scale);
183 def->parent_ = layoutbook;
185 scaled = def->unprotect ();
188 /* TODO: fix or junk --no-layout. */
189 SCM context = ly_run_translator (music_, def->self_scm (), scm_key);
190 if (dynamic_cast<Global_context *> (unsmob_context (context)))
192 SCM s = ly_format_output (context);
194 *tail = scm_cons (s, SCM_EOL);
195 tail = SCM_CDRLOC (*tail);
198 scm_remember_upto_here_1 (scaled);
201 scm_remember_upto_here_1 (scm_key);
202 scm_remember_upto_here_1 (scaled_bookdef);
207 Score::set_music (SCM music)
209 if (unsmob_music (music_))
211 unsmob_music (music)->origin ()->error (_ ("already have music in score"));
212 unsmob_music (music_)->origin ()->error (_ ("this is the previous music"));
214 Music *m = unsmob_music (music);
215 if (m && to_boolean (m->get_property ("error-found")))
217 m->origin ()->error (_ ("errors found, ignoring music expression"));
219 this->error_found_ = this->error_found_
220 || to_boolean (m->get_property ("error-found"));
223 if (this->error_found_)
224 this->music_ = SCM_EOL;
226 this->music_ = music;
230 Score::get_music () const
236 Score::add_output_def (Output_def *def)
238 defs_.push_back (def);