]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-scheme.cc
Update blank sheet music example again.
[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--2006 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 "lilypond-key.hh"
15
16 LY_DEFINE (ly_make_score, "ly:make-score",
17            1, 0, 0,
18            (SCM music),
19            "Return score with @var{music} encapsulated in @var{score}.")
20 {
21   Music *mus = unsmob_music (music);
22   SCM_ASSERT_TYPE (mus, music, SCM_ARG1, __FUNCTION__, "music");
23
24   Score *score = new Score;
25   score->set_music (music);
26
27   return score->unprotect ();
28 }
29
30 LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format",
31            2, 1, 0, (SCM score, SCM layout, SCM key),
32            "Run @var{score} through @var{layout}, an output definition, "
33            "scaled to correct output-scale already, "
34            "return a list of layout-lines. "
35            "\nTake optional Object_key argument.")
36 {
37   Score *sc = unsmob_score (score);
38   Output_def *od = unsmob_output_def (layout);
39
40   if (sc->error_found_)
41     return SCM_EOL;
42
43   SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "Score");
44   SCM_ASSERT_TYPE (od, layout, SCM_ARG2, __FUNCTION__, "Output_def");
45
46   Output_def *score_def = 0;
47
48   /* UGR, FIXME, these are default \layout blocks once again.  They
49      suck. */
50   for (vsize i = 0; !score_def && i < sc->defs_.size (); i++)
51     if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T)
52       score_def = sc->defs_[i];
53
54   if (!score_def)
55     return SCM_BOOL_F;
56
57   score_def = score_def->clone ();
58   SCM prot = score_def->unprotect ();
59
60   /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD
61      itself. */
62   score_def->parent_ = od;
63
64   SCM context = ly_run_translator (sc->get_music (), score_def->self_scm (),
65                                    key);
66   SCM output = ly_format_output (context);
67
68   scm_remember_upto_here_1 (prot);
69   return output;
70 }
71
72 LY_DEFINE (ly_score_process, "ly:score-process",
73            5, 0, 0,
74            (SCM score_smob,
75             SCM default_header,
76             SCM default_paper,
77             SCM default_layout,
78             SCM basename),
79            "Print score without page-layout: just print the systems.")
80 {
81   Score *score = unsmob_score (score_smob);
82
83   SCM_ASSERT_TYPE (score, score_smob, SCM_ARG1, __FUNCTION__, "score");
84
85   // allow header to be undefined.
86   SCM_ASSERT_TYPE (unsmob_output_def (default_paper),
87                    default_header, SCM_ARG3, __FUNCTION__, "\\paper block");
88   SCM_ASSERT_TYPE (unsmob_output_def (default_layout),
89                    default_header, SCM_ARG4, __FUNCTION__, "\\layout block");
90
91   Object_key *key = new Lilypond_general_key (0, score->user_key_, 0);
92
93   if (score->error_found_)
94     return SCM_UNSPECIFIED;
95
96   SCM header = ly_is_module (score->header_)
97     ? score->header_
98     : default_header;
99
100   for (vsize i = 0; i < score->defs_.size (); i++)
101     default_rendering (score->get_music (), score->defs_[i]->self_scm (),
102                        default_paper, header, basename, key->self_scm ());
103
104   if (score->defs_.empty ())
105     {
106       default_rendering (score->get_music (),
107                          default_layout,
108                          default_paper,
109                          header, basename, key->self_scm ());
110     }
111
112   key->unprotect ();
113   return SCM_UNSPECIFIED;
114 }
115