]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-scheme.cc
*** empty log message ***
[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            5, 0, 0,
78            (SCM score_smob,
79             SCM default_header,
80             SCM default_paper,
81             SCM default_layout,
82             SCM basename),
83            "Print score without page-layout: just print the systems.")
84 {
85   Score *score = unsmob_score (score_smob);
86
87   SCM_ASSERT_TYPE (score, score_smob, SCM_ARG1, __FUNCTION__, "score");
88
89   // allow header to be undefined.
90   SCM_ASSERT_TYPE (unsmob_output_def (default_paper),
91                    default_header, SCM_ARG3, __FUNCTION__, "\\paper block");
92   SCM_ASSERT_TYPE (unsmob_output_def (default_layout),
93                    default_header, SCM_ARG4, __FUNCTION__, "\\layout block");
94   SCM_ASSERT_TYPE (scm_is_string (basename),
95                    default_header, SCM_ARG5, __FUNCTION__, "basename");
96   
97   Object_key *key = new Lilypond_general_key (0, score->user_key_, 0);
98
99   if (score->error_found_)
100     return SCM_UNSPECIFIED;
101
102   SCM header = ly_is_module (score->header_)
103     ? score->header_
104     : default_header;
105   
106   for (int i = 0; i < score->defs_.size (); i++)
107     default_rendering (score->get_music (), score->defs_[i]->self_scm (),
108                        default_paper, header, basename, key->self_scm ());
109
110   if (score->defs_.is_empty ())
111     {
112       default_rendering (score->get_music (),
113                          default_layout,
114                          default_paper,
115                          header, basename, key->self_scm ());
116     }
117
118   scm_gc_unprotect_object (key->self_scm ());
119   return SCM_UNSPECIFIED;
120 }
121
122