]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
* lily/book.cc:
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "book.hh"
10
11 #include <cstdio>
12
13 #include "lilypond-key.hh"
14 #include "global-context.hh"
15 #include "main.hh"
16 #include "music-iterator.hh"
17 #include "music-output.hh"
18 #include "music.hh"
19 #include "output-def.hh"
20 #include "paper-book.hh"
21 #include "score.hh"
22 #include "stencil.hh"
23 #include "text-item.hh"
24 #include "warn.hh"
25
26 #include "ly-smobs.icc"
27
28 Book::Book ()
29   : Input ()
30 {
31   paper_ = 0;
32   header_ = SCM_EOL;
33   scores_ = SCM_EOL;
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
49 #if 0
50   if (book->key_)
51     scm_gc_mark (book->key_->self_scm());
52 #endif
53
54   if (book->paper_)
55     scm_gc_mark (book->paper_->self_scm ());
56   scm_gc_mark (book->scores_);
57
58   return book->header_;
59 }
60
61 int
62 Book::print_smob (SCM, SCM p, scm_print_state*)
63 {
64   scm_puts ("#<Book>", p);
65   return 1;
66 }
67
68 void
69 Book::add_score (SCM s)
70 {
71   scores_ = scm_cons (s, scores_);
72 }
73
74 /* This function does not dump the output; outname is required eg. for
75    dumping header fields.  */
76 Paper_book *
77 Book::process (String outname, Output_def *default_def)
78 {
79   for (SCM s = scores_; s != SCM_EOL; s = scm_cdr (s))
80     if (Score *score = unsmob_score (scm_car (s)))
81       if (score->error_found_)
82         return 0;
83
84   Paper_book *paper_book = new Paper_book ();
85   Real scale = scm_to_double (paper_->c_variable ("outputscale"));
86   Output_def * scaled_bookdef = scale_output_def (paper_, scale);
87
88   Object_key * key = new Lilypond_general_key (0, user_key_, 0);
89   SCM  scm_key = key->self_scm();
90   scm_gc_unprotect_object (scm_key);
91   
92   paper_book->paper_ = scaled_bookdef;
93   scm_gc_unprotect_object (scaled_bookdef->self_scm());
94   
95   paper_book->header_ = header_;
96
97   /* Render in order of parsing.  */
98   for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
99     {
100       if (Score *score = unsmob_score (scm_car (s)))
101         {
102           SCM systems = score
103             ->book_rendering (outname, paper_book->paper_, default_def, key);
104       
105           /* If the score is empty, generate no output.  Should we do
106              titling? */
107           if (scm_is_vector (systems))
108             {
109               if (ly_c_module_p (header_))
110                 paper_book->add_score (header_);
111               paper_book->add_score (systems);
112             }
113         }
114       else if (Text_interface::markup_p (scm_car (s)))
115         paper_book->add_score (scm_car (s));
116       else
117         assert (0);
118     }
119
120   scm_remember_upto_here_1 (scm_key);
121   return paper_book;
122 }