2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "ly-smobs.icc"
15 #include "music-output-def.hh"
16 #include "music-output.hh"
17 #include "music-iterator.hh"
19 #include "global-translator.hh"
20 #include "scm-hash.hh"
21 #include "cpu-timer.hh"
23 #include "paper-def.hh"
24 #include "ly-modules.hh"
48 IMPLEMENT_SMOBS (Score);
49 IMPLEMENT_DEFAULT_EQUAL_P (Score);
53 Score::mark_smob (SCM s)
55 Score * sc = (Score*) SCM_CELL_WORD_1 (s);
58 scm_gc_mark (sc->header_);
59 for (int i = sc->defs_.size (); i--;)
60 scm_gc_mark (sc->defs_[i]->self_scm ());
66 Score::print_smob (SCM , SCM p, scm_print_state*)
68 scm_puts ("#<Score>", p);
76 store point & click locations.
77 Global to save some time. (Sue us!)
80 Score::Score (Score const &s)
87 Music * m =unsmob_music (s.music_);
88 music_ = m?m->clone ()->self_scm () : SCM_EOL;
89 scm_gc_unprotect_object (music_);
91 for (int i=0; i < s.defs_.size (); i++)
92 defs_.push (s.defs_[i]->clone ());
94 header_ = ly_make_anonymous_module ();
95 if (ly_module_p (s.header_))
96 ly_copy_module_variables (header_, s.header_);
101 LY_DEFINE(ly_run_translator, "ly:run-translator",
103 (SCM mus, SCM output_def),
104 "Process @var{mus} according to @var{output_def}. A interpretation "
105 "context is set up, and @var{mus} is interpreted with it. The "
106 "context is returned in its final state." )
108 Music_output_def *odef = unsmob_music_output_def (output_def);
109 Music * music = unsmob_music (mus);
111 SCM_ASSERT_TYPE (music, mus, SCM_ARG1, __FUNCTION__, "Music");
112 SCM_ASSERT_TYPE (odef, output_def, SCM_ARG2, __FUNCTION__, "Output definition");
115 Global_translator * trans = odef->get_global_translator ();
118 programming_error ("no toplevel translator");
121 progress_indication (_ ("Interpreting music..."));
123 trans->final_mom_ = music->get_length ();
124 SCM protected_iter = Music_iterator::get_static_get_iterator (music);
125 Music_iterator * iter = unsmob_iterator (protected_iter);
126 iter->init_translator (music, trans);
128 iter->construct_children ();
132 warning (_ ("Need music in a score"));
133 return SCM_BOOL_F; // todo: shoudl throw exception.
137 trans->run_iterator_on_me (iter);
139 scm_remember_upto_here_1 (protected_iter);
142 if (verbose_global_b)
143 progress_indication (_f ("elapsed time: %.2f seconds", timer.read ()));
146 return scm_gc_unprotect_object (trans->self_scm ());
150 LY_DEFINE(ly_render_output, "ly:render-output",
152 (SCM context, SCM header, SCM out_filename),
153 "Given a Score context in its final state, calculate the output, "
154 "and dump the result to @var{out-filename}, using "
155 "@var{header} for the bibliographic information.")
157 Translator *tr = unsmob_translator (context);
158 Global_translator * gt = dynamic_cast<Global_translator*> (tr);
160 SCM_ASSERT_TYPE(gt, context, SCM_ARG1, __FUNCTION__,
162 SCM_ASSERT_TYPE(ly_module_p(header), header, SCM_ARG2, __FUNCTION__,
164 SCM_ASSERT_TYPE(gh_string_p (out_filename), out_filename, SCM_ARG3, __FUNCTION__,
167 Music_output * output = gt->get_output ();
169 output->header_ = header;
171 progress_indication ("\n");
172 output->process (ly_scm2string (out_filename));
176 return SCM_UNDEFINED ;
180 default_rendering (SCM mus, SCM outdef, SCM head, SCM outname)
182 SCM context = ly_run_translator (mus, outdef);
184 if (unsmob_translator (context))
185 ly_render_output (context, head, outname);