]> git.donarmstrong.com Git - lilypond.git/blob - lily/global-context-scheme.cc
(process): return #f iso. #<undefined>. This
[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 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            2, 0, 0, (SCM context, SCM outname),
21            "Given a Global context in its final state, "
22            "process it and return the (rendered) result.")
23 {
24   Global_context *g = dynamic_cast<Global_context *> (unsmob_context (context));
25   SCM_ASSERT_TYPE (g, context, SCM_ARG1, __FUNCTION__, "Global context");
26   SCM_ASSERT_TYPE (scm_is_string (outname), outname, SCM_ARG2, __FUNCTION__, "output file name");
27
28   Music_output *output = g->get_output ();
29   progress_indication ("\n");
30
31   /* ugh, midi still wants outname  */
32   return output->process (ly_scm2string (outname));
33 }
34
35 LY_DEFINE (ly_run_translator, "ly:run-translator",
36            2, 1, 0, (SCM mus, SCM output_def, SCM key),
37            "Process @var{mus} according to @var{output_def}. \n"
38            "An interpretation context is set up,\n"
39            "and @var{mus} is interpreted with it.  \n"
40            "The context is returned in its final state.\n"
41
42            "\n\nOptionally, this routine takes an Object-key to\n"
43            "to uniquely identify the Score block containing it.\n")
44 {
45   Output_def *odef = unsmob_output_def (output_def);
46   Music *music = unsmob_music (mus);
47
48   if (!music
49       || !music->get_length ().to_bool ())
50     {
51       warning (_ ("no music found in score"));
52       return SCM_BOOL_F;
53     }
54
55   SCM_ASSERT_TYPE (music, mus, SCM_ARG1, __FUNCTION__, "Music");
56   SCM_ASSERT_TYPE (odef, output_def, SCM_ARG2, __FUNCTION__,
57                    "Output definition");
58
59   Cpu_timer timer;
60
61   Global_context *trans = new Global_context (odef, music->get_length (), 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
74   iter->construct_children ();
75
76   if (!iter->ok ())
77     {
78       warning (_ ("no music found in score"));
79       /* todo: should throw exception. */
80       return SCM_BOOL_F;
81     }
82
83   trans->run_iterator_on_me (iter);
84   iter->quit ();
85   scm_remember_upto_here_1 (protected_iter);
86   trans->finish ();
87
88   if (be_verbose_global)
89     message (_f ("elapsed time: %.2f seconds", timer.read ()));
90
91   return scm_gc_unprotect_object (trans->self_scm ());
92 }