]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-scheme.cc
replace SCM_ASSERT_TYPE with LY_ASSERT_TYPE and friends
[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_FIRST_SMOB (Music, music);
24   Music *mus = unsmob_music (music);
25
26   Score *score = new Score;
27   score->set_music (music);
28
29   return score->unprotect ();
30 }
31
32 LY_DEFINE (ly_score_output_defs, "ly:score-output-defs",
33            1, 0, 0, (SCM score),
34            "All output defs in a score.")
35 {
36   LY_ASSERT_FIRST_SMOB (Score, score);
37   Score *sc = unsmob_score (score);
38
39   SCM l = SCM_EOL;
40   for (vsize i = 0; i < sc->defs_.size (); i++)
41     l = scm_cons (sc->defs_[i]->self_scm(), l);
42   return scm_reverse_x (l, SCM_EOL);
43 }
44
45
46
47 LY_DEFINE (ly_score_header, "ly:score-header",
48            1, 0, 0, (SCM score),
49            "return score header.")
50 {
51   LY_ASSERT_FIRST_SMOB (Score, score);
52   Score *sc = unsmob_score (score);
53   return sc->header_;
54 }
55
56
57 LY_DEFINE (ly_score_music, "ly:score-music",
58            1, 0, 0, (SCM score),
59            "return score music.")
60 {
61   LY_ASSERT_FIRST_SMOB (Score, score);
62   Score *sc = unsmob_score (score);
63   return sc->get_music ();
64 }
65
66 LY_DEFINE (ly_score_error_p, "ly:score-error?",
67            1, 0, 0, (SCM score),
68            "Was there an error in the score?")
69 {
70   LY_ASSERT_FIRST_SMOB (Score, score);
71   Score *sc = unsmob_score (score);
72   return scm_from_bool (sc->error_found_);
73 }
74
75 LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
76            2, 0, 0, (SCM score, SCM layout),
77            "Run @var{score} through @var{layout}, an output definition, "
78            "scaled to correct output-scale already, "
79            "return a list of layout-lines. "
80            "\nTake optional Object_key argument.")
81 {
82   LY_ASSERT_FIRST_SMOB (Score, score);
83   LY_ASSERT_SMOB (Output_def, 2);
84
85   Score *sc = unsmob_score (score);
86   Output_def *od = unsmob_output_def (layout);
87
88   if (sc->error_found_)
89     return SCM_EOL;
90
91   Output_def *score_def = 0;
92
93   /* UGR, FIXME, these are default \layout blocks once again.  They
94      suck. */
95   for (vsize i = 0; !score_def && i < sc->defs_.size (); i++)
96     if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T)
97       score_def = sc->defs_[i];
98
99   if (!score_def)
100     return SCM_BOOL_F;
101
102   score_def = score_def->clone ();
103   SCM prot = score_def->unprotect ();
104
105   /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD
106      itself. */
107   score_def->parent_ = od;
108
109   SCM context = ly_run_translator (sc->get_music (), score_def->self_scm ());
110   SCM output = ly_format_output (context);
111
112   scm_remember_upto_here_1 (prot);
113   return output;
114 }