]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
Remove paper var caching.
[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 "ly-smobs.icc"
12
13 #include "book.hh"
14 #include "global-context.hh"
15 #include "ly-module.hh"
16 #include "main.hh"
17 #include "music-iterator.hh"
18 #include "music-output-def.hh"
19 #include "music-output.hh"
20 #include "music.hh"
21 #include "page.hh"
22 #include "paper-book.hh"
23 #include "paper-def.hh"
24 #include "score.hh"
25 #include "warn.hh"
26
27 Book::Book ()
28   : Input ()
29 {
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   return book->header_;
50 }
51
52 int
53 Book::print_smob (SCM, SCM p, scm_print_state*)
54 {
55   scm_puts ("#<Book>", p);
56   return 1;
57 }
58
59 void
60 Book::process (String outname, Music_output_def *default_def, SCM header)
61 {
62   Paper_book *paper_book = new Paper_book ();
63   int score_count = scores_.size ();
64   for (int i = 0; i < score_count; i++)
65     {
66       Paper_def *paper = 0;
67       SCM systems = scores_[i]->book_rendering (outname, default_def, &paper);
68       if (systems != SCM_UNDEFINED)
69         {
70           if (paper)
71             paper_book->papers_.push (paper);
72           paper_book->scores_.push (systems);
73
74           // fixme.
75           //paper_book->global_headers_.push (global_input_file->header_);
76           //paper_book->headers_.push (scores_[i]->header_);
77           paper_book->headers_.push (header);
78         }
79     }
80   paper_book->output (outname);
81   scm_gc_unprotect_object (paper_book->self_scm ());
82 }
83
84 /* FIXME: WIP, this is a hack.  Return first page as stencil.  */
85 SCM
86 Book::to_stencil (Music_output_def *default_def, SCM header)
87 {
88   Paper_book *paper_book = new Paper_book ();
89   int score_count = scores_.size ();
90   for (int i = 0; i < score_count; i++)
91     {
92       Paper_def *paper = 0;
93       SCM systems = scores_[i]->book_rendering ("<markup>", default_def,
94                                                 &paper);
95       if (systems != SCM_UNDEFINED)
96         {
97           if (paper)
98             paper_book->papers_.push (paper);
99           paper_book->scores_.push (systems);
100           paper_book->headers_.push (header);
101         }
102     }
103
104   SCM pages = paper_book->pages ();
105   paper_book = 0;
106   if (pages != SCM_EOL)
107     {
108       progress_indication (_f ("paper output to `%s'...", "<markup>"));
109       return (unsmob_page (ly_car (pages)))->to_stencil ();
110     }
111   return SCM_EOL;
112 }