]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-score.cc
* lily/paper-score.cc (find_break_indices): move from Break_algorithm.
[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--2006 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 "gourlay-breaking.hh"
14 #include "international.hh"
15 #include "main.hh"
16 #include "misc.hh"
17 #include "output-def.hh"
18 #include "paper-book.hh"
19 #include "paper-column.hh"
20 #include "scm-hash.hh"
21 #include "score.hh"
22 #include "stencil.hh"
23 #include "system.hh"
24 #include "warn.hh"
25 #include "constrained-breaking.hh"
26
27 Paper_score::Paper_score (Output_def *layout)
28 {
29   layout_ = layout;
30   system_ = 0;
31   systems_ = SCM_EOL;
32   paper_systems_ = SCM_EOL;
33 }
34
35 Paper_score::Paper_score (Paper_score const &s)
36   : Music_output (s)
37 {
38   assert (false);
39 }
40
41 void
42 Paper_score::derived_mark () const
43 {
44   if (layout_)
45     scm_gc_mark (layout_->self_scm ());
46   scm_gc_mark (systems_);
47   scm_gc_mark (paper_systems_);
48 }
49
50 void
51 Paper_score::typeset_system (System *system)
52 {
53   if (!system_)
54     system_ = system;
55
56   systems_ = scm_cons (system->self_scm (), systems_);
57   system->pscore_ = this;
58   system->layout_ = layout_;
59   system->unprotect ();
60 }
61
62
63 vector<int>
64 Paper_score::find_break_indices () const
65 {
66   vector<Grob*> all = root_system ()->columns ();
67   vector<int> retval;
68
69   for (vsize i = 0; i < all.size (); i++)
70     if (Item::is_breakable (all[i]))
71       retval.push_back (i);
72
73   return retval;
74 }
75
76
77 vector<Column_x_positions>
78 Paper_score::calc_breaking ()
79 {
80   Break_algorithm *algorithm = 0;
81   vector<Column_x_positions> sol;
82   
83   int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
84   if (system_count)
85     {
86       Constrained_breaking *b = new Constrained_breaking (/* FIXME */);
87       algorithm = b;
88       b->systems_ = system_count;
89     }
90   else
91     algorithm = new Gourlay_breaking;
92   
93   algorithm->set_pscore (this);
94   sol = algorithm->solve ();
95   delete algorithm;
96
97   return sol;
98 }
99
100 void
101 Paper_score::process ()
102 {
103   if (be_verbose_global)
104     message (_f ("Element count %d (spanners %d) ",
105                  system_->element_count (),
106                  system_->spanner_count ()));
107
108   message (_ ("Preprocessing graphical objects...") + " ");
109
110   /* FIXME: Check out why we need this - removing gives assertion failures
111      down the road.
112
113      doubly, also done in Score_engraver */
114   vector<Grob*> pc (system_->columns ());
115   pc[0]->set_property ("breakable", SCM_BOOL_T);
116   pc.back ()->set_property ("breakable", SCM_BOOL_T);
117
118   system_->pre_processing ();
119
120   vector<Column_x_positions> breaking = calc_breaking ();
121   system_->break_into_pieces (breaking);
122
123   paper_systems_ = system_->get_paper_systems ();
124 }
125
126 System *
127 Paper_score::root_system () const
128 {
129   return system_;
130 }
131
132 Output_def *
133 Paper_score::layout () const
134 {
135   return layout_;
136 }
137
138 SCM
139 Paper_score::get_paper_systems () const
140 {
141   return paper_systems_;
142 }
143