X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fglobal-context-scheme.cc;h=46bdae7b9097f9ec42f1703f5dcb1c98b22aea8b;hb=refs%2Fheads%2Fbugs%2F567849;hp=f26b0b19f72a10dd4c72de5d99dc66bdf9922e96;hpb=5097490ed5bcd65115a8a311b5b7e61192cec9f2;p=lilypond.git diff --git a/lily/global-context-scheme.cc b/lily/global-context-scheme.cc index f26b0b19f7..46bdae7b90 100644 --- a/lily/global-context-scheme.cc +++ b/lily/global-context-scheme.cc @@ -1,94 +1,149 @@ /* - global-context-scheme.cc -- implement Global_context bindings + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2005--2011 Han-Wen Nienhuys - (c) 2005 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ -#include "warn.hh" -#include "music-output.hh" -#include "output-def.hh" -#include "music-iterator.hh" -#include "music.hh" #include "cpu-timer.hh" #include "global-context.hh" -#include "object-key.hh" +#include "international.hh" #include "main.hh" +#include "music-iterator.hh" +#include "music-output.hh" +#include "music.hh" +#include "output-def.hh" +#include "translator-group.hh" +#include "warn.hh" LY_DEFINE (ly_format_output, "ly:format-output", - 2, 0, 0, (SCM context, SCM outname), - "Given a Global context in its final state, " - "process it and return the (rendered) result.") + 1, 0, 0, (SCM context), + "Given a global context in its final state," + " process it and return the @code{Music_output} object" + " in its final state.") { - Global_context *g = dynamic_cast (unsmob_context (context)); - SCM_ASSERT_TYPE (g, context, SCM_ARG1, __FUNCTION__, "Global context"); - SCM_ASSERT_TYPE (scm_is_string (outname), outname, SCM_ARG2, __FUNCTION__, "output file name"); + Global_context *g = dynamic_cast (unsmob_context (context)); - Music_output *output = g->get_output (); + LY_ASSERT_TYPE (unsmob_global_context, context, 1); + + SCM output = g->get_output (); progress_indication ("\n"); - /* ugh, midi still wants outname */ - return output->process (ly_scm2string (outname)); + + if (Music_output *od = unsmob_music_output (output)) + od->process (); + + return output; } +LY_DEFINE (ly_make_global_translator, "ly:make-global-translator", + 1, 0, 0, (SCM global), + "Create a translator group and connect it to the global context" + " @var{global}. The translator group is returned.") +{ + Global_context *g = dynamic_cast (unsmob_context (global)); + LY_ASSERT_TYPE (unsmob_global_context, global, 1); + + Translator_group *tg = new Translator_group (); + tg->connect_to_context (g); + g->implementation_ = tg; -LY_DEFINE (ly_run_translator, "ly:run-translator", - 2, 1, 0, (SCM mus, SCM output_def, SCM key), - "Process @var{mus} according to @var{output_def}. \n" - "An interpretation context is set up,\n" - "and @var{mus} is interpreted with it. \n" - "The context is returned in its final state.\n" + return tg->unprotect (); +} - "\n\nOptionally, this routine takes an Object-key to\n" - "to uniquely identify the Score block containing it.\n") +LY_DEFINE (ly_make_global_context, "ly:make-global-context", + 1, 0, 0, (SCM output_def), + "Set up a global interpretation context, using the output" + " block @var{output-def}. The context is returned.") { + LY_ASSERT_SMOB (Output_def, output_def, 1); Output_def *odef = unsmob_output_def (output_def); - Music *music = unsmob_music (mus); - if (!music - || !music->get_length ().to_bool ()) + Global_context *glob = new Global_context (odef); + + if (!glob) { - warning (_ ("Need music in a score")); + programming_error ("no toplevel translator"); return SCM_BOOL_F; } - - SCM_ASSERT_TYPE (music, mus, SCM_ARG1, - __FUNCTION__, "Music"); - SCM_ASSERT_TYPE (odef, output_def, SCM_ARG2, __FUNCTION__, - "Output definition"); - - Cpu_timer timer; - - Global_context *trans = new Global_context (odef, music->get_length (), unsmob_key (key) ); - if (!trans) + + return glob->unprotect (); +} + +LY_DEFINE (ly_interpret_music_expression, "ly:interpret-music-expression", + 2, 0, 0, (SCM mus, SCM ctx), + "Interpret the music expression @var{mus} in the global context" + " @var{ctx}. The context is returned in its final state.") +{ + LY_ASSERT_SMOB (Music, mus, 1); + LY_ASSERT_TYPE (unsmob_global_context, ctx, 2); + + Music *music = unsmob_music (mus); + if (!music + || !music->get_length ().to_bool ()) { - programming_error ("no toplevel translator"); + warning (_ ("no music found in score")); return SCM_BOOL_F; } - progress_indication (_ ("Interpreting music... ")); - + Global_context *g = dynamic_cast (unsmob_context (ctx)); + + Cpu_timer timer; + + message (_ ("Interpreting music... ")); + SCM protected_iter = Music_iterator::get_static_get_iterator (music); - Music_iterator * iter = unsmob_iterator (protected_iter); - iter->init_translator (music, trans); + Music_iterator *iter = unsmob_iterator (protected_iter); + iter->init_context (music, g); iter->construct_children (); if (!iter->ok ()) { - warning (_ ("Need music in a score")); + warning (_ ("no music found in score")); /* todo: should throw exception. */ return SCM_BOOL_F; } - trans->run_iterator_on_me (iter); + g->run_iterator_on_me (iter); + iter->quit (); scm_remember_upto_here_1 (protected_iter); - trans->finish (); + + send_stream_event (g, "Finish", 0, 0); if (be_verbose_global) - progress_indication (_f ("elapsed time: %.2f seconds", timer.read ())); - - return scm_gc_unprotect_object (trans->self_scm ()); + message (_f ("elapsed time: %.2f seconds", timer.read ())); + + return ctx; +} + +LY_DEFINE (ly_run_translator, "ly:run-translator", + 2, 1, 0, (SCM mus, SCM output_def), + "Process @var{mus} according to @var{output-def}. An" + " interpretation context is set up, and @var{mus} is" + " interpreted with it. The context is returned in its" + " final state.\n" + "\n" + "Optionally, this routine takes an object-key to" + " to uniquely identify the score block containing it.") +{ + LY_ASSERT_SMOB (Music, mus, 1); + LY_ASSERT_SMOB (Output_def, output_def, 2); + + SCM glob = ly_make_global_context (output_def); + ly_make_global_translator (glob); + ly_interpret_music_expression (mus, glob); + return glob; }