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