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