]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-score.cc
* lily/include/constrained-breaking.hh (class
[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
26 Paper_score::Paper_score (Output_def *layout)
27 {
28   layout_ = layout;
29   system_ = 0;
30   systems_ = SCM_EOL;
31   paper_systems_ = SCM_EOL;
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 vector<Column_x_positions>
62 Paper_score::calc_breaking ()
63 {
64   Break_algorithm *algorithm = 0;
65   vector<Column_x_positions> sol;
66   
67   int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
68   if (system_count)
69     {
70       Constrained_breaking *b = new Constrained_breaking;
71       algorithm = b;
72     }
73   else
74     algorithm = new Gourlay_breaking;
75   
76   algorithm->set_pscore (this);
77   sol = algorithm->solve ();
78   delete algorithm;
79
80   return sol;
81 }
82
83 void
84 Paper_score::process ()
85 {
86   if (be_verbose_global)
87     message (_f ("Element count %d (spanners %d) ",
88                  system_->element_count (),
89                  system_->spanner_count ()));
90
91   message (_ ("Preprocessing graphical objects...") + " ");
92
93   /* FIXME: Check out why we need this - removing gives assertion failures
94      down the road.
95
96      doubly, also done in Score_engraver */
97   vector<Grob*> pc (system_->columns ());
98   pc[0]->set_property ("breakable", SCM_BOOL_T);
99   pc.back ()->set_property ("breakable", SCM_BOOL_T);
100
101   system_->pre_processing ();
102
103   vector<Column_x_positions> breaking = calc_breaking ();
104   system_->break_into_pieces (breaking);
105
106   paper_systems_ = system_->get_paper_systems ();
107 }
108
109 System *
110 Paper_score::root_system () const
111 {
112   return system_;
113 }
114
115 Output_def *
116 Paper_score::layout () const
117 {
118   return layout_;
119 }
120
121 SCM
122 Paper_score::get_paper_systems () const
123 {
124   return paper_systems_;
125 }
126