2 book.cc -- implement Book
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
16 #include "output-def.hh"
17 #include "paper-book.hh"
19 #include "text-interface.hh"
21 #include "performance.hh"
22 #include "paper-score.hh"
23 #include "page-marker.hh"
25 #include "ly-smobs.icc"
33 input_location_ = SCM_EOL;
36 input_location_ = make_input (Input ());
39 Book::Book (Book const &s)
45 input_location_ = SCM_EOL;
50 paper_ = s.paper_->clone ();
54 input_location_ = make_input (*s.origin ());
56 header_ = ly_make_anonymous_module (false);
57 if (ly_is_module (s.header_))
58 ly_module_copy (header_, s.header_);
61 for (SCM p = s.scores_; scm_is_pair (p); p = scm_cdr (p))
63 Score *newscore = unsmob_score (scm_car (p))->clone ();
65 *t = scm_cons (newscore->self_scm (), SCM_EOL);
67 newscore->unprotect ();
71 for (SCM p = s.bookparts_; scm_is_pair (p); p = scm_cdr (p))
73 Book *newpart = unsmob_book (scm_car (p))->clone ();
75 *t = scm_cons (newpart->self_scm (), SCM_EOL);
77 newpart->unprotect ();
84 return unsmob_input (input_location_);
91 IMPLEMENT_SMOBS (Book);
92 IMPLEMENT_DEFAULT_EQUAL_P (Book);
95 Book::mark_smob (SCM s)
97 Book *book = (Book *) SCM_CELL_WORD_1 (s);
100 scm_gc_mark (book->paper_->self_scm ());
101 scm_gc_mark (book->scores_);
102 scm_gc_mark (book->bookparts_);
103 scm_gc_mark (book->input_location_);
105 return book->header_;
109 Book::print_smob (SCM, SCM p, scm_print_state*)
111 scm_puts ("#<Book>", p);
116 Book::add_score (SCM s)
118 scores_ = scm_cons (s, scores_);
122 Book::set_parent (Book *parent)
126 paper_ = new Output_def ();
127 paper_->unprotect ();
129 paper_->parent_ = parent->paper_;
130 /* If this part is the first child of parent, copy its header */
131 if (ly_is_module (parent->header_) && (scm_is_null (parent->bookparts_)))
133 header_ = ly_make_anonymous_module (false);
134 ly_module_copy (header_, parent->header_);
139 Book::add_bookpart ()
141 if (scm_is_pair (scores_))
143 warning ("add_bookpart");
144 /* If scores have been added to this book, add them to a child
146 Book *part = new Book;
147 part->set_parent (this);
148 part->scores_ = scores_;
149 bookparts_ = scm_cons (part->self_scm (), bookparts_);
156 Book::add_bookpart (SCM b)
159 Book *part = unsmob_book (b);
160 part->set_parent (this);
161 bookparts_ = scm_cons (b, bookparts_);
167 for (SCM s = scores_; scm_is_pair (s); s = scm_cdr (s))
168 if (Score *score = unsmob_score (scm_car (s)))
169 if (score->error_found_)
172 for (SCM part = bookparts_; scm_is_pair (part); part = scm_cdr (part))
173 if (Book *bookpart = unsmob_book (scm_car (part)))
174 if (bookpart->error_found ())
181 Book::process (Output_def *default_paper,
182 Output_def *default_layout)
184 return process (default_paper, default_layout, 0);
187 /* Concatenate all score or book part outputs into a Paper_book
190 Book::process (Output_def *default_paper,
191 Output_def *default_layout,
192 Paper_book *parent_part)
194 Output_def *paper = paper_ ? paper_ : default_paper;
196 /* If top book, recursively check score errors */
197 if (!parent_part && error_found ())
203 Paper_book *paper_book = new Paper_book ();
204 Real scale = scm_to_double (paper->c_variable ("output-scale"));
205 Output_def *scaled_bookdef = scale_output_def (paper, scale);
206 paper_book->paper_ = scaled_bookdef;
209 paper_book->parent_ = parent_part;
210 paper_book->paper_->parent_ = parent_part->paper_;
212 paper_book->header_ = header_;
214 if (scm_is_pair (bookparts_))
216 /* Process children book parts */
218 for (SCM p = scm_reverse (bookparts_); scm_is_pair (p); p = scm_cdr (p))
220 if (Book *book = unsmob_book (scm_car (p)))
222 Paper_book *paper_book_part = book
223 ->process (paper, default_layout, paper_book);
225 paper_book->add_bookpart (paper_book_part->self_scm ());
232 /* Render in order of parsing. */
233 for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s))
235 if (Score *score = unsmob_score (scm_car (s)))
238 ->book_rendering (paper_book->paper_, default_layout);
240 while (scm_is_pair (outputs))
242 Music_output *output = unsmob_music_output (scm_car (outputs));
244 if (Performance *perf = dynamic_cast<Performance *> (output))
245 paper_book->add_performance (perf->self_scm ());
246 else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
248 if (ly_is_module (score->get_header ()))
249 paper_book->add_score (score->get_header ());
250 paper_book->add_score (pscore->self_scm ());
253 outputs = scm_cdr (outputs);
256 else if (Text_interface::is_markup_list (scm_car (s))
257 || unsmob_page_marker (scm_car (s)))
258 paper_book->add_score (scm_car (s));