2 book.cc -- implement Book
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "global-context.hh"
13 #include "ly-module.hh"
15 #include "music-iterator.hh"
16 #include "music-output.hh"
18 #include "output-def.hh"
19 #include "paper-book.hh"
24 #include "ly-smobs.icc"
31 assert (!scores_.size ());
39 IMPLEMENT_SMOBS (Book);
40 IMPLEMENT_DEFAULT_EQUAL_P (Book);
43 Book::mark_smob (SCM s)
45 Book *book = (Book*) SCM_CELL_WORD_1 (s);
46 int score_count = book->scores_.size ();
47 for (int i = 0; i < score_count; i++)
48 scm_gc_mark (book->scores_[i]->self_scm ());
51 scm_gc_mark (book->bookpaper_->self_scm ());
56 Book::print_smob (SCM, SCM p, scm_print_state*)
58 scm_puts ("#<Book>", p);
62 /* This function does not dump the output; outname is required eg. for
63 dumping header fields. */
65 Book::process (String outname, Output_def *default_def)
67 Paper_book *paper_book = new Paper_book ();
68 Real scale = ly_scm2double (bookpaper_->c_variable ("outputscale"));
70 Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale);
72 paper_book->bookpaper_ = scaled_bookdef;
73 scm_gc_unprotect_object (scaled_bookdef->self_scm());
75 paper_book->header_ = header_;
77 int score_count = scores_.size ();
78 for (int i = 0; i < score_count; i++)
80 SCM systems = scores_[i]->book_rendering (outname,
81 paper_book->bookpaper_,
84 /* If the score is empty, generate no output. Should we
86 if (SCM_NFALSEP(scm_vector_p (systems)))
91 paper_book->score_lines_.push (sc);
98 LY_DEFINE(ly_make_book, "ly:make-book",
99 2, 0, 1, (SCM bookpaper, SCM header, SCM scores),
100 "Make a \\book of @var{bookpaper} and @var{header} (which may be #f as well) "
101 "containing @code{\scores}.")
103 Output_def * odef = unsmob_output_def (bookpaper);
104 SCM_ASSERT_TYPE (odef, bookpaper,
105 SCM_ARG1, __FUNCTION__, "Output_def");
107 Book *book = new Book;
108 book->bookpaper_ = odef;
110 if (ly_c_module_p (header))
111 book->header_ = header;
113 for (SCM s = scores; ly_c_pair_p (s); s = ly_cdr (s))
115 Score *score = unsmob_score (ly_car (s));
117 book->scores_.push (score);
120 SCM x = book->self_scm ();
121 scm_gc_unprotect_object (x);