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 ("#<", port);
61 scm_puts (classname (b), port);
71 for (int i = dump_header_fieldnames_global.size (); i--;)
73 = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
79 Paper_book::add_score (SCM s)
81 scores_ = scm_cons (s, scores_);
86 Paper_book::add_performance (SCM s)
88 performances_ = scm_cons (s, performances_);
93 Paper_book::output (SCM output_channel)
95 if (scores_ == SCM_EOL)
98 /* Generate all stencils to trigger font loads. */
101 SCM scopes = SCM_EOL;
102 if (ly_is_module (header_))
103 scopes = scm_cons (header_, scopes);
105 String mod_nm = "scm framework-" + output_backend_global;
107 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
110 SCM func = scm_c_module_lookup (mod, "output-framework");
112 func = scm_variable_ref (func);
113 scm_apply_0 (func, scm_list_n (output_channel,
122 SCM func = scm_c_module_lookup (mod, "output-preview-framework");
123 func = scm_variable_ref (func);
124 scm_apply_0 (func, scm_list_n (output_channel,
133 Paper_book::classic_output (SCM output)
135 /* Generate all stencils to trigger font loads. */
138 SCM scopes = SCM_EOL;
139 if (ly_is_module (header_))
140 scopes = scm_cons (header_, scopes);
142 if (ly_is_module (header_0_))
143 scopes = scm_cons (header_0_, scopes);
145 String format = output_backend_global;
146 String mod_nm = "scm framework-" + format;
148 SCM mod = scm_c_resolve_module (mod_nm.to_str0 ());
149 SCM func = scm_c_module_lookup (mod, "output-classic-framework");
151 func = scm_variable_ref (func);
152 scm_apply_0 (func, scm_list_n (output,
158 progress_indication ("\n");
161 /* TODO: resurrect more complex user-tweaks for titling? */
163 Paper_book::book_title ()
165 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("book-title"));
168 SCM scopes = SCM_EOL;
169 if (ly_is_module (header_))
170 scopes = scm_cons (header_, scopes);
173 if (ly_is_procedure (title_func))
174 tit = scm_call_2 (title_func,
178 if (unsmob_stencil (tit))
179 title = *unsmob_stencil (tit);
181 if (!title.is_empty ())
182 title.align_to (Y_AXIS, UP);
188 Paper_book::score_title (SCM header)
190 SCM title_func = paper_->lookup_variable (ly_symbol2scm ("score-title"));
194 SCM scopes = SCM_EOL;
195 if (ly_is_module (header_))
196 scopes = scm_cons (header_, scopes);
198 if (ly_is_module (header))
199 scopes = scm_cons (header, scopes);
202 if (ly_is_procedure (title_func))
203 tit = scm_call_2 (title_func,
207 if (unsmob_stencil (tit))
208 title = *unsmob_stencil (tit);
210 if (!title.is_empty ())
211 title.align_to (Y_AXIS, UP);
217 set_system_penalty (Paper_system *ps, SCM header)
219 if (ly_is_module (header))
221 SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore"));
222 if (SCM_VARIABLEP (force)
223 && scm_is_bool (SCM_VARIABLE_REF (force)))
225 ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF (force))
233 Paper_book::add_score_title (SCM header)
235 Stencil title = score_title (header);
236 if (title.is_empty ())
237 title = score_title (header_);
238 if (!title.is_empty ())
240 Paper_system *ps = new Paper_system (title, true);
241 systems_ = scm_cons (ps->self_scm (), systems_);
242 scm_gc_unprotect_object (ps->self_scm ());
243 set_system_penalty (ps, header);
248 Paper_book::systems ()
250 if (systems_ != SCM_BOOL_F)
254 Stencil title = book_title ();
256 if (!title.is_empty ())
258 Paper_system *ps = new Paper_system (title, true);
259 set_system_penalty (ps, header_);
261 systems_ = scm_cons (ps->self_scm (), systems_);
262 scm_gc_unprotect_object (ps->self_scm ());
266 = scm_call_1 (ly_lily_module_constant ("layout-extract-page-properties"),
267 paper_->self_scm ());
269 SCM header = SCM_EOL;
270 for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
272 if (ly_is_module (scm_car (s)))
274 header = scm_car (s);
275 if (header_0_ == SCM_EOL)
278 else if (Music_output *mop = unsmob_music_output (scm_car (s)))
281 if (Paper_score *pscore = dynamic_cast<Paper_score *> (mop))
283 add_score_title (header);
287 SCM system_list = scm_vector_to_list (pscore->get_paper_systems ());
288 system_list = scm_reverse (system_list);
289 systems_ = scm_append (scm_list_2 (system_list, systems_));
298 else if (scm_is_vector (scm_car (s)))
303 add_score_title (header);
306 SCM system_list = scm_vector_to_list (scm_car (s));
307 system_list = scm_reverse (system_list);
308 systems_ = scm_append (scm_list_2 (system_list, systems_));
310 else if (Text_interface::markup_p (scm_car (s)))
312 SCM t = Text_interface::interpret_markup (paper_->self_scm (),
315 // FIXME: title=true?
316 Paper_system *ps = new Paper_system (*unsmob_stencil (t), true);
317 systems_ = scm_cons (ps->self_scm (), systems_);
318 scm_gc_unprotect_object (ps->self_scm ());
319 // FIXME: figure out penalty.
320 //set_system_penalty (ps, scores_[i].header_);
326 systems_ = scm_reverse (systems_);
329 Paper_system *last = 0;
330 for (SCM s = systems_; s != SCM_EOL; s = scm_cdr (s))
332 Paper_system *ps = unsmob_paper_system (scm_car (s));
337 && !ps->break_before_penalty_)
338 ps->break_before_penalty_ = 10000;
348 if (SCM_BOOL_F != pages_)
352 SCM proc = paper_->c_variable ("page-breaking");
353 pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
358 Paper_book::performances () const
360 return scm_reverse (performances_);