]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
* lily/book.cc (process): return Paper_book
[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
12 #include "ly-smobs.icc"
13 #include "stencil.hh"
14 #include "book.hh"
15 #include "global-context.hh"
16 #include "ly-module.hh"
17 #include "main.hh"
18 #include "music-iterator.hh"
19 #include "output-def.hh"
20 #include "music-output.hh"
21 #include "music.hh"
22 #include "page.hh"
23 #include "paper-book.hh"
24 #include "output-def.hh"
25 #include "score.hh"
26 #include "warn.hh"
27
28 Book::Book ()
29   : Input ()
30 {
31   bookpaper_ = 0;
32   header_ = SCM_EOL;
33   assert (!scores_.size ());
34   smobify_self ();
35 }
36
37 Book::~Book ()
38 {
39 }
40
41 IMPLEMENT_SMOBS (Book);
42 IMPLEMENT_DEFAULT_EQUAL_P (Book);
43
44 SCM
45 Book::mark_smob (SCM s)
46 {
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 ());
51
52   if (book->bookpaper_)
53     scm_gc_mark (book->bookpaper_->self_scm ());
54   return book->header_;
55 }
56
57 int
58 Book::print_smob (SCM, SCM p, scm_print_state*)
59 {
60   scm_puts ("#<Book>", p);
61   return 1;
62 }
63
64 /*
65   This function does not dump the output; outname is required eg. for
66   dumping header fields.
67  */
68 Paper_book *
69 Book::process (String outname, Output_def *default_def)
70 {
71   Paper_book *paper_book = new Paper_book ();
72         
73   Real scale = ly_scm2double (bookpaper_->c_variable ("outputscale"));
74   
75   Output_def * scaled_bookdef = scale_output_def (bookpaper_, scale);
76
77   paper_book->bookpaper_ = scaled_bookdef;
78   scm_gc_unprotect_object (scaled_bookdef->self_scm());
79   
80   paper_book->header_ = header_;
81   
82   int score_count = scores_.size ();
83   for (int i = 0; i < score_count; i++)
84     {
85       SCM systems = scores_[i]->book_rendering (outname,
86                                                 paper_book->bookpaper_,
87                                                 default_def);
88       if (systems != SCM_UNDEFINED)
89         {
90           Score_lines sc;
91           sc.lines_ = systems;
92           sc.header_ = header_;
93
94           paper_book->score_lines_.push (sc);
95         }
96     }
97
98   return paper_book;
99 }
100
101 /* FIXME: WIP, this is a hack.  Return first page as stencil.  */
102 SCM
103 Book::to_stencil (Output_def *default_def)
104 {
105   Paper_book *paper_book = process ("<markup>", default_def);
106
107   SCM pages = paper_book->pages ();
108   scm_gc_unprotect_object (paper_book->self_scm ());
109
110   if (pages != SCM_EOL)
111     {
112       progress_indication (_f ("paper output to `%s'...", "<markup>"));
113       return (unsmob_page (ly_car (pages)))->to_stencil ().smobbed_copy ();
114     }
115
116   scm_gc_unprotect_object (paper_book->bookpaper_->self_scm ());
117   
118   return SCM_EOL;
119 }