]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-scheme.cc
Merge branch 'master' of ssh+git://gpercival@git.sv.gnu.org/srv/git/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 defs 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
45
46 LY_DEFINE (ly_score_header, "ly:score-header",
47            1, 0, 0, (SCM score),
48            "return score header.")
49 {
50   LY_ASSERT_SMOB (Score, score, 1);
51   Score *sc = unsmob_score (score);
52   return sc->header_;
53 }
54
55
56 LY_DEFINE (ly_score_music, "ly:score-music",
57            1, 0, 0, (SCM score),
58            "return score music.")
59 {
60   LY_ASSERT_SMOB (Score, score, 1);
61   Score *sc = unsmob_score (score);
62   return sc->get_music ();
63 }
64
65 LY_DEFINE (ly_score_error_p, "ly:score-error?",
66            1, 0, 0, (SCM score),
67            "Was there an error in the score?")
68 {
69   LY_ASSERT_SMOB (Score, score, 1);
70   Score *sc = unsmob_score (score);
71   return scm_from_bool (sc->error_found_);
72 }
73
74 LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
75            2, 0, 0, (SCM score, SCM layout),
76            "Run @var{score} through @var{layout}, an output definition, "
77            "scaled to correct output-scale already, "
78            "return a list of layout-lines. "
79            "\nTake optional Object_key argument.")
80 {
81   LY_ASSERT_SMOB (Score, score, 1);
82   LY_ASSERT_SMOB (Output_def, layout, 2);
83
84   Score *sc = unsmob_score (score);
85   Output_def *od = unsmob_output_def (layout);
86
87   if (sc->error_found_)
88     return SCM_EOL;
89
90   Output_def *score_def = 0;
91
92   /* UGR, FIXME, these are default \layout blocks once again.  They
93      suck. */
94   for (vsize i = 0; !score_def && i < sc->defs_.size (); i++)
95     if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T)
96       score_def = sc->defs_[i];
97
98   if (!score_def)
99     return SCM_BOOL_F;
100
101   score_def = score_def->clone ();
102   SCM prot = score_def->unprotect ();
103
104   /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD
105      itself. */
106   score_def->parent_ = od;
107
108   SCM context = ly_run_translator (sc->get_music (), score_def->self_scm ());
109   SCM output = ly_format_output (context);
110
111   scm_remember_upto_here_1 (prot);
112   return output;
113 }