2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
27 #include "cpu-timer.hh"
28 #include "global-context.hh"
29 #include "international.hh"
30 #include "lily-parser.hh"
34 #include "output-def.hh"
35 #include "paper-book.hh"
36 #include "paper-score.hh"
39 #include "ly-smobs.icc"
42 Score::origin () const
44 return Input::unsmob (input_location_);
51 input_location_ = SCM_EOL;
56 input_location_ = make_input (Input ());
63 IMPLEMENT_SMOBS (Score);
64 IMPLEMENT_DEFAULT_EQUAL_P (Score);
65 IMPLEMENT_TYPE_P (Score, "ly:score?");
68 Score::mark_smob (SCM s)
70 Score *sc = (Score *) SCM_CELL_WORD_1 (s);
72 scm_gc_mark (sc->header_);
73 for (vsize i = sc->defs_.size (); i--;)
74 scm_gc_mark (sc->defs_[i]->self_scm ());
76 scm_gc_mark (sc->input_location_);
81 Score::print_smob (SCM, SCM p, scm_print_state *)
83 scm_puts ("#<Score>", p);
88 Score::Score (Score const &s)
92 input_location_ = SCM_EOL;
93 error_found_ = s.error_found_;
96 input_location_ = make_input (*s.origin ());
98 Music *m = Music::unsmob (s.music_);
101 Music *mclone = m->clone ();
102 music_ = mclone->unprotect ();
107 for (vsize i = 0, n = s.defs_.size (); i < n; i++)
109 Output_def *copy = s.defs_[i]->clone ();
110 defs_.push_back (copy);
113 header_ = ly_make_module (false);
114 if (ly_is_module (s.header_))
115 ly_module_copy (header_, s.header_);
119 Format score, return list of Music_output objects.
121 LAYOUTBOOK should be scaled already.
124 Score::book_rendering (Output_def *layoutbook,
125 Output_def *default_def)
132 if (layoutbook && layoutbook->c_variable ("is-paper") == SCM_BOOL_T)
133 scale = scm_to_double (layoutbook->c_variable ("output-scale"));
135 SCM outputs = SCM_EOL;
137 int outdef_count = defs_.size ();
139 for (int i = 0; !i || i < outdef_count; i++)
141 Output_def *def = outdef_count ? defs_[i] : default_def;
142 SCM scaled = def->self_scm ();
144 if (def->c_variable ("is-layout") == SCM_BOOL_T)
146 def = scale_output_def (def, scale);
147 def->parent_ = layoutbook;
149 scaled = def->unprotect ();
152 /* TODO: fix or junk --no-layout. */
153 SCM context = ly_run_translator (music_, scaled);
154 if (dynamic_cast<Global_context *> (Context::unsmob (context)))
156 SCM s = ly_format_output (context);
158 outputs = scm_cons (s, outputs);
161 scm_remember_upto_here_1 (scaled);
164 return scm_reverse_x (outputs, SCM_EOL);
168 Score::set_music (SCM music)
170 if (Music::unsmob (music_))
172 Music::unsmob (music)->origin ()->error (_ ("already have music in score"));
173 Music::unsmob (music_)->origin ()->error (_ ("this is the previous music"));
175 Music *m = Music::unsmob (music);
176 if (m && to_boolean (m->get_property ("error-found")))
178 m->origin ()->error (_ ("errors found, ignoring music expression"));
180 this->error_found_ = this->error_found_
181 || to_boolean (m->get_property ("error-found"));
184 if (this->error_found_)
185 this->music_ = SCM_EOL;
187 this->music_ = music;
191 Score::get_music () const
197 Score::add_output_def (Output_def *def)
199 defs_.push_back (def);
203 Score::get_header () const
209 Score::set_header (SCM module)
211 assert (ly_is_module (module));