Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / score-scheme.cc
blobf3afd1429bd69157c2b287a7e890526ec0aa67b8
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2011 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 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",
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 ();
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__,
82 "module");
84 Score *sc = unsmob_score (score);
85 sc->set_header (module);
86 return SCM_UNSPECIFIED;
89 LY_DEFINE (ly_score_music, "ly:score-music",
90 1, 0, 0, (SCM score),
91 "Return score music.")
93 LY_ASSERT_SMOB (Score, score, 1);
94 Score *sc = unsmob_score (score);
95 return sc->get_music ();
98 LY_DEFINE (ly_score_error_p, "ly:score-error?",
99 1, 0, 0, (SCM score),
100 "Was there an error in the score?")
102 LY_ASSERT_SMOB (Score, score, 1);
103 Score *sc = unsmob_score (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"
111 " layout-lines.")
113 LY_ASSERT_SMOB (Score, score, 1);
114 LY_ASSERT_SMOB (Output_def, layout, 2);
116 Score *sc = unsmob_score (score);
117 Output_def *od = unsmob_output_def (layout);
119 if (sc->error_found_)
120 return SCM_EOL;
122 Output_def *score_def = 0;
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];
130 if (!score_def)
131 return SCM_BOOL_F;
133 score_def = score_def->clone ();
134 SCM prot = score_def->unprotect ();
136 /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD
137 itself. */
138 score_def->parent_ = od;
140 SCM context = ly_run_translator (sc->get_music (), score_def->self_scm ());
141 SCM output = ly_format_output (context);
143 scm_remember_upto_here_1 (prot);
144 return output;