]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/global-context-scheme.cc
* lily/ various: Introduce stream events of types Prepare,
[lilypond.git] / lily / global-context-scheme.cc
index 4f717561533cbc1fd28a84aa20a2b1bc20ab7194..9229a8a0d956d8124cfd83aa671cbfb185f08d7a 100644 (file)
@@ -3,33 +3,48 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
-#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 "object-key.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),
+          1, 0, 0, (SCM context),
           "Given a Global context in its final state, "
-          "process it and return the (rendered) result.")
+          "process it and return the @code{Music_output} object in its final state.")
 {
   Global_context *g = dynamic_cast<Global_context *> (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");
 
-  Music_output *output = g->get_output ();
+  SCM output = g->get_output ();
   progress_indication ("\n");
+  unsmob_music_output (output)->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\n"
+          "@var{global}. The translator group is returned.")
+{
+  Global_context *g = dynamic_cast<Global_context *> (unsmob_context (global));
+  SCM_ASSERT_TYPE (g, global, SCM_ARG1, __FUNCTION__, "Global context");
 
-  /* ugh, midi still wants outname  */
-  return output->process (ly_scm2string (outname));
+  Translator_group *tg = new Translator_group ();
+  tg->connect_to_context (g);
+  g->implementation_ = tg;
+
+  return tg->unprotect ();
 }
 
 LY_DEFINE (ly_run_translator, "ly:run-translator",
@@ -38,8 +53,8 @@ LY_DEFINE (ly_run_translator, "ly:run-translator",
           "An interpretation context is set up,\n"
           "and @var{mus} is interpreted with it.  \n"
           "The context is returned in its final state.\n"
-
-          "\n\nOptionally, this routine takes an Object-key to\n"
+          "\n\n"
+          "Optionally, this routine takes an Object-key to\n"
           "to uniquely identify the Score block containing it.\n")
 {
   Output_def *odef = unsmob_output_def (output_def);
@@ -58,19 +73,21 @@ LY_DEFINE (ly_run_translator, "ly:run-translator",
 
   Cpu_timer timer;
 
-  Global_context *trans = new Global_context (odef, music->get_length (), unsmob_key (key));
-  if (!trans)
+  Global_context *glob = new Global_context (odef, unsmob_key (key));
+  if (!glob)
     {
-      programming_error ("no toplevel translator");
+      programming_error ("Couldn't create Global context");
       return SCM_BOOL_F;
     }
 
+  SCM tgs = ly_make_global_translator (glob->self_scm ());
+  Translator_group *tg = unsmob_translator_group (tgs);
+
   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);
-
+  iter->init_translator (music, glob);
   iter->construct_children ();
 
   if (!iter->ok ())
@@ -80,13 +97,13 @@ LY_DEFINE (ly_run_translator, "ly:run-translator",
       return SCM_BOOL_F;
     }
 
-  trans->run_iterator_on_me (iter);
+  glob->run_iterator_on_me (iter);
   iter->quit ();
   scm_remember_upto_here_1 (protected_iter);
-  trans->finish ();
+  send_stream_event (glob, "Finish", 0, 0);
 
   if (be_verbose_global)
     message (_f ("elapsed time: %.2f seconds", timer.read ()));
 
-  return scm_gc_unprotect_object (trans->self_scm ());
+  return glob->unprotect ();
 }