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"
15 #include "global-context.hh"
17 #include "music-iterator.hh"
18 #include "music-output.hh"
20 #include "output-def.hh"
21 #include "paper-book.hh"
24 #include "text-interface.hh"
27 #include "performance.hh"
28 #include "paper-score.hh"
30 #include "ly-smobs.icc"
44 return new Book (*this);
51 IMPLEMENT_SMOBS (Book);
52 IMPLEMENT_DEFAULT_EQUAL_P (Book);
55 Book::mark_smob (SCM s)
57 Book *book = (Book *) SCM_CELL_WORD_1 (s);
61 scm_gc_mark (book->key_->self_scm ());
65 scm_gc_mark (book->paper_->self_scm ());
66 scm_gc_mark (book->scores_);
72 Book::print_smob (SCM, SCM p, scm_print_state*)
74 scm_puts ("#<Book>", p);
79 Book::add_score (SCM s)
81 scores_ = scm_cons (s, scores_);
85 /* Concatenate all score outputs into a Paper_book
88 Book::process (Output_def *default_paper,
89 Output_def *default_layout)
91 for (SCM s = scores_; s != SCM_EOL; s = scm_cdr (s))
92 if (Score *score = unsmob_score (scm_car (s)))
93 if (score->error_found_)
96 Output_def *paper = paper_ ? paper_ : default_paper;
100 Paper_book *paper_book = new Paper_book ();
101 Real scale = scm_to_double (paper->c_variable ("output-scale"));
102 Output_def *scaled_bookdef = scale_output_def (paper, scale);
104 Object_key *key = new Lilypond_general_key (0, user_key_, 0);
105 SCM scm_key = key->unprotect ();
107 paper_book->paper_ = scaled_bookdef;
108 scaled_bookdef->unprotect ();
110 paper_book->header_ = header_;
112 /* Render in order of parsing. */
113 for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
115 if (Score *score = unsmob_score (scm_car (s)))
118 ->book_rendering (paper_book->paper_, default_layout, key);
120 while (scm_is_pair (outputs))
122 Music_output *output = unsmob_music_output (scm_car (outputs));
124 if (Performance *perf = dynamic_cast<Performance *> (output))
125 paper_book->add_performance (perf->self_scm ());
126 else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
128 if (ly_is_module (score->header_))
129 paper_book->add_score (score->header_);
130 paper_book->add_score (pscore->self_scm ());
133 outputs = scm_cdr (outputs);
136 else if (Text_interface::is_markup (scm_car (s)))
137 paper_book->add_score (scm_car (s));
142 scm_remember_upto_here_1 (scm_key);