2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
15 #include "cpu-timer.hh"
16 #include "global-context.hh"
17 #include "lily-parser.hh"
18 #include "lilypond-key.hh"
21 #include "output-def.hh"
22 #include "paper-book.hh"
23 #include "paper-score.hh"
27 #include "ly-smobs.icc"
43 IMPLEMENT_SMOBS (Score);
44 IMPLEMENT_DEFAULT_EQUAL_P (Score);
45 IMPLEMENT_TYPE_P (Score, "ly:score?");
48 Score::mark_smob (SCM s)
50 Score *sc = (Score *) SCM_CELL_WORD_1 (s);
52 scm_gc_mark (sc->header_);
53 scm_gc_mark (sc->texts_);
54 for (int 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)
73 error_found_ = s.error_found_;
76 Music *m = unsmob_music (s.music_);
79 Music *mclone = m->clone ();
80 music_ = mclone->unprotect ();
85 for (int i = 0, n = s.defs_.size (); i < n; i++)
87 Output_def *copy = s.defs_[i]->clone ();
91 header_ = ly_make_anonymous_module (false);
92 if (ly_is_module (s.header_))
93 ly_module_copy (header_, s.header_);
99 default_rendering (SCM music, SCM outdef,
105 SCM scaled_def = outdef;
106 SCM scaled_bookdef = book_outputdef;
108 Output_def *bpd = unsmob_output_def (book_outputdef);
111 if (bpd->c_variable ("is-paper") == SCM_BOOL_T)
113 Real scale = scm_to_double (bpd->c_variable ("outputscale"));
115 Output_def *def = scale_output_def (unsmob_output_def (outdef), scale);
116 Output_def *bdef = scale_output_def (bpd, scale);
119 scaled_def = def->self_scm ();
120 scaled_bookdef = bdef->self_scm ();
126 SCM context = ly_run_translator (music, scaled_def, key);
128 SCM output_as_scm = ly_format_output (context);
129 Music_output *output = unsmob_music_output (output_as_scm);
131 if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
133 /* ugh, this is strange, Paper_book without a Book object. */
134 Paper_book *paper_book = new Paper_book ();
135 paper_book->header_ = header;
136 paper_book->paper_ = unsmob_output_def (scaled_bookdef);
138 if (ly_is_module (header))
139 paper_book->add_score (header);
141 SCM systems = pscore->get_paper_systems ();
142 paper_book->add_score (systems);
144 paper_book->classic_output (outname);
145 paper_book->unprotect ();
148 scm_remember_upto_here_1 (scaled_def);
149 scm_remember_upto_here_1 (output_as_scm);
150 scm_remember_upto_here_1 (scaled_bookdef);
154 Format score, return list of Music_output objects.
156 LAYOUTBOOK should be scaled already.
159 Score::book_rendering (Output_def *layoutbook,
160 Output_def *default_def,
161 Object_key *book_key)
166 SCM scaled_bookdef = SCM_EOL;
169 if (layoutbook && layoutbook->c_variable ("is-paper") == SCM_BOOL_T)
170 scale = scm_to_double (layoutbook->c_variable ("outputscale"));
172 SCM outputs = SCM_EOL;
173 SCM *tail = &outputs;
175 int outdef_count = defs_.size ();
177 Object_key *key = new Lilypond_general_key (book_key, user_key_, 0);
178 SCM scm_key = key->unprotect ();
180 for (int i = 0; !i || i < outdef_count; i++)
182 Output_def *def = outdef_count ? defs_[i] : default_def;
183 SCM scaled = SCM_EOL;
185 if (def->c_variable ("is-layout") == SCM_BOOL_T)
187 def = scale_output_def (def, scale);
188 def->parent_ = layoutbook;
190 scaled = def->unprotect ();
193 /* TODO: fix or junk --no-layout. */
194 SCM context = ly_run_translator (music_, def->self_scm (), scm_key);
195 if (dynamic_cast<Global_context *> (unsmob_context (context)))
197 SCM s = ly_format_output (context);
199 *tail = scm_cons (s, SCM_EOL);
200 tail = SCM_CDRLOC (*tail);
203 scm_remember_upto_here_1 (scaled);
206 scm_remember_upto_here_1 (scm_key);
207 scm_remember_upto_here_1 (scaled_bookdef);
212 Score::set_music (SCM music)
214 if (unsmob_music (music_))
216 unsmob_music (music)->origin ()->error (_ ("already have music in score"));
217 unsmob_music (music_)->origin ()->error (_ ("this is the previous music"));
219 Music *m = unsmob_music (music);
220 if (m && to_boolean (m->get_property ("error-found")))
222 m->origin ()->error (_ ("errors found, ignoring music expression"));
224 this->error_found_ = this->error_found_
225 || to_boolean (m->get_property ("error-found"));
228 if (this->error_found_)
229 this->music_ = SCM_EOL;
231 this->music_ = music;
235 Score::get_music () const