2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2015 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/>.
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",
32 "Return score with @var{music} encapsulated in it.")
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",
44 "All output definitions in a score.")
46 LY_ASSERT_SMOB (Score, score, 1);
47 Score *sc = Score::unsmob (score);
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 = Score::unsmob (score);
62 Output_def *output_def = Output_def::unsmob (def);
63 sc->add_output_def (output_def);
64 return SCM_UNSPECIFIED;
67 LY_DEFINE (ly_score_header, "ly:score-header",
69 "Return score header.")
71 LY_ASSERT_SMOB (Score, score, 1);
72 Score *sc = Score::unsmob (score);
73 return sc->get_header ();
76 LY_DEFINE (ly_score_set_header_x, "ly:score-set-header!",
77 2, 0, 0, (SCM score, SCM module),
78 "Set the score header.")
80 LY_ASSERT_SMOB (Score, score, 1);
81 SCM_ASSERT_TYPE (ly_is_module (module), module, SCM_ARG2, __FUNCTION__,
84 Score *sc = Score::unsmob (score);
85 sc->set_header (module);
86 return SCM_UNSPECIFIED;
89 LY_DEFINE (ly_score_music, "ly:score-music",
91 "Return score music.")
93 LY_ASSERT_SMOB (Score, score, 1);
94 Score *sc = Score::unsmob (score);
95 return sc->get_music ();
98 LY_DEFINE (ly_score_error_p, "ly:score-error?",
100 "Was there an error in the score?")
102 LY_ASSERT_SMOB (Score, score, 1);
103 Score *sc = Score::unsmob (score);
104 return scm_from_bool (sc->error_found_);
107 LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
108 2, 0, 0, (SCM score, SCM layout),
109 "Run @var{score} through @var{layout} (an output definition)"
110 " scaled to correct output-scale already, returning a list of"
113 LY_ASSERT_SMOB (Score, score, 1);
114 LY_ASSERT_SMOB (Output_def, layout, 2);
116 Score *sc = Score::unsmob (score);
117 Output_def *od = Output_def::unsmob (layout);
119 if (sc->error_found_)
122 Output_def *score_def = 0;
124 /* UGR, FIXME, these are default \layout blocks once again. They
126 for (vsize i = 0; !score_def && i < sc->defs_.size (); i++)
127 if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T)
128 score_def = sc->defs_[i];
133 /* Don't rescale if the layout has already been scaled */
134 if (to_boolean (score_def->c_variable ("cloned")))
135 score_def = score_def->clone ();
137 score_def = scale_output_def (score_def, output_scale (od));
139 score_def->parent_ = od;
141 SCM context = ly_run_translator (sc->get_music (), score_def->unprotect ());
142 SCM output = ly_format_output (context);