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