]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-scheme.cc
* flower
[lilypond.git] / lily / score-scheme.cc
1 /*
2   score-scheme.cc -- implement Score 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 "score.hh"
10 #include "music.hh"
11 #include "output-def.hh"
12 #include "global-context.hh"
13
14 LY_DEFINE (ly_music_scorify, "ly:music-scorify",
15            2, 0, 0,
16            (SCM music, SCM parser),
17            "Return MUSIC with TEXTS encapsulated in SCORE.")
18 {
19 #if 0
20   SCM_ASSERT_TYPE (ly_c_music_p (music), music, SCM_ARG1, __FUNCTION__, "music");
21 #endif
22   Score *score = new Score;
23   score->set_music (music, parser);
24   scm_gc_unprotect_object (score->self_scm ());
25   return score->self_scm ();
26 }
27
28 LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
29            2, 1, 0, (SCM score, SCM layout, SCM key),
30            "Run @var{score} through @var{layout}, an output definition, "
31            "scaled to correct outputscale already, "
32            "return a list of layout-lines. "
33            "\nTake optional Object_key argument.")
34 {
35   Score *sc = unsmob_score (score);
36   Output_def *od = unsmob_output_def (layout);
37
38   if (sc->error_found_)
39     return SCM_EOL;
40
41   SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "Score");
42   SCM_ASSERT_TYPE (od, layout, SCM_ARG2, __FUNCTION__, "Output_def");
43
44   Output_def *score_def = 0;
45
46   /* UGR, FIXME, these are default \layout blocks once again.  They
47      suck. */
48   for (int i = 0; !score_def && i < sc->defs_.size (); i++)
49     if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T)
50       score_def = sc->defs_[i];
51
52   if (!score_def)
53     return scm_c_make_vector (0, SCM_EOL);
54
55   score_def = score_def->clone ();
56   SCM prot = score_def->self_scm ();
57   scm_gc_unprotect_object (prot);
58
59   /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD
60      itself. */
61   score_def->parent_ = od;
62
63   SCM context = ly_run_translator (sc->get_music (), score_def->self_scm (),
64                                    key);
65   SCM lines = ly_format_output (context, scm_makfrom0str ("<embedded>"));
66
67   scm_remember_upto_here_1 (prot);
68   return lines;
69 }