2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 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/>.
22 ADD_SMOB_INIT (Score);
29 #include "cpu-timer.hh"
30 #include "global-context.hh"
31 #include "international.hh"
32 #include "lily-parser.hh"
36 #include "output-def.hh"
37 #include "paper-book.hh"
38 #include "paper-score.hh"
43 Score::origin () const
45 return Input::unsmob (input_location_);
52 input_location_ = SCM_EOL;
57 input_location_ = Input ().smobbed_copy ();
64 const char Score::type_p_name_[] = "ly:score?";
69 scm_gc_mark (header_);
70 for (vsize i = defs_.size (); i--;)
71 scm_gc_mark (defs_[i]->self_scm ());
73 scm_gc_mark (input_location_);
77 Score::Score (Score const &s)
82 input_location_ = SCM_EOL;
83 error_found_ = s.error_found_;
86 input_location_ = s.origin ()->smobbed_copy ();
88 Music *m = Music::unsmob (s.music_);
91 Music *mclone = m->clone ();
92 music_ = mclone->unprotect ();
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);
103 header_ = ly_make_module (false);
104 if (ly_is_module (s.header_))
105 ly_module_copy (header_, s.header_);
109 Format score, return list of Music_output objects.
111 LAYOUTBOOK should be scaled already.
114 Score::book_rendering (Output_def *layoutbook,
115 Output_def *default_def)
122 if (layoutbook && to_boolean (layoutbook->c_variable ("is-paper")))
123 scale = scm_to_double (layoutbook->c_variable ("output-scale"));
125 SCM outputs = SCM_EOL;
127 int outdef_count = defs_.size ();
129 for (int i = 0; !i || i < outdef_count; i++)
131 Output_def *def = outdef_count ? defs_[i] : default_def;
132 SCM scaled = def->self_scm ();
134 if (to_boolean (def->c_variable ("is-layout")))
136 def = scale_output_def (def, scale);
137 def->parent_ = layoutbook;
139 scaled = def->unprotect ();
142 /* TODO: fix or junk --no-layout. */
143 SCM context = ly_run_translator (music_, scaled);
144 if (dynamic_cast<Global_context *> (Context::unsmob (context)))
146 SCM s = ly_format_output (context);
148 outputs = scm_cons (s, outputs);
151 scm_remember_upto_here_1 (scaled);
154 return scm_reverse_x (outputs, SCM_EOL);
158 Score::set_music (SCM music)
160 if (Music::is_smob (music_))
162 Music::unsmob (music)->origin ()->error (_ ("already have music in score"));
163 Music::unsmob (music_)->origin ()->error (_ ("this is the previous music"));
165 Music *m = Music::unsmob (music);
166 if (m && to_boolean (m->get_property ("error-found")))
168 m->origin ()->error (_ ("errors found, ignoring music expression"));
170 this->error_found_ = this->error_found_
171 || to_boolean (m->get_property ("error-found"));
174 if (this->error_found_)
175 this->music_ = SCM_EOL;
177 this->music_ = music;
181 Score::get_music () const
187 Score::add_output_def (Output_def *def)
189 defs_.push_back (def);
193 Score::get_header () const
199 Score::set_header (SCM module)
201 assert (ly_is_module (module));