]> git.donarmstrong.com Git - lilypond.git/blob - lily/global-context-scheme.cc
* scm/layout-page-layout.scm (write-page-breaks): record tweaks
[lilypond.git] / lily / global-context-scheme.cc
1 /*
2   global-context-scheme.cc -- implement Global_context bindings
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "warn.hh"
10 #include "music-output.hh"
11 #include "output-def.hh"
12 #include "music-iterator.hh"
13 #include "music.hh"
14 #include "cpu-timer.hh"
15 #include "global-context.hh"
16 #include "object-key.hh"
17 #include "main.hh"
18
19 LY_DEFINE (ly_format_output, "ly:format-output",
20            1, 0, 0, (SCM context),
21            "Given a Global context in its final state, "
22            "process it and return the @code{Music_output} object in its final state.")
23 {
24   Global_context *g = dynamic_cast<Global_context *> (unsmob_context (context));
25   SCM_ASSERT_TYPE (g, context, SCM_ARG1, __FUNCTION__, "Global context");
26
27   SCM output = g->get_output ();
28   progress_indication ("\n");
29   unsmob_music_output (output)->process ();
30   return output;
31 }
32
33 LY_DEFINE (ly_run_translator, "ly:run-translator",
34            2, 1, 0, (SCM mus, SCM output_def, SCM key),
35            "Process @var{mus} according to @var{output_def}. \n"
36            "An interpretation context is set up,\n"
37            "and @var{mus} is interpreted with it.  \n"
38            "The context is returned in its final state.\n"
39            "\n\n"
40            "Optionally, this routine takes an Object-key to\n"
41            "to uniquely identify the Score block containing it.\n")
42 {
43   Output_def *odef = unsmob_output_def (output_def);
44   Music *music = unsmob_music (mus);
45
46   if (!music
47       || !music->get_length ().to_bool ())
48     {
49       warning (_ ("no music found in score"));
50       return SCM_BOOL_F;
51     }
52
53   SCM_ASSERT_TYPE (music, mus, SCM_ARG1, __FUNCTION__, "Music");
54   SCM_ASSERT_TYPE (odef, output_def, SCM_ARG2, __FUNCTION__,
55                    "Output definition");
56
57   Cpu_timer timer;
58
59   Global_context *trans = new Global_context (odef, music->get_length (),
60                                               unsmob_key (key));
61   if (!trans)
62     {
63       programming_error ("no toplevel translator");
64       return SCM_BOOL_F;
65     }
66
67   message (_ ("Interpreting music... "));
68
69   SCM protected_iter = Music_iterator::get_static_get_iterator (music);
70   Music_iterator *iter = unsmob_iterator (protected_iter);
71   iter->init_translator (music, trans);
72   iter->construct_children ();
73
74   if (!iter->ok ())
75     {
76       warning (_ ("no music found in score"));
77       /* todo: should throw exception. */
78       return SCM_BOOL_F;
79     }
80
81   trans->run_iterator_on_me (iter);
82   iter->quit ();
83   scm_remember_upto_here_1 (protected_iter);
84   trans->finish ();
85
86   if (be_verbose_global)
87     message (_f ("elapsed time: %.2f seconds", timer.read ()));
88
89   return trans->unprotect ();
90 }