]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-score.cc
Run `make grand-replace'.
[lilypond.git] / lily / paper-score.cc
1 /*
2   paper-score.cc -- implement Paper_score
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "paper-score.hh"
10
11 #include "all-font-metrics.hh"
12 #include "book.hh"
13 #include "international.hh"
14 #include "main.hh"
15 #include "misc.hh"
16 #include "output-def.hh"
17 #include "paper-book.hh"
18 #include "paper-column.hh"
19 #include "scm-hash.hh"
20 #include "score.hh"
21 #include "stencil.hh"
22 #include "system.hh"
23 #include "warn.hh"
24 #include "constrained-breaking.hh"
25
26 Paper_score::Paper_score (Output_def *layout)
27 {
28   layout_ = layout;
29   system_ = 0;
30   systems_ = SCM_EOL;
31   paper_systems_ = SCM_BOOL_F;
32 }
33
34 Paper_score::Paper_score (Paper_score const &s)
35   : Music_output (s)
36 {
37   assert (false);
38 }
39
40 void
41 Paper_score::derived_mark () const
42 {
43   if (layout_)
44     scm_gc_mark (layout_->self_scm ());
45   scm_gc_mark (systems_);
46   scm_gc_mark (paper_systems_);
47 }
48
49 void
50 Paper_score::typeset_system (System *system)
51 {
52   if (!system_)
53     system_ = system;
54
55   systems_ = scm_cons (system->self_scm (), systems_);
56   system->pscore_ = this;
57   system->layout_ = layout_;
58   system->unprotect ();
59 }
60
61
62 vector<vsize>
63 Paper_score::find_break_indices () const
64 {
65   vector<Grob*> all = root_system ()->used_columns ();
66   vector<vsize> retval;
67
68   for (vsize i = 0; i < all.size (); i++)
69     {
70       Item *it = dynamic_cast<Item*> (all[i]);
71       if (Paper_column::is_breakable (all[i])
72           && (i == 0 || it->find_prebroken_piece (LEFT))
73           && (i == all.size () - 1 || it->find_prebroken_piece (RIGHT)))
74         retval.push_back (i);
75     }
76
77   cols_ = all;
78   break_indices_ = retval;
79
80   return retval;
81 }
82
83 vector<vsize>
84 Paper_score::get_break_indices () const
85 {
86   if (break_indices_.empty ())
87     find_break_indices ();
88   return break_indices_;
89 }
90
91 vector<Grob*>
92 Paper_score::get_columns () const
93 {
94   if (cols_.empty ())
95     find_break_indices ();
96   return cols_;
97 }
98
99 vector<Column_x_positions>
100 Paper_score::calc_breaking ()
101 {
102   Constrained_breaking algorithm (this);
103   vector<Column_x_positions> sol;
104
105   message (_ ("Calculating line breaks...") + " ");
106
107   int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
108   if (system_count)
109     return algorithm.solve (0, VPOS, system_count);
110
111   return algorithm.best_solution (0, VPOS);
112 }
113
114 void
115 Paper_score::process ()
116 {
117   if (be_verbose_global)
118     message (_f ("Element count %d (spanners %d) ",
119                  system_->element_count (),
120                  system_->spanner_count ()));
121
122   message (_ ("Preprocessing graphical objects..."));
123
124   system_->pre_processing ();
125 }
126
127 System *
128 Paper_score::root_system () const
129 {
130   return system_;
131 }
132
133 Output_def *
134 Paper_score::layout () const
135 {
136   return layout_;
137 }
138
139 SCM
140 Paper_score::get_paper_systems ()
141 {
142   if (paper_systems_ == SCM_BOOL_F)
143     {
144       vector<Column_x_positions> breaking = calc_breaking ();
145       system_->break_into_pieces (breaking);
146       message (_ ("Drawing systems...") + " ");
147       system_->do_break_substitution_and_fixup_refpoints ();
148       paper_systems_ = system_->get_paper_systems ();
149     }
150   return paper_systems_;
151 }
152
153
154 Paper_score *
155 unsmob_paper_score (SCM x)
156 {
157   return dynamic_cast<Paper_score*> (unsmob_music_output (x));
158 }