Merge remote branch 'origin' into release/unstable
[lilypond/patrick.git] / lily / paper-score.cc
blob9b5e8aa7dfb26c936c88ae212938829414bc134c
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1996--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "paper-score.hh"
22 #include "all-font-metrics.hh"
23 #include "book.hh"
24 #include "international.hh"
25 #include "main.hh"
26 #include "misc.hh"
27 #include "output-def.hh"
28 #include "paper-book.hh"
29 #include "paper-column.hh"
30 #include "scm-hash.hh"
31 #include "score.hh"
32 #include "stencil.hh"
33 #include "system.hh"
34 #include "warn.hh"
35 #include "constrained-breaking.hh"
37 Paper_score::Paper_score (Output_def *layout)
39 layout_ = layout;
40 system_ = 0;
41 systems_ = SCM_EOL;
42 paper_systems_ = SCM_BOOL_F;
45 Paper_score::Paper_score (Paper_score const &s)
46 : Music_output (s)
48 assert (false);
51 void
52 Paper_score::derived_mark () const
54 if (layout_)
55 scm_gc_mark (layout_->self_scm ());
56 scm_gc_mark (systems_);
57 scm_gc_mark (paper_systems_);
60 void
61 Paper_score::typeset_system (System *system)
63 if (!system_)
64 system_ = system;
66 systems_ = scm_cons (system->self_scm (), systems_);
67 system->pscore_ = this;
68 system->layout_ = layout_;
69 system->unprotect ();
72 void
73 Paper_score::find_break_indices () const
75 cols_ = root_system ()->used_columns ();
76 break_indices_.clear ();
77 break_ranks_.clear ();
79 for (vsize i = 0; i < cols_.size (); i++)
81 Item *it = dynamic_cast<Item*> (cols_[i]);
82 if (Paper_column::is_breakable (cols_[i])
83 && (i == 0 || it->find_prebroken_piece (LEFT))
84 && (i == cols_.size () - 1 || it->find_prebroken_piece (RIGHT)))
86 break_indices_.push_back (i);
87 break_ranks_.push_back (it->get_column ()->get_rank ());
92 vector<vsize>
93 Paper_score::get_break_indices () const
95 if (break_indices_.empty ())
96 find_break_indices ();
97 return break_indices_;
100 vector<Grob*>
101 Paper_score::get_columns () const
103 if (cols_.empty ())
104 find_break_indices ();
105 return cols_;
108 vector<vsize>
109 Paper_score::get_break_ranks () const
111 if (break_ranks_.empty ())
112 find_break_indices ();
113 return break_ranks_;
116 vector<Column_x_positions>
117 Paper_score::calc_breaking ()
119 Constrained_breaking algorithm (this);
120 vector<Column_x_positions> sol;
122 message (_ ("Calculating line breaks...") + " ");
124 int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
125 if (system_count)
126 return algorithm.solve (0, VPOS, system_count);
128 return algorithm.best_solution (0, VPOS);
131 void
132 Paper_score::process ()
134 if (be_verbose_global)
135 message (_f ("Element count %d (spanners %d) ",
136 system_->element_count (),
137 system_->spanner_count ()));
139 message (_ ("Preprocessing graphical objects..."));
141 system_->pre_processing ();
144 System *
145 Paper_score::root_system () const
147 return system_;
150 Output_def *
151 Paper_score::layout () const
153 return layout_;
157 Paper_score::get_paper_systems ()
159 if (paper_systems_ == SCM_BOOL_F)
161 vector<Column_x_positions> breaking = calc_breaking ();
162 system_->break_into_pieces (breaking);
163 message (_ ("Drawing systems...") + " ");
164 system_->do_break_substitution_and_fixup_refpoints ();
165 paper_systems_ = system_->get_paper_systems ();
167 return paper_systems_;
171 Paper_score *
172 unsmob_paper_score (SCM x)
174 return dynamic_cast<Paper_score*> (unsmob_music_output (x));