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