2 paper-book.cc -- implement Paper_book
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "ly-module.hh"
11 #include "paper-book.hh"
12 #include "output-def.hh"
13 #include "paper-outputter.hh"
14 #include "paper-system.hh"
15 #include "paper-score.hh"
21 Ugh. the Function of the Paper_book class is unclear. Trim this
27 Paper_book::Paper_book ()
37 Paper_book::~Paper_book ()
41 #include "ly-smobs.icc"
43 IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
44 IMPLEMENT_SMOBS (Paper_book)
45 IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?")
48 Paper_book::mark_smob (SCM smob)
50 Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
51 for (int i = 0; i < b->score_lines_.size (); i++)
52 b->score_lines_[i].gc_mark ();
55 scm_gc_mark (b->bookpaper_->self_scm ());
56 scm_gc_mark (b->header_);
57 scm_gc_mark (b->pages_);
62 Paper_book::print_smob (SCM smob, SCM port, scm_print_state*)
64 Paper_book *b = (Paper_book*) ly_cdr (smob);
66 scm_puts ("#<", port);
67 scm_puts (classname (b), port);
69 //scm_puts (b->, port);
75 split_string (String s, char c)
84 s = s.nomid_string (0, 1);
91 rv.push (s.cut_string (0, i));
92 s = s.nomid_string (0, i);
101 SCM fields = SCM_EOL;
102 for (int i = dump_header_fieldnames_global.size (); i--; )
104 = scm_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
109 LY_DEFINE (ly_output_formats, "ly:output-formats",
111 "Formats passed to --format as a list of strings, "
112 "used for the output.")
114 Array<String> output_formats = split_string (output_format_global, ',');
117 for (int i = 0; i < output_formats.size (); i ++)
118 lst = scm_cons (scm_makfrom0str (output_formats[i].to_str0 ()), lst);
124 Paper_book::output (String outname)
126 if (!score_lines_.size ())
130 /* Generate all stencils to trigger font loads. */
134 SCM formats = ly_output_formats();
135 for (SCM s = formats; ly_c_pair_p (s); s = ly_cdr (s))
137 String format = ly_scm2string (ly_car (s));
139 Paper_outputter *out = get_paper_outputter (outname + "." + format, format);
141 SCM scopes = SCM_EOL;
142 if (ly_c_module_p (header_))
143 scopes = scm_cons (header_, scopes);
145 String func_nm = format;
146 func_nm = "output-framework-" + func_nm;
148 SCM func = ly_scheme_function (func_nm.to_str0 ());
149 scm_apply_0 (func, scm_list_n (out->self_scm (),
153 scm_makfrom0str (outname.to_str0 ()),
157 scm_gc_unprotect_object (out->self_scm ());
163 Paper_book::classic_output (String outname)
166 /* Generate all stencils to trigger font loads. */
171 SCM scopes = SCM_EOL;
172 if (ly_c_module_p (header_))
173 scopes = scm_cons (header_, scopes);
175 if (ly_c_module_p (score_lines_[0].header_))
176 scopes = scm_cons (score_lines_[0].header_, scopes);
180 Array<String> output_formats = split_string (output_format_global, ',');
182 for (int i = 0; i < output_formats.size (); i++)
184 String format = output_formats[i];
185 String func_nm = format;
186 func_nm = "output-classic-framework-" + func_nm;
188 SCM func = ly_scheme_function (func_nm.to_str0 ());
190 Paper_outputter *out = get_paper_outputter (outname + "." + format, format);
192 scm_apply_0 (func, scm_list_n (out->self_scm (),
196 scm_makfrom0str (outname.to_str0 ()),
200 scm_gc_unprotect_object (out->self_scm ());
203 progress_indication ("\n");
209 LY_DEFINE(ly_paper_book_pages, "ly:paper-book-pages",
212 "Return pages in book PB.")
214 return unsmob_paper_book(pb)->pages ();
218 LY_DEFINE(ly_paper_book_scopes, "ly:paper-book-scopes",
221 "Return pages in paper book @var{book}.")
223 Paper_book * pb = unsmob_paper_book(book);
224 SCM_ASSERT_TYPE(pb, book, SCM_ARG1, __FUNCTION__, "Paper_book");
226 SCM scopes = SCM_EOL;
227 if (ly_c_module_p (pb->header_))
228 scopes = scm_cons (pb->header_, scopes);
234 LY_DEFINE(ly_paper_book_lines, "ly:paper-book-lines",
237 "Return lines in book PB.")
239 return unsmob_paper_book (pb)->lines ();
243 LY_DEFINE(ly_paper_book_book_paper, "ly:paper-book-book-paper",
246 "Return pages in book PB.")
248 return unsmob_paper_book(pb)->bookpaper_->self_scm ();
253 TODO: resurrect more complex user-tweaks for titling?
257 Paper_book::book_title ()
259 SCM title_func = bookpaper_->lookup_variable (ly_symbol2scm ("book-title"));
262 SCM scopes = SCM_EOL;
263 if (ly_c_module_p (header_))
264 scopes = scm_cons (header_, scopes);
268 if (ly_c_procedure_p (title_func))
269 tit = scm_call_2 (title_func,
270 bookpaper_->self_scm (),
273 if (unsmob_stencil (tit))
274 title = *unsmob_stencil (tit);
276 if (!title.is_empty ())
277 title.align_to (Y_AXIS, UP);
285 Paper_book::score_title (int i)
287 SCM title_func = bookpaper_->lookup_variable (ly_symbol2scm ("score-title"));
292 SCM scopes = SCM_EOL;
293 if (ly_c_module_p (header_))
294 scopes = scm_cons (header_, scopes);
296 if (ly_c_module_p (score_lines_[i].header_))
297 scopes = scm_cons (score_lines_[i].header_, scopes);
301 if (ly_c_procedure_p (title_func))
302 tit = scm_call_2 (title_func,
303 bookpaper_->self_scm (),
306 if (unsmob_stencil (tit))
307 title = *unsmob_stencil (tit);
310 if (!title.is_empty ())
311 title.align_to (Y_AXIS, UP);
320 if (SCM_BOOL_F != lines_)
324 Stencil title = book_title ();
326 if (!title.is_empty ())
328 Paper_system *pl = new Paper_system (title, true);
330 lines_ = scm_cons (pl->self_scm (), lines_);
331 scm_gc_unprotect_object (pl->self_scm ());
334 int score_count = score_lines_.size ();
335 for (int i = 0; i < score_count; i++)
337 Stencil title = score_title (i);
338 if (!title.is_empty ())
340 Paper_system *pl = new Paper_system (title, true);
341 lines_ = scm_cons (pl->self_scm (), lines_);
342 scm_gc_unprotect_object (pl->self_scm ());
345 if (scm_vector_p (score_lines_[i].lines_) == SCM_BOOL_T)
347 SCM line_list = scm_vector_to_list (score_lines_[i].lines_); // guh.
349 line_list = scm_reverse (line_list);
350 lines_ = scm_append (scm_list_2 (line_list, lines_));
354 lines_ = scm_reverse (lines_);
357 Paper_system * last = 0;
358 for (SCM s = lines_; s != SCM_EOL; s = ly_cdr (s))
360 Paper_system * p = unsmob_paper_line (ly_car (s));
363 if (last && last->is_title ())
365 p->penalty_ = 10000; // ugh, hardcoded.
378 if (SCM_BOOL_F != pages_)
383 Output_def *paper = bookpaper_;
385 SCM proc = paper->c_variable ("page-breaking");
386 pages_ = scm_apply_0 (proc, scm_list_n (lines (),
396 /****************************************************************/
398 Score_lines::Score_lines ()
405 Score_lines::gc_mark ()
407 scm_gc_mark (lines_);
408 scm_gc_mark (header_);