2 book.cc -- implement Book
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
14 #include "lilypond-key.hh"
16 #include "music-output.hh"
18 #include "output-def.hh"
19 #include "paper-book.hh"
22 #include "text-interface.hh"
24 #include "performance.hh"
25 #include "paper-score.hh"
27 #include "ly-smobs.icc"
34 input_location_ = SCM_EOL;
37 input_location_ = make_input (Input ());
40 Book::Book (Book const &s)
45 input_location_ = SCM_EOL;
49 paper_ = s.paper_->clone ();
51 input_location_ = make_input (*s.origin ());
52 header_ = ly_make_anonymous_module (false);
53 if (ly_is_module (s.header_))
54 ly_module_copy (header_, s.header_);
57 for (SCM p = s.scores_; scm_is_pair (p); p = scm_cdr (p))
59 Score *newscore = unsmob_score (scm_car (p))->clone ();
61 *t = scm_cons (newscore->self_scm (), SCM_EOL);
63 newscore->unprotect ();
70 return unsmob_input (input_location_);
77 IMPLEMENT_SMOBS (Book);
78 IMPLEMENT_DEFAULT_EQUAL_P (Book);
81 Book::mark_smob (SCM s)
83 Book *book = (Book *) SCM_CELL_WORD_1 (s);
87 scm_gc_mark (book->key_->self_scm ());
91 scm_gc_mark (book->paper_->self_scm ());
92 scm_gc_mark (book->scores_);
93 scm_gc_mark (book->input_location_);
99 Book::print_smob (SCM, SCM p, scm_print_state*)
101 scm_puts ("#<Book>", p);
106 Book::add_score (SCM s)
108 scores_ = scm_cons (s, scores_);
112 /* Concatenate all score outputs into a Paper_book
115 Book::process (Output_def *default_paper,
116 Output_def *default_layout)
118 for (SCM s = scores_; scm_is_pair (s); s = scm_cdr (s))
119 if (Score *score = unsmob_score (scm_car (s)))
120 if (score->error_found_)
123 Output_def *paper = paper_ ? paper_ : default_paper;
127 Paper_book *paper_book = new Paper_book ();
128 Real scale = scm_to_double (paper->c_variable ("output-scale"));
129 Output_def *scaled_bookdef = scale_output_def (paper, scale);
131 Object_key *key = new Lilypond_general_key (0, user_key_, 0);
132 SCM scm_key = key->unprotect ();
134 paper_book->paper_ = scaled_bookdef;
135 scaled_bookdef->unprotect ();
137 paper_book->header_ = header_;
139 /* Render in order of parsing. */
140 for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s))
142 if (Score *score = unsmob_score (scm_car (s)))
145 ->book_rendering (paper_book->paper_, default_layout, key);
147 while (scm_is_pair (outputs))
149 Music_output *output = unsmob_music_output (scm_car (outputs));
151 if (Performance *perf = dynamic_cast<Performance *> (output))
152 paper_book->add_performance (perf->self_scm ());
153 else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
155 if (ly_is_module (score->header_))
156 paper_book->add_score (score->header_);
157 paper_book->add_score (pscore->self_scm ());
160 outputs = scm_cdr (outputs);
163 else if (Text_interface::is_markup (scm_car (s)))
164 paper_book->add_score (scm_car (s));
169 scm_remember_upto_here_1 (scm_key);