]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
(Score): oops. Copy error_found_ too.
[lilypond.git] / lily / book.cc
1 /*
2   book.cc -- implement Book
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <stdio.h>
10
11 #include "book.hh"
12 #include "global-context.hh"
13 #include "ly-module.hh"
14 #include "main.hh"
15 #include "music-iterator.hh"
16 #include "music-output.hh"
17 #include "music.hh"
18 #include "output-def.hh"
19 #include "paper-book.hh"
20 #include "score.hh"
21 #include "stencil.hh"
22 #include "warn.hh"
23
24 #include "ly-smobs.icc"
25
26 Book::Book ()
27   : Input ()
28 {
29   bookpaper_ = 0;
30   header_ = SCM_EOL;
31   assert (!scores_.size ());
32   smobify_self ();
33 }
34
35 Book::~Book ()
36 {
37 }
38
39 IMPLEMENT_SMOBS (Book);
40 IMPLEMENT_DEFAULT_EQUAL_P (Book);
41
42 SCM
43 Book::mark_smob (SCM s)
44 {
45   Book *book = (Book*) SCM_CELL_WORD_1 (s);
46   int score_count = book->scores_.size ();
47   for (int i = 0; i < score_count; i++)
48     scm_gc_mark (book->scores_[i]->self_scm ());
49
50   if (book->bookpaper_)
51     scm_gc_mark (book->bookpaper_->self_scm ());
52   return book->header_;
53 }
54
55 int
56 Book::print_smob (SCM, SCM p, scm_print_state*)
57 {
58   scm_puts ("#<Book>", p);
59   return 1;
60 }
61
62 /* This function does not dump the output; outname is required eg. for
63    dumping header fields.  */
64 Paper_book *
65 Book::process (String outname, Output_def *default_def)
66 {
67   bool error = false;
68   for (int i = 0; i < scores_.size(); i++)
69     error = error || scores_[i]->error_found_;
70
71   if (error)
72     return 0;
73     
74   Paper_book *paper_book = new Paper_book ();
75   Real scale = scm_to_double (bookpaper_->c_variable ("outputscale"));
76   
77   Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale);
78
79   paper_book->bookpaper_ = scaled_bookdef;
80   scm_gc_unprotect_object (scaled_bookdef->self_scm());
81   
82   paper_book->header_ = header_;
83   
84   int score_count = scores_.size ();
85   for (int i = 0; i < score_count; i++)
86     {
87       SCM systems = scores_[i]->book_rendering (outname,
88                                                 paper_book->bookpaper_,
89                                                 default_def);
90       
91       /* If the score is empty, generate no output.  Should we
92          do titling?  */
93       if (SCM_NFALSEP(scm_vector_p (systems)))
94         {
95           Score_systems sc;
96           sc.systems_ = systems;
97           sc.header_ = scores_[i]->header_;
98           paper_book->score_systems_.push (sc);
99         }
100     }
101
102   return paper_book;
103 }
104
105 LY_DEFINE(ly_make_book, "ly:make-book",
106           2, 0, 1, (SCM bookpaper, SCM header, SCM scores),
107           "Make a \\book of @var{bookpaper} and @var{header} (which may be #f as well)  "
108           "containing @code{\\scores}.")
109 {
110   Output_def * odef = unsmob_output_def (bookpaper);
111   SCM_ASSERT_TYPE (odef, bookpaper,
112                    SCM_ARG1, __FUNCTION__, "Output_def");
113
114   Book *book = new Book;
115   book->bookpaper_ = odef;
116
117   if (ly_c_module_p (header))
118     book->header_ = header;
119   
120   for (SCM s = scores; scm_is_pair (s); s = ly_cdr (s))
121     {
122       Score *score = unsmob_score (ly_car (s));
123       if (score)
124         book->scores_.push (score);
125     }
126   
127   SCM x = book->self_scm ();
128   scm_gc_unprotect_object (x);
129   return x;
130 }
131