]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
* lily/include/object-key-undumper.hh (Module): new file.
[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 "lilypond-key.hh"
12 #include "book.hh"
13 #include "global-context.hh"
14 #include "ly-module.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 "warn.hh"
24
25 #include "ly-smobs.icc"
26
27 Book::Book ()
28   : Input ()
29 {
30   paper_ = 0;
31   header_ = SCM_EOL;
32   assert (!scores_.size ());
33   smobify_self ();
34 }
35
36 Book::~Book ()
37 {
38 }
39
40 IMPLEMENT_SMOBS (Book);
41 IMPLEMENT_DEFAULT_EQUAL_P (Book);
42
43 SCM
44 Book::mark_smob (SCM s)
45 {
46   Book *book = (Book*) SCM_CELL_WORD_1 (s);
47   int score_count = book->scores_.size ();
48   for (int i = 0; i < score_count; i++)
49     scm_gc_mark (book->scores_[i]->self_scm ());
50
51 #if 0
52   if (book->key_)
53     scm_gc_mark (book->key_->self_scm());
54 #endif
55   if (book->paper_)
56     scm_gc_mark (book->paper_->self_scm ());
57   return book->header_;
58 }
59
60 int
61 Book::print_smob (SCM, SCM p, scm_print_state*)
62 {
63   scm_puts ("#<Book>", p);
64   return 1;
65 }
66
67 /* This function does not dump the output; outname is required eg. for
68    dumping header fields.  */
69 Paper_book *
70 Book::process (String outname, Output_def *default_def)
71 {
72   bool error = false;
73   for (int i = 0; i < scores_.size(); i++)
74     error = error || scores_[i]->error_found_;
75
76   if (error)
77     return 0;
78
79   Paper_book *paper_book = new Paper_book ();
80   Real scale = scm_to_double (paper_->c_variable ("outputscale"));
81   Output_def * scaled_bookdef = scale_output_def (paper_, scale);
82
83
84   Object_key * key = new Lilypond_general_key (0, user_key_, 0);
85   SCM  scm_key = key->self_scm();
86   scm_gc_unprotect_object (scm_key);
87   
88   paper_book->paper_ = scaled_bookdef;
89   scm_gc_unprotect_object (scaled_bookdef->self_scm());
90   
91   paper_book->header_ = header_;
92   int score_count = scores_.size ();
93   for (int i = 0; i < score_count; i++)
94     {
95       SCM systems = scores_[i]->book_rendering (outname,
96                                                 paper_book->paper_,
97                                                 default_def,
98                                                 key
99                                                 );
100       
101       /*
102         If the score is empty, generate no output.  Should we
103         do titling?
104       */
105       if (SCM_NFALSEP(scm_vector_p (systems)))
106         {
107           Score_systems sc;
108           sc.systems_ = systems;
109           sc.header_ = scores_[i]->header_;
110           paper_book->score_systems_.push (sc);
111         }
112     }
113
114
115   scm_remember_upto_here_1 (scm_key);
116   return paper_book;
117 }
118
119 LY_DEFINE(ly_make_book, "ly:make-book",
120           2, 0, 1, (SCM paper, SCM header, SCM scores),
121           "Make a \\book of @var{paper} and @var{header} (which may be #f as well)  "
122           "containing @code{\\scores}.")
123 {
124   Output_def * odef = unsmob_output_def (paper);
125   SCM_ASSERT_TYPE (odef, paper,
126                    SCM_ARG1, __FUNCTION__, "Output_def");
127
128   Book *book = new Book;
129   book->paper_ = odef;
130
131   if (ly_c_module_p (header))
132     book->header_ = header;
133   
134   for (SCM s = scores; scm_is_pair (s); s = scm_cdr (s))
135     {
136       Score *score = unsmob_score (scm_car (s));
137       if (score)
138         book->scores_.push (score);
139     }
140   
141   SCM x = book->self_scm ();
142   scm_gc_unprotect_object (x);
143   return x;
144 }
145   
146
147 void
148 Book::add_score (Score *s)
149 {
150   scores_.push (s);
151   scm_gc_unprotect_object (s->self_scm ());
152 }