]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-score.cc
* scm/paper-system.scm (paper-system-annotate): also annotate the
[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_BOOL_F;
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<vsize>
64 Paper_score::find_break_indices () const
65 {
66   vector<Grob*> all = root_system ()->columns ();
67   vector<vsize> retval;
68
69   for (vsize i = 0; i < all.size (); i++)
70     {
71       Item *it = dynamic_cast<Item*> (all[i]);
72       if (Paper_column::is_breakable (all[i])
73           && (i == 0 || it->find_prebroken_piece (LEFT))
74           && (i == all.size () - 1 || it->find_prebroken_piece (RIGHT)))
75         retval.push_back (i);
76     }
77
78   cols_ = all;
79   break_indices_ = retval;
80
81   return retval;
82 }
83
84 vector<vsize>
85 Paper_score::get_break_indices () const
86 {
87   if (break_indices_.empty ())
88     find_break_indices ();
89   return break_indices_;
90 }
91
92 vector<Grob*>
93 Paper_score::get_columns () const
94 {
95   if (cols_.empty ())
96     find_break_indices ();
97   return cols_;
98 }
99
100 vector<Column_x_positions>
101 Paper_score::calc_breaking ()
102 {
103   Break_algorithm *algorithm = 0;
104   vector<Column_x_positions> sol;
105
106   message (_ ("Calculating line breaks...") + " ");
107
108   int system_count = robust_scm2int (layout ()->c_variable ("system-count"), 0);
109   if (system_count)
110     {
111       Constrained_breaking *b = new Constrained_breaking;
112       b->resize (system_count);
113       algorithm = b;
114     }
115   else
116     algorithm = new Gourlay_breaking;
117   
118   algorithm->set_pscore (this);
119   sol = algorithm->solve ();
120   delete algorithm;
121
122   return sol;
123 }
124
125 void
126 Paper_score::process ()
127 {
128   if (be_verbose_global)
129     message (_f ("Element count %d (spanners %d) ",
130                  system_->element_count (),
131                  system_->spanner_count ()));
132
133   message (_ ("Preprocessing graphical objects...") + " ");
134
135   /* FIXME: Check out why we need this - removing gives assertion failures
136      down the road.
137
138      doubly, also done in Score_engraver */
139   vector<Grob*> pc (system_->columns ());
140   pc[0]->set_property ("line-break-permission", ly_symbol2scm ("allow"));
141   pc.back ()->set_property ("line-break-permission", ly_symbol2scm ("allow"));
142
143   system_->pre_processing ();
144 }
145
146 System *
147 Paper_score::root_system () const
148 {
149   return system_;
150 }
151
152 Output_def *
153 Paper_score::layout () const
154 {
155   return layout_;
156 }
157
158 SCM
159 Paper_score::get_paper_systems ()
160 {
161   if (paper_systems_ == SCM_BOOL_F)
162     {
163       vector<Column_x_positions> breaking = calc_breaking ();
164       system_->break_into_pieces (breaking);
165       message (_ ("Drawing systems...") + " ");
166       paper_systems_ = system_->get_paper_systems ();
167     }
168   return paper_systems_;
169 }
170