]> git.donarmstrong.com Git - lilypond.git/blob - lily/book.cc
release commit
[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@xs4all.nl>
7 */
8
9 #include "book.hh"
10
11 #include <cstdio>
12 using namespace std;
13
14 #include "lilypond-key.hh"
15 #include "global-context.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 "text-interface.hh"
25 #include "warn.hh"
26
27 #include "performance.hh"
28 #include "paper-score.hh"
29
30 #include "ly-smobs.icc"
31
32 Book::Book ()
33   : Input ()
34 {
35   paper_ = 0;
36   header_ = SCM_EOL;
37   scores_ = SCM_EOL;
38   smobify_self ();
39 }
40
41 Book::~Book ()
42 {
43 }
44
45 IMPLEMENT_SMOBS (Book);
46 IMPLEMENT_DEFAULT_EQUAL_P (Book);
47
48 SCM
49 Book::mark_smob (SCM s)
50 {
51   Book *book = (Book *) SCM_CELL_WORD_1 (s);
52
53 #if 0
54   if (book->key_)
55     scm_gc_mark (book->key_->self_scm ());
56 #endif
57
58   if (book->paper_)
59     scm_gc_mark (book->paper_->self_scm ());
60   scm_gc_mark (book->scores_);
61
62   return book->header_;
63 }
64
65 int
66 Book::print_smob (SCM, SCM p, scm_print_state*)
67 {
68   scm_puts ("#<Book>", p);
69   return 1;
70 }
71
72 void
73 Book::add_score (SCM s)
74 {
75   scores_ = scm_cons (s, scores_);
76 }
77
78 /* Concatenate all score outputs into a Paper_book
79  */
80 Paper_book *
81 Book::process (Output_def *default_paper,
82                Output_def *default_layout)
83 {
84   for (SCM s = scores_; s != SCM_EOL; s = scm_cdr (s))
85     if (Score *score = unsmob_score (scm_car (s)))
86       if (score->error_found_)
87         return 0;
88
89   Output_def *paper = paper_ ? paper_ : default_paper;
90   if (!paper)
91     return 0;
92   
93   Paper_book *paper_book = new Paper_book ();
94   Real scale = scm_to_double (paper->c_variable ("outputscale"));
95   Output_def *scaled_bookdef = scale_output_def (paper, scale);
96
97   Object_key *key = new Lilypond_general_key (0, user_key_, 0);
98   SCM scm_key = key->unprotect ();
99
100   paper_book->paper_ = scaled_bookdef;
101   scaled_bookdef->unprotect ();
102
103   paper_book->header_ = header_;
104
105   /* Render in order of parsing.  */
106   for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
107     {
108       if (Score *score = unsmob_score (scm_car (s)))
109         {
110           SCM outputs = score
111             ->book_rendering (paper_book->paper_, default_layout, key);
112
113           while (scm_is_pair (outputs))
114             {
115               Music_output *output = unsmob_music_output (scm_car (outputs));
116
117               if (Performance *perf = dynamic_cast<Performance *> (output))
118                 paper_book->add_performance (perf->self_scm ());
119               else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
120                 {
121                   SCM systems = pscore->get_paper_systems ();
122                   if (ly_is_module (score->header_))
123                     paper_book->add_score (score->header_);
124                   paper_book->add_score (systems);
125                 }
126
127               outputs = scm_cdr (outputs);
128             }
129         }
130       else if (Text_interface::is_markup (scm_car (s)))
131         paper_book->add_score (scm_car (s));
132       else
133         assert (0);
134     }
135
136   scm_remember_upto_here_1 (scm_key);
137   return paper_book;
138 }