*** empty log message ***
[lilypond.git] / lily / book.cc
blob724ab9cc13ad14ded6c74f5872cc7918df64b5c0
1 /*
2 book.cc -- implement Book
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "book.hh"
11 #include <cstdio>
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-interface.hh"
24 #include "warn.hh"
26 #include "performance.hh"
27 #include "paper-score.hh"
29 #include "ly-smobs.icc"
31 Book::Book ()
32 : Input ()
34 paper_ = 0;
35 header_ = SCM_EOL;
36 scores_ = SCM_EOL;
37 smobify_self ();
40 Book::~Book ()
44 IMPLEMENT_SMOBS (Book);
45 IMPLEMENT_DEFAULT_EQUAL_P (Book);
47 SCM
48 Book::mark_smob (SCM s)
50 Book *book = (Book *) SCM_CELL_WORD_1 (s);
52 #if 0
53 if (book->key_)
54 scm_gc_mark (book->key_->self_scm ());
55 #endif
57 if (book->paper_)
58 scm_gc_mark (book->paper_->self_scm ());
59 scm_gc_mark (book->scores_);
61 return book->header_;
64 int
65 Book::print_smob (SCM, SCM p, scm_print_state*)
67 scm_puts ("#<Book>", p);
68 return 1;
71 void
72 Book::add_score (SCM s)
74 scores_ = scm_cons (s, scores_);
77 /* This function does not dump the output; outname is required eg. for
78 dumping header fields. */
79 Paper_book *
80 Book::process (String outname, Output_def *default_def)
82 for (SCM s = scores_; s != SCM_EOL; s = scm_cdr (s))
83 if (Score *score = unsmob_score (scm_car (s)))
84 if (score->error_found_)
85 return 0;
87 Paper_book *paper_book = new Paper_book ();
88 Real scale = scm_to_double (paper_->c_variable ("outputscale"));
89 Output_def *scaled_bookdef = scale_output_def (paper_, scale);
91 Object_key *key = new Lilypond_general_key (0, user_key_, 0);
92 SCM scm_key = key->self_scm ();
93 scm_gc_unprotect_object (scm_key);
95 paper_book->paper_ = scaled_bookdef;
96 scm_gc_unprotect_object (scaled_bookdef->self_scm ());
98 paper_book->header_ = header_;
100 /* Render in order of parsing. */
101 int midi_count = 0;
102 for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
104 if (Score *score = unsmob_score (scm_car (s)))
106 SCM outputs = score
107 ->book_rendering (paper_book->paper_, default_def, key);
109 while (scm_is_pair (outputs))
111 Music_output *output = unsmob_music_output (scm_car (outputs));
113 if (Performance *perf = dynamic_cast<Performance *> (output))
115 String fn = outname;
116 if (midi_count)
117 fn += "-" + to_string (midi_count);
119 midi_count ++;
120 perf->write_output (fn);
122 else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
124 SCM systems = pscore->get_paper_systems ();
125 if (ly_c_module_p (score->header_))
126 paper_book->add_score (score->header_);
127 paper_book->add_score (systems);
130 outputs = scm_cdr (outputs);
133 else if (Text_interface::markup_p (scm_car (s)))
134 paper_book->add_score (scm_car (s));
135 else
136 assert (0);
139 scm_remember_upto_here_1 (scm_key);
140 return paper_book;