]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[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 "book.hh"
10
11 #include <cstdio>
12
13 #include "lilypond-key.hh"
14 #include "global-context.hh"
15 #include "ly-module.hh"
16 #include "main.hh"
17 #include "music-iterator.hh"
18 #include "music-output.hh"
19 #include "music.hh"
20 #include "output-def.hh"
21 #include "paper-book.hh"
22 #include "score.hh"
23 #include "stencil.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   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 0
53   if (book->key_)
54     scm_gc_mark (book->key_->self_scm());
55 #endif
56   if (book->paper_)
57     scm_gc_mark (book->paper_->self_scm ());
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 /* This function does not dump the output; outname is required eg. for
69    dumping header fields.  */
70 Paper_book *
71 Book::process (String outname, Output_def *default_def)
72 {
73   bool error = false;
74   for (int i = 0; i < scores_.size(); i++)
75     error = error || scores_[i]->error_found_;
76
77   if (error)
78     return 0;
79
80   Paper_book *paper_book = new Paper_book ();
81   Real scale = scm_to_double (paper_->c_variable ("outputscale"));
82   Output_def * scaled_bookdef = scale_output_def (paper_, scale);
83
84
85   Object_key * key = new Lilypond_general_key (0, user_key_, 0);
86   SCM  scm_key = key->self_scm();
87   scm_gc_unprotect_object (scm_key);
88   
89   paper_book->paper_ = scaled_bookdef;
90   scm_gc_unprotect_object (scaled_bookdef->self_scm());
91   
92   paper_book->header_ = header_;
93   int score_count = scores_.size ();
94   for (int i = 0; i < score_count; i++)
95     {
96       SCM systems = scores_[i]->book_rendering (outname,
97                                                 paper_book->paper_,
98                                                 default_def,
99                                                 key
100                                                 );
101       
102       /*
103         If the score is empty, generate no output.  Should we
104         do titling?
105       */
106       if (SCM_NFALSEP(scm_vector_p (systems)))
107         {
108           Score_systems sc;
109           sc.systems_ = systems;
110           sc.header_ = scores_[i]->header_;
111           paper_book->score_systems_.push (sc);
112         }
113     }
114
115
116   scm_remember_upto_here_1 (scm_key);
117   return paper_book;
118 }
119
120 LY_DEFINE(ly_make_book, "ly:make-book",
121           2, 0, 1, (SCM paper, SCM header, SCM scores),
122           "Make a \\book of @var{paper} and @var{header} (which may be #f as well)  "
123           "containing @code{\\scores}.")
124 {
125   Output_def * odef = unsmob_output_def (paper);
126   SCM_ASSERT_TYPE (odef, paper,
127                    SCM_ARG1, __FUNCTION__, "Output_def");
128
129   Book *book = new Book;
130   book->paper_ = odef;
131
132   if (ly_c_module_p (header))
133     book->header_ = header;
134   
135   for (SCM s = scores; scm_is_pair (s); s = scm_cdr (s))
136     {
137       Score *score = unsmob_score (scm_car (s));
138       if (score)
139         book->scores_.push (score);
140     }
141   
142   SCM x = book->self_scm ();
143   scm_gc_unprotect_object (x);
144   return x;
145 }
146   
147
148 void
149 Book::add_score (Score *s)
150 {
151   scores_.push (s);
152   scm_gc_unprotect_object (s->self_scm ());
153 }