2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "cpu-timer.hh"
21 #include "global-context.hh"
22 #include "international.hh"
24 #include "music-iterator.hh"
25 #include "music-output.hh"
27 #include "output-def.hh"
28 #include "translator-group.hh"
31 LY_DEFINE (ly_format_output
, "ly:format-output",
32 1, 0, 0, (SCM context
),
33 "Given a global context in its final state,"
34 " process it and return the @code{Music_output} object"
35 " in its final state.")
37 Global_context
*g
= dynamic_cast<Global_context
*> (unsmob_context (context
));
39 LY_ASSERT_TYPE (unsmob_global_context
, context
, 1);
41 SCM output
= g
->get_output ();
42 progress_indication ("\n");
44 if (Music_output
*od
= unsmob_music_output (output
))
50 LY_DEFINE (ly_make_global_translator
, "ly:make-global-translator",
51 1, 0, 0, (SCM global
),
52 "Create a translator group and connect it to the global context"
53 " @var{global}. The translator group is returned.")
55 Global_context
*g
= dynamic_cast<Global_context
*> (unsmob_context (global
));
56 LY_ASSERT_TYPE (unsmob_global_context
, global
, 1);
58 Translator_group
*tg
= new Translator_group ();
59 tg
->connect_to_context (g
);
60 g
->implementation_
= tg
;
62 return tg
->unprotect ();
65 LY_DEFINE (ly_make_global_context
, "ly:make-global-context",
66 1, 0, 0, (SCM output_def
),
67 "Set up a global interpretation context, using the output"
68 " block @var{output-def}. The context is returned.")
70 LY_ASSERT_SMOB (Output_def
, output_def
, 1);
71 Output_def
*odef
= unsmob_output_def (output_def
);
73 Global_context
*glob
= new Global_context (odef
);
77 programming_error ("no toplevel translator");
81 return glob
->unprotect ();
84 LY_DEFINE (ly_interpret_music_expression
, "ly:interpret-music-expression",
85 2, 0, 0, (SCM mus
, SCM ctx
),
86 "Interpret the music expression @var{mus} in the global context"
87 " @var{ctx}. The context is returned in its final state.")
89 LY_ASSERT_SMOB (Music
, mus
, 1);
90 LY_ASSERT_TYPE (unsmob_global_context
, ctx
, 2);
92 Music
*music
= unsmob_music (mus
);
94 || !music
->get_length ().to_bool ())
96 warning (_ ("no music found in score"));
100 Global_context
*g
= dynamic_cast<Global_context
*> (unsmob_context (ctx
));
104 message (_ ("Interpreting music... "));
106 SCM protected_iter
= Music_iterator::get_static_get_iterator (music
);
107 Music_iterator
*iter
= unsmob_iterator (protected_iter
);
109 iter
->init_context (music
, g
);
110 iter
->construct_children ();
114 warning (_ ("no music found in score"));
115 /* todo: should throw exception. */
119 g
->run_iterator_on_me (iter
);
122 scm_remember_upto_here_1 (protected_iter
);
124 send_stream_event (g
, "Finish", 0, 0);
126 if (be_verbose_global
)
127 message (_f ("elapsed time: %.2f seconds", timer
.read ()));
132 LY_DEFINE (ly_run_translator
, "ly:run-translator",
133 2, 1, 0, (SCM mus
, SCM output_def
),
134 "Process @var{mus} according to @var{output-def}. An"
135 " interpretation context is set up, and @var{mus} is"
136 " interpreted with it. The context is returned in its"
139 "Optionally, this routine takes an object-key to"
140 " to uniquely identify the score block containing it.")
142 LY_ASSERT_SMOB (Music
, mus
, 1);
143 LY_ASSERT_SMOB (Output_def
, output_def
, 2);
145 SCM glob
= ly_make_global_context (output_def
);
146 ly_make_global_translator (glob
);
147 ly_interpret_music_expression (mus
, glob
);