Fix arpeggio overshoot for some chords which reach centre line.
[lilypond.git] / lily / book.cc
blob335507601d37fc46d3e1fa381e904b4b27421f82
1 /*
2 book.cc -- implement Book
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "book.hh"
11 #include <cstdio>
12 using namespace std;
14 #include "main.hh"
15 #include "music.hh"
16 #include "output-def.hh"
17 #include "paper-book.hh"
18 #include "score.hh"
19 #include "text-interface.hh"
20 #include "warn.hh"
21 #include "performance.hh"
22 #include "paper-score.hh"
23 #include "page-marker.hh"
25 #include "ly-smobs.icc"
27 Book::Book ()
29 paper_ = 0;
30 header_ = SCM_EOL;
31 scores_ = SCM_EOL;
32 input_location_ = SCM_EOL;
33 smobify_self ();
35 input_location_ = make_input (Input ());
38 Book::Book (Book const &s)
40 paper_ = 0;
41 header_ = SCM_EOL;
42 scores_ = SCM_EOL;
43 input_location_ = SCM_EOL;
44 smobify_self ();
46 if (s.paper_)
48 paper_ = s.paper_->clone ();
49 paper_->unprotect ();
52 input_location_ = make_input (*s.origin ());
54 header_ = ly_make_anonymous_module (false);
55 if (ly_is_module (s.header_))
56 ly_module_copy (header_, s.header_);
58 SCM *t = &scores_;
59 for (SCM p = s.scores_; scm_is_pair (p); p = scm_cdr (p))
61 Score *newscore = unsmob_score (scm_car (p))->clone ();
63 *t = scm_cons (newscore->self_scm (), SCM_EOL);
64 t = SCM_CDRLOC (*t);
65 newscore->unprotect ();
69 Input *
70 Book::origin () const
72 return unsmob_input (input_location_);
75 Book::~Book ()
79 IMPLEMENT_SMOBS (Book);
80 IMPLEMENT_DEFAULT_EQUAL_P (Book);
82 SCM
83 Book::mark_smob (SCM s)
85 Book *book = (Book *) SCM_CELL_WORD_1 (s);
87 if (book->paper_)
88 scm_gc_mark (book->paper_->self_scm ());
89 scm_gc_mark (book->scores_);
90 scm_gc_mark (book->input_location_);
92 return book->header_;
95 int
96 Book::print_smob (SCM, SCM p, scm_print_state*)
98 scm_puts ("#<Book>", p);
99 return 1;
102 void
103 Book::add_score (SCM s)
105 scores_ = scm_cons (s, scores_);
109 /* Concatenate all score outputs into a Paper_book
111 Paper_book *
112 Book::process (Output_def *default_paper,
113 Output_def *default_layout)
115 for (SCM s = scores_; scm_is_pair (s); s = scm_cdr (s))
116 if (Score *score = unsmob_score (scm_car (s)))
117 if (score->error_found_)
118 return 0;
120 Output_def *paper = paper_ ? paper_ : default_paper;
121 if (!paper)
122 return 0;
124 Paper_book *paper_book = new Paper_book ();
125 Real scale = scm_to_double (paper->c_variable ("output-scale"));
126 Output_def *scaled_bookdef = scale_output_def (paper, scale);
128 paper_book->paper_ = scaled_bookdef;
129 scaled_bookdef->unprotect ();
131 paper_book->header_ = header_;
133 /* Render in order of parsing. */
134 for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s))
136 if (Score *score = unsmob_score (scm_car (s)))
138 SCM outputs = score
139 ->book_rendering (paper_book->paper_, default_layout);
141 while (scm_is_pair (outputs))
143 Music_output *output = unsmob_music_output (scm_car (outputs));
145 if (Performance *perf = dynamic_cast<Performance *> (output))
146 paper_book->add_performance (perf->self_scm ());
147 else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output))
149 if (ly_is_module (score->get_header ()))
150 paper_book->add_score (score->get_header ());
151 paper_book->add_score (pscore->self_scm ());
154 outputs = scm_cdr (outputs);
157 else if (Text_interface::is_markup_list (scm_car (s))
158 || unsmob_page_marker (scm_car (s)))
159 paper_book->add_score (scm_car (s));
160 else
161 assert (0);
164 return paper_book;