2 scoreline.cc -- implement Line_of_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "axis-group-interface.hh"
11 #include "line-of-score.hh"
13 #include "paper-column.hh"
14 #include "paper-def.hh"
15 #include "paper-outputter.hh"
16 #include "paper-score.hh"
19 #include "dimensions.hh"
20 #include "molecule.hh"
21 #include "all-font-metrics.hh"
23 Line_of_score::Line_of_score()
26 set_elt_pointer ("columns", SCM_EOL);
27 set_elt_pointer ("all-elements", SCM_EOL);
29 Axis_group_interface (this).set_interface ();
30 Axis_group_interface (this).set_axes (Y_AXIS,X_AXIS);
34 Line_of_score::element_count () const
36 return scm_ilength ( get_elt_pointer ("all-elements"));
40 Line_of_score::typeset_element (Score_element * elem_p)
42 elem_p->pscore_l_ = pscore_l_;
43 Pointer_group_interface (this, "all-elements").add_element (elem_p);
44 scm_unprotect_object (elem_p->self_scm_);
48 Line_of_score::output_lines ()
50 for (SCM s = get_elt_pointer ("all-elements");
51 gh_pair_p (s); s = gh_cdr (s))
53 unsmob_element (gh_car (s))->do_break_processing ();
56 fixups must be done in broken line_of_scores, because new elements
57 are put over there. */
59 for (int i=0; i < broken_into_l_arr_.size (); i++)
61 Score_element *se = broken_into_l_arr_[i];
62 SCM all = se->get_elt_pointer ("all-elements");
63 for (SCM s = all; gh_pair_p (s); s = gh_cdr (s))
65 unsmob_element (gh_car (s))->fixup_refpoint ();
67 count += scm_ilength (all);
72 needed for doing items.
74 for (SCM s = get_elt_pointer ("all-elements");
75 gh_pair_p (s); s = gh_cdr (s))
77 unsmob_element (gh_car (s))->fixup_refpoint ();
80 for (SCM s = get_elt_pointer ("all-elements");
81 gh_pair_p (s); s = gh_cdr (s))
83 unsmob_element (gh_car (s))->handle_broken_dependencies ();
85 handle_broken_dependencies ();
88 progress_indication ( _f("Element count %d.", count + element_count()));
91 for (int i=0; i < broken_into_l_arr_.size (); i++)
93 Line_of_score *line_l = dynamic_cast<Line_of_score*> (broken_into_l_arr_[i]);
96 progress_indication ("[");
97 line_l->post_processing ();
101 progress_indication (to_str (i));
102 progress_indication ("]");
109 Line_of_score::break_into_pieces (Array<Column_x_positions> const &breaking)
111 for (int i=0; i < breaking.size (); i++)
113 Line_of_score *line_l = dynamic_cast <Line_of_score*> (clone());
115 Link_array<Paper_column> c (breaking[i].cols_);
116 pscore_l_->typeset_line (line_l);
118 line_l->set_bound(LEFT,c[0]);
119 line_l->set_bound(RIGHT,c.top ());
120 for (int j=0; j < c.size(); j++)
122 c[j]->translate_axis (breaking[i].config_[j],X_AXIS);
123 c[j]->line_l_ = line_l;
126 broken_into_l_arr_.push (line_l);
132 Line_of_score::output_molecule (SCM expr, Offset o)
134 SCM offset_sym = ly_symbol2scm ("translate-molecule");
135 SCM combine_sym = ly_symbol2scm ("combine-molecule");
138 if (!gh_pair_p (expr))
141 SCM head =gh_car (expr);
142 if (head == offset_sym)
144 o += ly_scm2offset (gh_cadr (expr));
145 expr = gh_caddr (expr);
148 else if (head == combine_sym)
150 output_molecule (gh_cadr (expr), o);
151 expr = gh_caddr (expr);
152 goto enter; // tail recursion
156 pscore_l_->outputter_l_->
157 output_scheme (gh_list (ly_symbol2scm ("placebox"),
158 gh_double2scm (o[X_AXIS]),
159 gh_double2scm (o[Y_AXIS]),
166 Line_of_score::output_scheme (SCM s)
168 pscore_l_->outputter_l_->output_scheme (s);
172 Line_of_score::add_column (Paper_column*p)
174 SCM cs = get_elt_pointer ("columns");
175 Score_element * prev = gh_pair_p (cs) ? unsmob_element (gh_car (cs)) : 0;
176 int rank = prev ? dynamic_cast<Paper_column*> (prev)->rank_i () + 1 : 0;
179 set_elt_pointer ("columns", gh_cons (p->self_scm_, cs));
181 Axis_group_interface (this).add_element (p);
187 fixup_refpoints (SCM s)
189 for (; gh_pair_p (s); s = gh_cdr (s))
191 Score_element * se = unsmob_element (gh_car (s));
194 se->fixup_refpoint ();
195 if (!dynamic_cast<Line_of_score*> (se) && !se->parent_l (Y_AXIS))
197 programming_error ("No parent!");
205 Line_of_score::pre_processing ()
207 for (SCM s = get_elt_pointer ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
208 unsmob_element (gh_car (s))->discretionary_processing ();
211 progress_indication ( _f("Element count %d ", element_count ()));
214 for (SCM s = get_elt_pointer ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
215 unsmob_element (gh_car (s))->handle_prebroken_dependencies ();
217 fixup_refpoints (get_elt_pointer ("all-elements"));
219 for (SCM s = get_elt_pointer ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
221 Score_element* sc = unsmob_element (gh_car (s));
222 sc->calculate_dependencies (PRECALCED, PRECALCING, ly_symbol2scm ("before-line-breaking-callback"));
225 progress_indication ("\n" + _ ("Calculating column positions...") + " " );
226 for (SCM s = get_elt_pointer ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
227 unsmob_element (gh_car (s))->do_space_processing ();
231 Line_of_score::post_processing ()
233 for (SCM s = get_elt_pointer ("all-elements");
234 gh_pair_p (s); s = gh_cdr (s))
236 Score_element* sc = unsmob_element (gh_car (s));
237 sc->calculate_dependencies (POSTCALCED, POSTCALCING,
238 ly_symbol2scm ("after-line-breaking-callback"));
241 Interval i(extent(Y_AXIS));
243 programming_error ("Huh? Empty Line_of_score?");
245 translate_axis (- i[MAX], Y_AXIS);
247 Real height = i.length ();
250 programming_error ("Improbable system height");
255 generate all molecules to trigger all font loads.
257 (ugh. This is not very memory efficient.) */
258 for (SCM s = get_elt_pointer ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
259 unsmob_element (gh_car (s))->get_molecule ();
264 SCM font_names = ly_quote_scm (all_fonts_global_p->font_descriptions ());
265 output_scheme (gh_list (ly_symbol2scm ("define-fonts"),
272 output_scheme (gh_list (ly_symbol2scm ("start-line"),
273 gh_double2scm (height),
276 Real il = paper_l ()->get_var ("interline");
281 for (SCM s = get_elt_pointer ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
283 Score_element * sc = unsmob_element (gh_car (s));
284 Molecule m = sc->get_molecule ();
286 Offset o (sc->relative_coordinate (this, X_AXIS),
287 sc->relative_coordinate (this, Y_AXIS));
289 SCM e = sc->get_elt_property ("extra-offset");
292 o[X_AXIS] += il * gh_scm2double (gh_car (e));
293 o[Y_AXIS] += il * gh_scm2double (gh_cdr (e));
296 output_molecule (m.get_expr (), o);
298 output_scheme (gh_list (ly_symbol2scm ("stop-line"), SCM_UNDEFINED));
303 Line_of_score::broken_col_range (Item const*l, Item const*r) const
305 Link_array<Item> ret;
309 SCM s = get_elt_pointer ("columns");
311 while (gh_pair_p (s) && gh_car (s) != r->self_scm_)
317 while (gh_pair_p (s) && gh_car (s) != l->self_scm_)
320 = dynamic_cast<Paper_column*> (unsmob_element (gh_car (s)));
321 if (c->breakable_b () && !c->line_l_)
332 Return all columns, but filter out any unused columns , since they might
333 disrupt the spacing problem.
335 Link_array<Paper_column>
336 Line_of_score::column_l_arr ()const
338 Link_array<Paper_column> acs
339 = Pointer_group_interface__extract_elements (this, (Paper_column*) 0, "columns");
341 for (int i= acs.size (); i -- ; )
343 bool brb = acs[i]->breakable_b();
344 bfound = bfound || brb;
347 the last column should be breakable. Weed out any columns that
348 seem empty. We need to retain breakable columns, in case
349 someone forced a breakpoint.
351 if (!bfound || !acs[i]->used_b ())