2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 #include "cpu-timer.hh"
15 #include "global-context.hh"
16 #include "lily-parser.hh"
17 #include "lilypond-key.hh"
18 #include "ly-smobs.icc"
20 #include "music-iterator.hh"
22 #include "output-def.hh"
23 #include "output-def.hh"
24 #include "paper-book.hh"
25 #include "paper-score.hh"
26 #include "scm-hash.hh"
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_);
77 music_ = m ? m->clone ()->self_scm () : SCM_EOL;
78 scm_gc_unprotect_object (music_);
80 for (int i = 0, n = s.defs_.size (); i < n; i++)
81 defs_.push (s.defs_[i]->clone ());
83 header_ = ly_make_anonymous_module (false);
84 if (ly_c_module_p (s.header_))
85 ly_module_copy (header_, s.header_);
91 default_rendering (SCM music, SCM outdef,
97 SCM scaled_def = outdef;
98 SCM scaled_bookdef = book_outputdef;
100 Output_def *bpd = unsmob_output_def (book_outputdef);
103 if (bpd->c_variable ("is-paper") == SCM_BOOL_T)
105 Real scale = scm_to_double (bpd->c_variable ("outputscale"));
107 Output_def *def = scale_output_def (unsmob_output_def (outdef), scale);
108 scaled_def = def->self_scm ();
110 scaled_bookdef = scale_output_def (bpd, scale)->self_scm ();
111 unsmob_output_def (scaled_def)->parent_
112 = unsmob_output_def (scaled_bookdef);
114 scm_gc_unprotect_object (scaled_bookdef);
115 scm_gc_unprotect_object (scaled_def);
118 SCM context = ly_run_translator (music, scaled_def, key);
119 Music_output *output = unsmob_music_output (ly_format_output (context));
121 if (Paper_score *pscore = dynamic_cast<Paper_score*> (output))
123 /* ugh, this is strange, Paper_book without a Book object. */
124 Paper_book *paper_book = new Paper_book ();
125 paper_book->header_ = header;
126 paper_book->paper_ = unsmob_output_def (scaled_bookdef);
128 if (ly_c_module_p (header))
129 paper_book->add_score (header);
131 SCM systems = pscore->get_paper_systems ();
132 paper_book->add_score (systems);
134 paper_book->classic_output (ly_scm2string (outname));
135 scm_gc_unprotect_object (paper_book->self_scm ());
137 scm_gc_unprotect_object (output->self_scm ());
139 scm_remember_upto_here_1 (scaled_def);
140 scm_remember_upto_here_1 (scaled_bookdef);
144 Format score, return list of Music_output objects.
146 LAYOUTBOOK should be scaled already.
149 Score::book_rendering (Output_def *layoutbook,
150 Output_def *default_def,
151 Object_key *book_key)
156 SCM scaled_bookdef = SCM_EOL;
159 if (layoutbook && layoutbook->c_variable ("is-paper") == SCM_BOOL_T)
160 scale = scm_to_double (layoutbook->c_variable ("outputscale"));
162 SCM outputs = SCM_EOL;
163 SCM *tail = &outputs;
165 int outdef_count = defs_.size ();
167 Object_key *key = new Lilypond_general_key (book_key, user_key_, 0);
168 SCM scm_key = key->self_scm ();
169 scm_gc_unprotect_object (scm_key);
171 for (int i = 0; !i || i < outdef_count; i++)
173 Output_def *def = outdef_count ? defs_[i] : default_def;
174 SCM scaled = SCM_EOL;
176 if (def->c_variable ("is-layout") == SCM_BOOL_T)
178 def = scale_output_def (def, scale);
179 def->parent_ = layoutbook;
180 scaled = def->self_scm ();
181 scm_gc_unprotect_object (scaled);
184 /* TODO: fix or junk --no-layout. */
185 SCM context = ly_run_translator (music_, def->self_scm (), scm_key);
186 if (dynamic_cast<Global_context *> (unsmob_context (context)))
188 SCM s = ly_format_output (context);
190 *tail = scm_cons (s, SCM_EOL);
191 tail = SCM_CDRLOC(*tail);
194 scm_remember_upto_here_1 (scaled);
197 scm_remember_upto_here_1 (scm_key);
198 scm_remember_upto_here_1 (scaled_bookdef);
203 Score::set_music (SCM music, SCM parser)
206 SCM check_funcs = ly_lily_module_constant ("toplevel-music-functions");
207 for (; scm_is_pair (check_funcs); check_funcs = scm_cdr (check_funcs))
208 music = scm_call_2 (scm_car (check_funcs), music, parser);
210 if (unsmob_music (music_))
212 unsmob_music (music)->origin ()->error (_ ("already have music in score"));
213 unsmob_music (music_)->origin ()->error (_ ("this is the previous music"));
215 Music *m = unsmob_music (music);
216 if (m && to_boolean (m->get_property ("error-found")))
218 m->origin ()->error (_ ("errors found, ignoring music expression"));
220 this->error_found_ = this->error_found_ || 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