]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-scheme.cc
Rewire lilypond-book output.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "score.hh"
10
11 #include "music.hh"
12 #include "output-def.hh"
13 #include "global-context.hh"
14 #include "lilypond-key.hh"
15 #include "music-output.hh"
16 #include "paper-score.hh"
17 #include "paper-book.hh"
18
19 LY_DEFINE (ly_make_score, "ly:make-score",
20            1, 0, 0,
21            (SCM music),
22            "Return score with @var{music} encapsulated in @var{score}.")
23 {
24   Music *mus = unsmob_music (music);
25   SCM_ASSERT_TYPE (mus, music, SCM_ARG1, __FUNCTION__, "music");
26
27   Score *score = new Score;
28   score->set_music (music);
29
30   return score->unprotect ();
31 }
32
33 LY_DEFINE (ly_score_output_defs, "ly:score-output-defs",
34            1, 0, 0, (SCM score),
35            "All output defs in a score.")
36 {
37   Score *sc = unsmob_score (score);
38   SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "score");
39
40   SCM l = SCM_EOL;
41   for (vsize i = 0; i < sc->defs_.size (); i++)
42     l = scm_cons (sc->defs_[i]->self_scm(), l);
43   return scm_reverse_x (l, SCM_EOL);
44 }
45
46
47
48 LY_DEFINE (ly_score_header, "ly:score-header",
49            1, 0, 0, (SCM score),
50            "return score header.")
51 {
52   Score *sc = unsmob_score (score);
53   SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "score");
54   return sc->header_;
55 }
56
57
58 LY_DEFINE (ly_score_music, "ly:score-music",
59            1, 0, 0, (SCM score),
60            "return score music.")
61 {
62   Score *sc = unsmob_score (score);
63   SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "score");
64   return sc->get_music ();
65 }
66
67 LY_DEFINE (ly_score_error_p, "ly:score-error?",
68            1, 0, 0, (SCM score),
69            "Was there an error in the score?")
70 {
71   Score *sc = unsmob_score (score);
72   SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "score");
73   return scm_from_bool (sc->error_found_);
74 }
75
76 LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
77            2, 1, 0, (SCM score, SCM layout, SCM key),
78            "Run @var{score} through @var{layout}, an output definition, "
79            "scaled to correct output-scale already, "
80            "return a list of layout-lines. "
81            "\nTake optional Object_key argument.")
82 {
83   Score *sc = unsmob_score (score);
84   Output_def *od = unsmob_output_def (layout);
85
86   if (sc->error_found_)
87     return SCM_EOL;
88
89   SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "Score");
90   SCM_ASSERT_TYPE (od, layout, SCM_ARG2, __FUNCTION__, "Output_def");
91
92   Output_def *score_def = 0;
93
94   /* UGR, FIXME, these are default \layout blocks once again.  They
95      suck. */
96   for (vsize i = 0; !score_def && i < sc->defs_.size (); i++)
97     if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T)
98       score_def = sc->defs_[i];
99
100   if (!score_def)
101     return SCM_BOOL_F;
102
103   score_def = score_def->clone ();
104   SCM prot = score_def->unprotect ();
105
106   /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD
107      itself. */
108   score_def->parent_ = od;
109
110   SCM context = ly_run_translator (sc->get_music (), score_def->self_scm (),
111                                    key);
112   SCM output = ly_format_output (context);
113
114   scm_remember_upto_here_1 (prot);
115   return output;
116 }