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