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>
13 #include "lilypond-key.hh"
14 #include "global-context.hh"
15 #include "ly-module.hh"
17 #include "music-iterator.hh"
18 #include "music-output.hh"
20 #include "output-def.hh"
21 #include "paper-book.hh"
26 #include "ly-smobs.icc"
33 assert (!scores_.size ());
41 IMPLEMENT_SMOBS (Book);
42 IMPLEMENT_DEFAULT_EQUAL_P (Book);
45 Book::mark_smob (SCM s)
47 Book *book = (Book*) SCM_CELL_WORD_1 (s);
48 int score_count = book->scores_.size ();
49 for (int i = 0; i < score_count; i++)
50 scm_gc_mark (book->scores_[i]->self_scm ());
54 scm_gc_mark (book->key_->self_scm());
57 scm_gc_mark (book->paper_->self_scm ());
62 Book::print_smob (SCM, SCM p, scm_print_state*)
64 scm_puts ("#<Book>", p);
68 /* This function does not dump the output; outname is required eg. for
69 dumping header fields. */
71 Book::process (String outname, Output_def *default_def)
74 for (int i = 0; i < scores_.size(); i++)
75 error = error || scores_[i]->error_found_;
80 Paper_book *paper_book = new Paper_book ();
81 Real scale = scm_to_double (paper_->c_variable ("outputscale"));
82 Output_def * scaled_bookdef = scale_output_def (paper_, scale);
85 Object_key * key = new Lilypond_general_key (0, user_key_, 0);
86 SCM scm_key = key->self_scm();
87 scm_gc_unprotect_object (scm_key);
89 paper_book->paper_ = scaled_bookdef;
90 scm_gc_unprotect_object (scaled_bookdef->self_scm());
92 paper_book->header_ = header_;
93 int score_count = scores_.size ();
94 for (int i = 0; i < score_count; i++)
96 SCM systems = scores_[i]->book_rendering (outname,
103 If the score is empty, generate no output. Should we
106 if (SCM_NFALSEP(scm_vector_p (systems)))
109 sc.systems_ = systems;
110 sc.header_ = scores_[i]->header_;
111 paper_book->score_systems_.push (sc);
116 scm_remember_upto_here_1 (scm_key);
120 LY_DEFINE(ly_make_book, "ly:make-book",
121 2, 0, 1, (SCM paper, SCM header, SCM scores),
122 "Make a \\book of @var{paper} and @var{header} (which may be #f as well) "
123 "containing @code{\\scores}.")
125 Output_def * odef = unsmob_output_def (paper);
126 SCM_ASSERT_TYPE (odef, paper,
127 SCM_ARG1, __FUNCTION__, "Output_def");
129 Book *book = new Book;
132 if (ly_c_module_p (header))
133 book->header_ = header;
135 for (SCM s = scores; scm_is_pair (s); s = scm_cdr (s))
137 Score *score = unsmob_score (scm_car (s));
139 book->scores_.push (score);
142 SCM x = book->self_scm ();
143 scm_gc_unprotect_object (x);
149 Book::add_score (Score *s)
152 scm_gc_unprotect_object (s->self_scm ());