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_);
111 Format score, return list of Music_output objects.
113 LAYOUTBOOK should be scaled already.
116 Score::book_rendering (Output_def *layoutbook,
117 Output_def *default_def,
118 Object_key *book_key)
123 SCM scaled_bookdef = SCM_EOL;
126 if (layoutbook && layoutbook->c_variable ("is-paper") == SCM_BOOL_T)
127 scale = scm_to_double (layoutbook->c_variable ("output-scale"));
129 SCM outputs = SCM_EOL;
130 SCM *tail = &outputs;
132 int outdef_count = defs_.size ();
134 Object_key *key = new Lilypond_general_key (book_key, user_key_, 0);
135 SCM scm_key = key->unprotect ();
137 for (int i = 0; !i || i < outdef_count; i++)
139 Output_def *def = outdef_count ? defs_[i] : default_def;
140 SCM scaled = SCM_EOL;
142 if (def->c_variable ("is-layout") == SCM_BOOL_T)
144 def = scale_output_def (def, scale);
145 def->parent_ = layoutbook;
147 scaled = def->unprotect ();
150 /* TODO: fix or junk --no-layout. */
151 SCM context = ly_run_translator (music_, def->self_scm (), scm_key);
152 if (dynamic_cast<Global_context *> (unsmob_context (context)))
154 SCM s = ly_format_output (context);
156 *tail = scm_cons (s, SCM_EOL);
157 tail = SCM_CDRLOC (*tail);
160 scm_remember_upto_here_1 (scaled);
163 scm_remember_upto_here_1 (scm_key);
164 scm_remember_upto_here_1 (scaled_bookdef);
169 Score::set_music (SCM music)
171 if (unsmob_music (music_))
173 unsmob_music (music)->origin ()->error (_ ("already have music in score"));
174 unsmob_music (music_)->origin ()->error (_ ("this is the previous music"));
176 Music *m = unsmob_music (music);
177 if (m && to_boolean (m->get_property ("error-found")))
179 m->origin ()->error (_ ("errors found, ignoring music expression"));
181 this->error_found_ = this->error_found_
182 || to_boolean (m->get_property ("error-found"));
185 if (this->error_found_)
186 this->music_ = SCM_EOL;
188 this->music_ = music;
192 Score::get_music () const
198 Score::add_output_def (Output_def *def)
200 defs_.push_back (def);