]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-scheme.cc
Merge branch 'master' of git://git.sv.gnu.org/lilypond
[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--2007 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 "music-output.hh"
15 #include "paper-score.hh"
16 #include "paper-book.hh"
17
18 LY_DEFINE (ly_make_score, "ly:make-score",
19            1, 0, 0,
20            (SCM music),
21            "Return score with @var{music} encapsulated in @var{score}.")
22 {
23   LY_ASSERT_SMOB (Music, music, 1);
24
25   Score *score = new Score;
26   score->set_music (music);
27
28   return score->unprotect ();
29 }
30
31 LY_DEFINE (ly_score_output_defs, "ly:score-output-defs",
32            1, 0, 0, (SCM score),
33            "All output definitions in a score.")
34 {
35   LY_ASSERT_SMOB (Score, score, 1);
36   Score *sc = unsmob_score (score);
37
38   SCM l = SCM_EOL;
39   for (vsize i = 0; i < sc->defs_.size (); i++)
40     l = scm_cons (sc->defs_[i]->self_scm (), l);
41   return scm_reverse_x (l, SCM_EOL);
42 }
43
44 LY_DEFINE (ly_score_add_output_def_x, "ly:score-add-output-def!",
45            2, 0, 0, (SCM score, SCM def),
46            "Add an output definition @var{def} to @var{score}.")
47 {
48   LY_ASSERT_SMOB (Score, score, 1);
49   LY_ASSERT_SMOB (Output_def, def, 2);
50   Score *sc = unsmob_score (score);
51   Output_def *output_def = unsmob_output_def (def);
52   sc->add_output_def (output_def);
53   return SCM_UNSPECIFIED;
54 }
55
56 LY_DEFINE (ly_score_header, "ly:score-header",
57            1, 0, 0, (SCM score),
58            "Return score header.")
59 {
60   LY_ASSERT_SMOB (Score, score, 1);
61   Score *sc = unsmob_score (score);
62   return sc->get_header ();
63 }
64
65
66 LY_DEFINE (ly_score_set_header_x, "ly:score-set-header!",
67            2, 0, 0, (SCM score, SCM module),
68            "Set the score header.")
69 {
70   LY_ASSERT_SMOB (Score, score, 1);
71   SCM_ASSERT_TYPE (ly_is_module (module), module, SCM_ARG2, __FUNCTION__,
72                    "module");
73   
74   Score *sc = unsmob_score (score);
75   return sc->get_header ();
76 }
77
78
79 LY_DEFINE (ly_score_music, "ly:score-music",
80            1, 0, 0, (SCM score),
81            "Return score music.")
82 {
83   LY_ASSERT_SMOB (Score, score, 1);
84   Score *sc = unsmob_score (score);
85   return sc->get_music ();
86 }
87
88 LY_DEFINE (ly_score_error_p, "ly:score-error?",
89            1, 0, 0, (SCM score),
90            "Was there an error in the score?")
91 {
92   LY_ASSERT_SMOB (Score, score, 1);
93   Score *sc = unsmob_score (score);
94   return scm_from_bool (sc->error_found_);
95 }
96
97 LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
98            2, 0, 0, (SCM score, SCM layout),
99            "Run @var{score} through @var{layout} (an output definition)"
100            " scaled to correct output-scale already, returning a list of"
101            " layout-lines.  This function takes an optional"
102            " @code{Object_key} argument.")
103 {
104   LY_ASSERT_SMOB (Score, score, 1);
105   LY_ASSERT_SMOB (Output_def, layout, 2);
106
107   Score *sc = unsmob_score (score);
108   Output_def *od = unsmob_output_def (layout);
109
110   if (sc->error_found_)
111     return SCM_EOL;
112
113   Output_def *score_def = 0;
114
115   /* UGR, FIXME, these are default \layout blocks once again.  They
116      suck. */
117   for (vsize i = 0; !score_def && i < sc->defs_.size (); i++)
118     if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T)
119       score_def = sc->defs_[i];
120
121   if (!score_def)
122     return SCM_BOOL_F;
123
124   score_def = score_def->clone ();
125   SCM prot = score_def->unprotect ();
126
127   /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD
128      itself. */
129   score_def->parent_ = od;
130
131   SCM context = ly_run_translator (sc->get_music (), score_def->self_scm ());
132   SCM output = ly_format_output (context);
133
134   scm_remember_upto_here_1 (prot);
135   return output;
136 }