2 paper-book.cc -- implement Paper_book
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "paper-book.hh"
12 #include "output-def.hh"
13 #include "paper-score.hh"
14 #include "paper-system.hh"
15 #include "text-interface.hh"
18 #include "ly-smobs.icc"
20 Paper_book::Paper_book ()
26 performances_ = SCM_EOL;
27 systems_ = SCM_BOOL_F;
33 Paper_book::~Paper_book ()
37 IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
38 IMPLEMENT_SMOBS (Paper_book);
39 IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?");
42 Paper_book::mark_smob (SCM smob)
44 Paper_book *b = (Paper_book *) SCM_CELL_WORD_1 (smob);
46 scm_gc_mark (b->paper_->self_scm ());
47 scm_gc_mark (b->header_);
48 scm_gc_mark (b->header_0_);
49 scm_gc_mark (b->pages_);
50 scm_gc_mark (b->performances_);
51 scm_gc_mark (b->scores_);
56 Paper_book::print_smob (SCM smob, SCM port, scm_print_state*)
58 Paper_book *b = (Paper_book *) SCM_CELL_WORD_1 (smob);
60 scm_puts ("#<Paper_book>", port);
68 for (int i = dump_header_fieldnames_global.size (); i--;)
70 = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
76 Paper_book::add_score (SCM s)
78 scores_ = scm_cons (s, scores_);
82 Paper_book::add_performance (SCM s)
84 performances_ = scm_cons (s, performances_);
88 Paper_book::output (SCM output_channel)
90 if (scm_is_pair (performances_))
92 SCM proc = ly_lily_module_constant ("paper-book-write-midis");
94 scm_call_2 (proc, self_scm (), output_channel);
97 if (scores_ == SCM_EOL)
100 /* Generate all stencils to trigger font loads. */
103 SCM scopes = SCM_EOL;
104 if (ly_is_module (header_))
105 scopes = scm_cons (header_, scopes);
107 String mod_nm = "scm framework-" + output_backend_global;
109 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
112 SCM func = scm_c_module_lookup (mod, "output-framework");
114 func = scm_variable_ref (func);
115 scm_apply_0 (func, scm_list_n (output_channel,
124 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
125 func = scm_variable_ref (func);
126 scm_apply_0 (func, scm_list_n (output_channel,
135 Paper_book::classic_output (SCM output)
137 /* Generate all stencils to trigger font loads. */
140 SCM scopes = SCM_EOL;
141 if (ly_is_module (header_))
142 scopes = scm_cons (header_, scopes);
144 if (ly_is_module (header_0_))
145 scopes = scm_cons (header_0_, scopes);
147 String format = output_backend_global;
148 String mod_nm = "scm framework-" + format;
150 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
151 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
153 func = scm_variable_ref (func);
154 scm_apply_0 (func, scm_list_n (output,
160 progress_indication ("\n");
163 /* TODO: resurrect more complex user-tweaks for titling? */
165 Paper_book::book_title ()
167 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
170 SCM scopes = SCM_EOL;
171 if (ly_is_module (header_))
172 scopes = scm_cons (header_, scopes);
175 if (ly_is_procedure (title_func))
176 tit = scm_call_2 (title_func,
180 if (unsmob_stencil (tit))
181 title = *unsmob_stencil (tit);
183 if (!title.is_empty ())
184 title.align_to (Y_AXIS, UP);
190 Paper_book::score_title (SCM header)
192 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
196 SCM scopes = SCM_EOL;
197 if (ly_is_module (header_))
198 scopes = scm_cons (header_, scopes);
200 if (ly_is_module (header))
201 scopes = scm_cons (header, scopes);
204 if (ly_is_procedure (title_func))
205 tit = scm_call_2 (title_func,
209 if (unsmob_stencil (tit))
210 title = *unsmob_stencil (tit);
212 if (!title.is_empty ())
213 title.align_to (Y_AXIS, UP);
219 set_system_penalty (Paper_system *ps, SCM header)
221 if (ly_is_module (header))
223 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
224 if (SCM_VARIABLEP (force)
225 && scm_is_bool (SCM_VARIABLE_REF (force)))
227 ps->set_property ("penalty",
228 scm_from_int(to_boolean (SCM_VARIABLE_REF (force))
236 Paper_book::add_score_title (SCM header)
238 Stencil title = score_title (header);
239 if (title.is_empty ())
240 title = score_title (header_);
241 if (!title.is_empty ())
244 TODO: this should come from the \layout {} block, which should
245 override settings from \paper {}
247 SCM props = paper_->lookup_variable (ly_symbol2scm ("score-title-properties"));
248 Paper_system *ps = new Paper_system (title, props);
249 systems_ = scm_cons (ps->self_scm (), systems_);
251 set_system_penalty (ps, header);
256 Paper_book::systems ()
258 if (systems_ != SCM_BOOL_F)
262 Stencil title = book_title ();
264 if (!title.is_empty ())
266 SCM props = paper_->lookup_variable (ly_symbol2scm ("book-title-properties"));
267 Paper_system *ps = new Paper_system (title, props);
268 set_system_penalty (ps, header_);
270 systems_ = scm_cons (ps->self_scm (), systems_);
275 = scm_call_1 (ly_lily_module_constant ("layout-extract-page-properties"),
276 paper_->self_scm ());
278 SCM header = SCM_EOL;
279 for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
281 if (ly_is_module (scm_car (s)))
283 header = scm_car (s);
284 if (header_0_ == SCM_EOL)
287 else if (Music_output *mop = unsmob_music_output (scm_car (s)))
290 if (Paper_score *pscore = dynamic_cast<Paper_score *> (mop))
292 add_score_title (header);
296 SCM system_list = scm_vector_to_list (pscore->get_paper_systems ());
297 system_list = scm_reverse (system_list);
298 systems_ = scm_append (scm_list_2 (system_list, systems_));
307 else if (scm_is_vector (scm_car (s)))
312 add_score_title (header);
315 SCM system_list = scm_vector_to_list (scm_car (s));
316 system_list = scm_reverse (system_list);
317 systems_ = scm_append (scm_list_2 (system_list, systems_));
319 else if (Text_interface::is_markup (scm_car (s)))
321 SCM t = Text_interface::interpret_markup (paper_->self_scm (),
326 Paper_system *ps = new Paper_system (*unsmob_stencil (t), SCM_EOL);
327 ps->set_property ("is-title", SCM_BOOL_T);
328 systems_ = scm_cons (ps->self_scm (), systems_);
331 // FIXME: figure out penalty.
332 //set_system_penalty (ps, scores_[i].header_);
338 systems_ = scm_reverse (systems_);
341 Paper_system *last = 0;
342 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
344 Paper_system *ps = unsmob_paper_system (scm_car (s));
345 ps->set_property ("number", scm_from_int (++i));
348 && to_boolean (last->get_property ("is-title"))
349 && !scm_is_number (ps->get_property ("penalty")))
350 ps->set_property ("penalty", scm_from_int (10000));
360 if (SCM_BOOL_F != pages_)
364 SCM proc = paper_->c_variable ("page-breaking");
365 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
370 Paper_book::performances () const
372 return scm_reverse (performances_);