Add display method for \bendAfter.
[lilypond/mpolesky.git] / lily / score-scheme.cc
blob6785ae7e32b084e36339d20a1d7cc47cad5c31da
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "score.hh"
22 #include "music.hh"
23 #include "output-def.hh"
24 #include "global-context.hh"
25 #include "music-output.hh"
26 #include "paper-score.hh"
27 #include "paper-book.hh"
29 LY_DEFINE (ly_make_score, "ly:make-score",
30 1, 0, 0,
31 (SCM music),
32 "Return score with @var{music} encapsulated in @var{score}.")
34 LY_ASSERT_SMOB (Music, music, 1);
36 Score *score = new Score;
37 score->set_music (music);
39 return score->unprotect ();
42 LY_DEFINE (ly_score_output_defs, "ly:score-output-defs",
43 1, 0, 0, (SCM score),
44 "All output definitions in a score.")
46 LY_ASSERT_SMOB (Score, score, 1);
47 Score *sc = unsmob_score (score);
49 SCM l = SCM_EOL;
50 for (vsize i = 0; i < sc->defs_.size (); i++)
51 l = scm_cons (sc->defs_[i]->self_scm (), l);
52 return scm_reverse_x (l, SCM_EOL);
55 LY_DEFINE (ly_score_add_output_def_x, "ly:score-add-output-def!",
56 2, 0, 0, (SCM score, SCM def),
57 "Add an output definition @var{def} to @var{score}.")
59 LY_ASSERT_SMOB (Score, score, 1);
60 LY_ASSERT_SMOB (Output_def, def, 2);
61 Score *sc = unsmob_score (score);
62 Output_def *output_def = unsmob_output_def (def);
63 sc->add_output_def (output_def);
64 return SCM_UNSPECIFIED;
67 LY_DEFINE (ly_score_header, "ly:score-header",
68 1, 0, 0, (SCM score),
69 "Return score header.")
71 LY_ASSERT_SMOB (Score, score, 1);
72 Score *sc = unsmob_score (score);
73 return sc->get_header ();
77 LY_DEFINE (ly_score_set_header_x, "ly:score-set-header!",
78 2, 0, 0, (SCM score, SCM module),
79 "Set the score header.")
81 LY_ASSERT_SMOB (Score, score, 1);
82 SCM_ASSERT_TYPE (ly_is_module (module), module, SCM_ARG2, __FUNCTION__,
83 "module");
85 Score *sc = unsmob_score (score);
86 sc->set_header (module);
87 return SCM_UNSPECIFIED;
91 LY_DEFINE (ly_score_music, "ly:score-music",
92 1, 0, 0, (SCM score),
93 "Return score music.")
95 LY_ASSERT_SMOB (Score, score, 1);
96 Score *sc = unsmob_score (score);
97 return sc->get_music ();
100 LY_DEFINE (ly_score_error_p, "ly:score-error?",
101 1, 0, 0, (SCM score),
102 "Was there an error in the score?")
104 LY_ASSERT_SMOB (Score, score, 1);
105 Score *sc = unsmob_score (score);
106 return scm_from_bool (sc->error_found_);
109 LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
110 2, 0, 0, (SCM score, SCM layout),
111 "Run @var{score} through @var{layout} (an output definition)"
112 " scaled to correct output-scale already, returning a list of"
113 " layout-lines. This function takes an optional"
114 " @code{Object_key} argument.")
116 LY_ASSERT_SMOB (Score, score, 1);
117 LY_ASSERT_SMOB (Output_def, layout, 2);
119 Score *sc = unsmob_score (score);
120 Output_def *od = unsmob_output_def (layout);
122 if (sc->error_found_)
123 return SCM_EOL;
125 Output_def *score_def = 0;
127 /* UGR, FIXME, these are default \layout blocks once again. They
128 suck. */
129 for (vsize i = 0; !score_def && i < sc->defs_.size (); i++)
130 if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T)
131 score_def = sc->defs_[i];
133 if (!score_def)
134 return SCM_BOOL_F;
136 score_def = score_def->clone ();
137 SCM prot = score_def->unprotect ();
139 /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD
140 itself. */
141 score_def->parent_ = od;
143 SCM context = ly_run_translator (sc->get_music (), score_def->self_scm ());
144 SCM output = ly_format_output (context);
146 scm_remember_upto_here_1 (prot);
147 return output;