2 score.cc -- implement Score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "ly-smobs.icc"
15 #include "music-output-def.hh"
16 #include "music-output.hh"
17 #include "music-iterator.hh"
19 #include "global-context.hh"
20 #include "scm-hash.hh"
21 #include "cpu-timer.hh"
23 #include "paper-def.hh"
24 #include "ly-module.hh"
25 #include "paper-book.hh"
26 #include "paper-score.hh"
27 #include "input-file-results.hh"
50 IMPLEMENT_SMOBS (Score
);
51 IMPLEMENT_DEFAULT_EQUAL_P (Score
);
55 Score::mark_smob (SCM s
)
57 Score
* sc
= (Score
*) SCM_CELL_WORD_1 (s
);
60 scm_gc_mark (sc
->header_
);
61 for (int i
= sc
->defs_
.size (); i
--;)
62 scm_gc_mark (sc
->defs_
[i
]->self_scm ());
68 Score::print_smob (SCM
, SCM p
, scm_print_state
*)
70 scm_puts ("#<Score>", p
);
78 store point & click locations.
79 Global to save some time. (Sue us!)
82 Score::Score (Score
const &s
)
89 Music
* m
=unsmob_music (s
.music_
);
90 music_
= m
?m
->clone ()->self_scm () : SCM_EOL
;
91 scm_gc_unprotect_object (music_
);
93 for (int i
= 0; i
< s
.defs_
.size (); i
++)
94 defs_
.push (s
.defs_
[i
]->clone ());
96 header_
= ly_make_anonymous_module ();
97 if (ly_module_p (s
.header_
))
98 ly_import_module (header_
, s
.header_
);
101 LY_DEFINE (ly_run_translator
, "ly:run-translator",
102 2, 0, 0, (SCM mus
, SCM output_def
),
103 "Process @var{mus} according to @var{output_def}. "
104 "An interpretation context is set up, "
105 "and @var{mus} is interpreted with it. "
106 "The context is returned in its final state.")
108 Music_output_def
*odef
= unsmob_music_output_def (output_def
);
109 Music
*music
= unsmob_music (mus
);
111 SCM_ASSERT_TYPE (music
, mus
, SCM_ARG1
, __FUNCTION__
, "Music");
112 SCM_ASSERT_TYPE (odef
, output_def
, SCM_ARG2
, __FUNCTION__
, "Output definition");
116 Global_context
* trans
= new Global_context (odef
,
122 programming_error ("no toplevel translator");
125 progress_indication (_ ("Interpreting music... "));
127 SCM protected_iter
= Music_iterator::get_static_get_iterator (music
);
128 Music_iterator
* iter
= unsmob_iterator (protected_iter
);
129 iter
->init_translator (music
, trans
);
131 iter
->construct_children ();
135 warning (_ ("Need music in a score"));
136 return SCM_BOOL_F
; // todo: should throw exception.
139 trans
->run_iterator_on_me (iter
);
141 scm_remember_upto_here_1 (protected_iter
);
144 if (verbose_global_b
)
145 progress_indication (_f ("elapsed time: %.2f seconds", timer
.read ()));
148 return scm_gc_unprotect_object (trans
->self_scm ());
151 LY_DEFINE (ly_format_output
, "ly:format-output",
152 2, 0, 0, (SCM context
, SCM outname
),
153 "Given a Score context in its final state,"
154 "process it and return the (rendered) result.")
156 Global_context
*g
= dynamic_cast<Global_context
*> (unsmob_context (context
));
157 SCM_ASSERT_TYPE (g
, context
, SCM_ARG1
, __FUNCTION__
, "Global context");
158 SCM_ASSERT_TYPE (ly_string_p (outname
), outname
, SCM_ARG2
, __FUNCTION__
, "output filename");
160 Music_output
*output
= g
->get_output ();
161 progress_indication ("\n");
162 // ugh, midi still wants outname
163 return output
->process (ly_scm2string (outname
));
167 default_rendering (SCM music
, SCM outdef
, SCM header
, SCM outname
)
169 SCM context
= ly_run_translator (music
, outdef
);
171 if (Global_context
*g
= dynamic_cast<Global_context
*>
172 (unsmob_context (context
)))
174 SCM systems
= ly_format_output (context
, outname
);
175 Music_output
*output
= g
->get_output ();
176 if (systems
!= SCM_UNDEFINED
)
178 Paper_score
*ps
= dynamic_cast<Paper_score
*> (output
);
180 paper_book
->papers_
.push (ps
->paper_
);
181 paper_book
->scores_
.push (systems
);
182 paper_book
->global_headers_
.push (global_input_file
->header_
);
183 paper_book
->headers_
.push (header
);
184 if (output_format_global
!= PAGE_LAYOUT
)
185 paper_book
->classic_output (ly_scm2string (outname
));