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)
68 for (int i = 0; i < scores_.size(); i++)
69 error |= scores_[i]->error_found_;
74 Paper_book *paper_book = new Paper_book ();
75 Real scale = scm_to_double (bookpaper_->c_variable ("outputscale"));
77 Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale);
79 paper_book->bookpaper_ = scaled_bookdef;
80 scm_gc_unprotect_object (scaled_bookdef->self_scm());
82 paper_book->header_ = header_;
84 int score_count = scores_.size ();
85 for (int i = 0; i < score_count; i++)
87 SCM systems = scores_[i]->book_rendering (outname,
88 paper_book->bookpaper_,
91 /* If the score is empty, generate no output. Should we
93 if (SCM_NFALSEP(scm_vector_p (systems)))
96 sc.systems_ = systems;
97 sc.header_ = scores_[i]->header_;
98 paper_book->score_systems_.push (sc);
105 LY_DEFINE(ly_make_book, "ly:make-book",
106 2, 0, 1, (SCM bookpaper, SCM header, SCM scores),
107 "Make a \\book of @var{bookpaper} and @var{header} (which may be #f as well) "
108 "containing @code{\\scores}.")
110 Output_def * odef = unsmob_output_def (bookpaper);
111 SCM_ASSERT_TYPE (odef, bookpaper,
112 SCM_ARG1, __FUNCTION__, "Output_def");
114 Book *book = new Book;
115 book->bookpaper_ = odef;
117 if (ly_c_module_p (header))
118 book->header_ = header;
120 for (SCM s = scores; ly_c_pair_p (s); s = ly_cdr (s))
122 Score *score = unsmob_score (ly_car (s));
124 book->scores_.push (score);
127 SCM x = book->self_scm ();
128 scm_gc_unprotect_object (x);