2 p-score.cc -- implement Paper_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "paper-def.hh"
14 #include "line-of-score.hh"
19 #include "word-wrap.hh"
20 #include "gourlay-breaking.hh"
21 #include "paper-stream.hh"
22 #include "paper-outputter.hh"
23 #include "file-results.hh"
26 Paper_score::Paper_score ()
28 protected_scms_
= scm_protect_object (gh_cons (SCM_BOOL_T
, SCM_EOL
));
31 Line_of_score
* line_p
= new Line_of_score
;
32 typeset_unbroken_spanner (line_p
);
37 Paper_score::Paper_score (Paper_score
const &s
)
43 Paper_score::~Paper_score ()
45 for (int i
=span_p_arr_
.size (); --i
>=0 ; )
46 delete span_p_arr_
[i
];
47 for (int i
=elem_p_arr_
.size (); --i
>=0 ; )
48 delete elem_p_arr_
[i
];
50 scm_unprotect_object (protected_scms_
);
54 Paper_score::typeset_element (Score_element
* elem_p
)
56 elem_p_arr_
.push (elem_p
);
57 elem_p
->pscore_l_
= this;
59 // take over protection.
60 SCM_CDR(protected_scms_
) = gh_cons (elem_p
->element_property_alist_
,
61 SCM_CDR (protected_scms_
));
62 scm_unprotect_object (elem_p
->element_property_alist_
);
64 SCM p
= elem_p
->remove_elt_property (break_helper_only_scm_sym
);
66 break_helpers_arr_
.push (elem_p
);
71 Paper_score::typeset_unbroken_spanner (Spanner
*span_p
)
73 span_p_arr_
.push (span_p
);
74 span_p
->pscore_l_
=this;
76 SCM p
= span_p
->remove_elt_property (break_helper_only_scm_sym
);
78 break_helpers_arr_
.push (span_p
);
82 Paper_score::add_column (Paper_column
*p
)
84 p
->set_rank (col_l_arr_
.size ());
92 Paper_score::print () const
97 DOUT
<< "Paper_score { ";
98 DOUT
<< "\n elements: ";
99 for (int i
=0; i
< span_p_arr_
.size (); i
++)
100 span_p_arr_
[i
]->print ();
101 for (int i
=0; i
< elem_p_arr_
.size (); i
++)
102 elem_p_arr_
[i
]->print();
109 Paper_score::find_col_idx (Paper_column
const *c
) const
111 Paper_column
const *what
= c
;
113 return col_l_arr_
.find_i ((Paper_column
*)what
);
116 Array
<Column_x_positions
>
117 Paper_score::calc_breaking ()
119 Break_algorithm
*algorithm_p
=0;
120 Array
<Column_x_positions
> sol
;
121 bool try_wrap
= !paper_l_
->get_var ("castingalgorithm");
125 algorithm_p
= new Gourlay_breaking
;
126 algorithm_p
->set_pscore (this);
127 sol
= algorithm_p
->solve ();
131 warning (_ ("Can't solve this casting problem exactly; revert to Word_wrap"));
137 algorithm_p
= new Word_wrap
;
138 algorithm_p
->set_pscore (this);
139 sol
= algorithm_p
->solve ();
148 Paper_score::process ()
150 Dictionary
<int> type_stats
;
151 type_stats
["Item"] =0;
152 type_stats
["Spanner"] =0;
153 type_stats
["Total"]=0;
156 *mlog
<< _ ("Preprocessing elements...") << " " << flush
;
157 line_l_
->breakable_col_processing ();
158 line_l_
->pre_processing ();
160 *mlog
<< '\n' << _ ("Calculating column positions...") << " " << flush
;
161 line_l_
->space_processing ();
163 Array
<Column_x_positions
> breaking
= calc_breaking ();
166 Paper_stream
* paper_stream_p
= paper_l_
->paper_stream_p ();
167 outputter_l_
= paper_l_
->paper_outputter_p (paper_stream_p
, header_l_
, origin_str_
);
169 Link_array
<Line_of_score
> lines
;
170 for (int i
=0; i
< breaking
.size (); i
++)
172 Line_of_score
*line_l
= line_l_
->set_breaking (breaking
, i
);
174 if (line_l
!= line_l_
)
175 typeset_element (line_l
);
178 if (experimental_features_global_b
)
179 *mlog
<< elem_p_arr_
.size () + span_p_arr_
.size () << _ (" elements. ");
182 *mlog
<< _ ("Line ... ");
183 line_l_
->break_processing ();
184 for (int i
=0; i
< lines
.size (); i
++)
186 *mlog
<< '[' << flush
;
188 Line_of_score
*line_l
= lines
[i
];
190 line_l
->post_processing ();
192 line_l
->output_all (i
+ 1 == lines
.size());
193 if (experimental_features_global_b
)
194 *mlog
<< '(' << elem_p_arr_
.size () + span_p_arr_
.size () << ')';
196 *mlog
<< ']' << flush
;
201 delete paper_stream_p
;
208 if (experimental_features_global_b
)
210 for (Dictionary_iter
<int> i(type_stats
); i
.ok(); i
++)
212 *mlog
<< i
.key () << ": " << i
.val () << " objects\n";
215 *mlog
<< '\n' << flush
;
220 Paper_score::broken_col_range (Item
const*l
, Item
const*r
) const
222 Link_array
<Item
> ret
;
228 ? find_col_idx (dynamic_cast<Paper_column
*> ((Item
*)l
))+1
232 ? find_col_idx (dynamic_cast<Paper_column
*>((Item
*)r
))
233 : col_l_arr_
.size ();
237 Paper_column
*c
= col_l_arr_
[start
];
238 if (c
->breakable_b () && !c
->line_l_
)