]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-scheme.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / score-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "score.hh"
21
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"
28
29 LY_DEFINE (ly_make_score, "ly:make-score",
30            1, 0, 0,
31            (SCM music),
32            "Return score with @var{music} encapsulated in it.")
33 {
34   LY_ASSERT_SMOB (Music, music, 1);
35
36   Score *score = new Score;
37   score->set_music (music);
38
39   return score->unprotect ();
40 }
41
42 LY_DEFINE (ly_score_output_defs, "ly:score-output-defs",
43            1, 0, 0, (SCM score),
44            "All output definitions in a score.")
45 {
46   LY_ASSERT_SMOB (Score, score, 1);
47   Score *sc = unsmob_score (score);
48
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);
53 }
54
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}.")
58 {
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;
65 }
66
67 LY_DEFINE (ly_score_header, "ly:score-header",
68            1, 0, 0, (SCM score),
69            "Return score header.")
70 {
71   LY_ASSERT_SMOB (Score, score, 1);
72   Score *sc = unsmob_score (score);
73   return sc->get_header ();
74 }
75
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.")
79 {
80   LY_ASSERT_SMOB (Score, score, 1);
81   SCM_ASSERT_TYPE (ly_is_module (module), module, SCM_ARG2, __FUNCTION__,
82                    "module");
83
84   Score *sc = unsmob_score (score);
85   sc->set_header (module);
86   return SCM_UNSPECIFIED;
87 }
88
89 LY_DEFINE (ly_score_music, "ly:score-music",
90            1, 0, 0, (SCM score),
91            "Return score music.")
92 {
93   LY_ASSERT_SMOB (Score, score, 1);
94   Score *sc = unsmob_score (score);
95   return sc->get_music ();
96 }
97
98 LY_DEFINE (ly_score_error_p, "ly:score-error?",
99            1, 0, 0, (SCM score),
100            "Was there an error in the score?")
101 {
102   LY_ASSERT_SMOB (Score, score, 1);
103   Score *sc = unsmob_score (score);
104   return scm_from_bool (sc->error_found_);
105 }
106
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"
111            " layout-lines.")
112 {
113   LY_ASSERT_SMOB (Score, score, 1);
114   LY_ASSERT_SMOB (Output_def, layout, 2);
115
116   Score *sc = unsmob_score (score);
117   Output_def *od = unsmob_output_def (layout);
118
119   if (sc->error_found_)
120     return SCM_EOL;
121
122   Output_def *score_def = 0;
123
124   /* UGR, FIXME, these are default \layout blocks once again.  They
125      suck. */
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];
129
130   if (!score_def)
131     return SCM_BOOL_F;
132
133   score_def = scale_output_def (score_def, output_scale (od));
134   score_def->parent_ = od;
135
136   SCM context = ly_run_translator (sc->get_music (), score_def->unprotect ());
137   SCM output = ly_format_output (context);
138
139   return output;
140 }