2 book.cc -- implement Book
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
14 #include "lilypond-key.hh"
17 #include "output-def.hh"
18 #include "paper-book.hh"
20 #include "text-interface.hh"
22 #include "performance.hh"
23 #include "paper-score.hh"
25 #include "ly-smobs.icc"
32 input_location_ = SCM_EOL;
35 input_location_ = make_input (Input ());
38 Book::Book (Book const &s)
43 input_location_ = SCM_EOL;
48 paper_ = s.paper_->clone ();
52 input_location_ = make_input (*s.origin ());
54 header_ = ly_make_anonymous_module (false);
55 if (ly_is_module (s.header_))
56 ly_module_copy (header_, s.header_);
59 for (SCM p = s.scores_; scm_is_pair (p); p = scm_cdr (p))
61 Score *newscore = unsmob_score (scm_car (p))->clone ();
63 *t = scm_cons (newscore->self_scm (), SCM_EOL);
65 newscore->unprotect ();
72 return unsmob_input (input_location_);
79 IMPLEMENT_SMOBS (Book);
80 IMPLEMENT_DEFAULT_EQUAL_P (Book);
83 Book::mark_smob (SCM s)
85 Book *book = (Book *) SCM_CELL_WORD_1 (s);
89 scm_gc_mark (book->key_->self_scm ());
93 scm_gc_mark (book->paper_->self_scm ());
94 scm_gc_mark (book->scores_);
95 scm_gc_mark (book->input_location_);
101 Book::print_smob (SCM, SCM p, scm_print_state*)
103 scm_puts ("#<Book>", p);
108 Book::add_score (SCM s)
110 scores_ = scm_cons (s, scores_);
114 /* Concatenate all score outputs into a Paper_book
117 Book::process (Output_def *default_paper,
118 Output_def *default_layout)
120 for (SCM s = scores_; scm_is_pair (s); s = scm_cdr (s))
121 if (Score *score = unsmob_score (scm_car (s)))
122 if (score->error_found_)
125 Output_def *paper = paper_ ? paper_ : default_paper;
129 Paper_book *paper_book = new Paper_book ();
130 Real scale = scm_to_double (paper->c_variable ("output-scale"));
131 Output_def *scaled_bookdef = scale_output_def (paper, scale);
133 Object_key *key = new Lilypond_general_key (0, user_key_, 0);
134 SCM scm_key = key->unprotect ();
136 paper_book->paper_ = scaled_bookdef;
137 scaled_bookdef->unprotect ();
139 paper_book->header_ = header_;
141 /* Render in order of parsing. */
142 for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s))
144 if (Score *score = unsmob_score (scm_car (s)))
147 ->book_rendering (paper_book->paper_, default_layout);
149 while (scm_is_pair (outputs))
151 Music_output *output = unsmob_music_output (scm_car (outputs));
153 if (Performance *perf = dynamic_cast<Performance *> (output))
154 paper_book->add_performance (perf->self_scm ());
155 else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
157 if (ly_is_module (score->header_))
158 paper_book->add_score (score->header_);
159 paper_book->add_score (pscore->self_scm ());
162 outputs = scm_cdr (outputs);
165 else if (Text_interface::is_markup (scm_car (s)))
166 paper_book->add_score (scm_car (s));
171 scm_remember_upto_here_1 (scm_key);