]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
* Documentation/topdocs/NEWS.tely (Top): Mention markup text feature.
[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 "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           sc.texts_ = scores_[i]->texts_;
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
121   
122
123 void
124 Book::add_score (Score *s)
125 {
126   scores_.push (s);
127   scm_gc_unprotect_object (s->self_scm ());
128 }