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"
25 fixup_refpoints (SCM s)
27 for (; gh_pair_p (s); s = gh_cdr (s))
29 Score_element::fixup_refpoint (gh_car (s));
34 Line_of_score::Line_of_score(SCM s)
38 set_elt_property ("columns", SCM_EOL);
39 set_elt_property ("all-elements", SCM_EOL);
41 Axis_group_interface::set_interface (this);
42 Axis_group_interface::set_axes (this, Y_AXIS,X_AXIS);
46 Line_of_score::element_count () const
48 return scm_ilength ( get_elt_property ("all-elements"));
52 Line_of_score::typeset_element (Score_element * elem_p)
54 elem_p->pscore_l_ = pscore_l_;
55 Pointer_group_interface (this, "all-elements").add_element (elem_p);
56 scm_unprotect_object (elem_p->self_scm_);
60 Line_of_score::output_lines ()
62 for (SCM s = get_elt_property ("all-elements");
63 gh_pair_p (s); s = gh_cdr (s))
65 unsmob_element (gh_car (s))->do_break_processing ();
68 fixups must be done in broken line_of_scores, because new elements
69 are put over there. */
71 for (int i=0; i < broken_into_l_arr_.size (); i++)
73 Score_element *se = broken_into_l_arr_[i];
74 SCM all = se->get_elt_property ("all-elements");
75 for (SCM s = all; gh_pair_p (s); s = gh_cdr (s))
77 fixup_refpoint (gh_car (s));
79 count += scm_ilength (all);
84 needed for doing items.
86 fixup_refpoints (get_elt_property ("all-elements"));
89 for (SCM s = get_elt_property ("all-elements");
90 gh_pair_p (s); s = gh_cdr (s))
92 unsmob_element (gh_car (s))->handle_broken_dependencies ();
94 handle_broken_dependencies ();
97 progress_indication ( _f("Element count %d.", count + element_count()));
100 for (int i=0; i < broken_into_l_arr_.size (); i++)
102 Line_of_score *line_l = dynamic_cast<Line_of_score*> (broken_into_l_arr_[i]);
104 if (verbose_global_b)
105 progress_indication ("[");
106 line_l->post_processing ();
108 if (verbose_global_b)
110 progress_indication (to_str (i));
111 progress_indication ("]");
114 if (i < broken_into_l_arr_.size () - 1)
116 SCM lastcol = gh_car (line_l->get_elt_property ("columns"));
117 Score_element* e = unsmob_element (lastcol);
118 SCM inter = e->get_elt_property ("between-system-string");
119 if (gh_string_p (inter))
121 pscore_l_->outputter_l_->output_string (inter);
129 Line_of_score::break_into_pieces (Array<Column_x_positions> const &breaking)
131 for (int i=0; i < breaking.size (); i++)
133 Line_of_score *line_l = dynamic_cast <Line_of_score*> (clone());
135 // line_l->set_immutable_elt_property ("rank", gh_int2scm( i));
136 Link_array<Score_element> c (breaking[i].cols_);
137 pscore_l_->typeset_line (line_l);
139 line_l->set_bound(LEFT,c[0]);
140 line_l->set_bound(RIGHT,c.top ());
141 for (int j=0; j < c.size(); j++)
143 c[j]->translate_axis (breaking[i].config_[j],X_AXIS);
144 dynamic_cast<Paper_column*> (c[j])->line_l_ = line_l;
147 broken_into_l_arr_.push (line_l);
153 Line_of_score::output_molecule (SCM expr, Offset o)
155 SCM offset_sym = ly_symbol2scm ("translate-molecule");
156 SCM combine_sym = ly_symbol2scm ("combine-molecule");
159 if (!gh_pair_p (expr))
162 SCM head =gh_car (expr);
163 if (head == offset_sym)
165 o += ly_scm2offset (gh_cadr (expr));
166 expr = gh_caddr (expr);
169 else if (head == combine_sym)
171 output_molecule (gh_cadr (expr), o);
172 expr = gh_caddr (expr);
173 goto enter; // tail recursion
177 pscore_l_->outputter_l_->
178 output_scheme (gh_list (ly_symbol2scm ("placebox"),
179 gh_double2scm (o[X_AXIS]),
180 gh_double2scm (o[Y_AXIS]),
187 Line_of_score::output_scheme (SCM s)
189 pscore_l_->outputter_l_->output_scheme (s);
193 Line_of_score::add_column (Paper_column*p)
195 Score_element *me = this;
196 SCM cs = me->get_elt_property ("columns");
197 Score_element * prev = gh_pair_p (cs) ? unsmob_element (gh_car (cs)) : 0;
199 p->rank_i_ = prev ? Paper_column::rank_i (prev) + 1 : 0;
203 me->set_elt_property ("columns", gh_cons (p->self_scm_, cs));
205 Axis_group_interface::add_element (me, p);
211 TODO: use scm_map iso. for loops.
214 Line_of_score::pre_processing ()
216 for (SCM s = get_elt_property ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
217 unsmob_element (gh_car (s))->discretionary_processing ();
220 progress_indication ( _f("Element count %d ", element_count ()));
223 for (SCM s = get_elt_property ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
224 unsmob_element (gh_car (s))->handle_prebroken_dependencies ();
226 fixup_refpoints (get_elt_property ("all-elements"));
228 for (SCM s = get_elt_property ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
230 Score_element* sc = unsmob_element (gh_car (s));
231 sc->calculate_dependencies (PRECALCED, PRECALCING, ly_symbol2scm ("before-line-breaking-callback"));
234 progress_indication ("\n" + _ ("Calculating column positions...") + " " );
235 for (SCM s = get_elt_property ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
237 Score_element * e = unsmob_element (gh_car (s));
238 SCM proc = e->get_elt_property ("spacing-procedure");
239 if (gh_procedure_p (proc))
240 gh_call1 (proc, e->self_scm_);
245 Line_of_score::post_processing ()
247 for (SCM s = get_elt_property ("all-elements");
248 gh_pair_p (s); s = gh_cdr (s))
250 Score_element* sc = unsmob_element (gh_car (s));
251 sc->calculate_dependencies (POSTCALCED, POSTCALCING,
252 ly_symbol2scm ("after-line-breaking-callback"));
255 Interval i(extent(Y_AXIS));
257 programming_error ("Huh? Empty Line_of_score?");
259 translate_axis (- i[MAX], Y_AXIS);
261 Real height = i.length ();
264 programming_error ("Improbable system height");
269 generate all molecules to trigger all font loads.
271 (ugh. This is not very memory efficient.) */
272 for (SCM s = get_elt_property ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
273 unsmob_element (gh_car (s))->get_molecule ();
278 SCM font_names = ly_quote_scm (all_fonts_global_p->font_descriptions ());
279 output_scheme (gh_list (ly_symbol2scm ("define-fonts"),
286 output_scheme (gh_list (ly_symbol2scm ("start-line"),
287 gh_double2scm (height),
290 Real il = paper_l ()->get_var ("interline");
295 for (SCM s = get_elt_property ("all-elements"); gh_pair_p (s); s = gh_cdr (s))
297 Score_element * sc = unsmob_element (gh_car (s));
298 Molecule m = sc->get_molecule ();
300 Offset o (sc->relative_coordinate (this, X_AXIS),
301 sc->relative_coordinate (this, Y_AXIS));
303 SCM e = sc->get_elt_property ("extra-offset");
306 o[X_AXIS] += il * gh_scm2double (gh_car (e));
307 o[Y_AXIS] += il * gh_scm2double (gh_cdr (e));
310 output_molecule (m.get_expr (), o);
312 output_scheme (gh_list (ly_symbol2scm ("stop-line"), SCM_UNDEFINED));
317 Line_of_score::broken_col_range (Item const*l, Item const*r) const
319 Link_array<Item> ret;
323 SCM s = get_elt_property ("columns");
325 while (gh_pair_p (s) && gh_car (s) != r->self_scm_)
331 while (gh_pair_p (s) && gh_car (s) != l->self_scm_)
333 Paper_column*c = dynamic_cast<Paper_column*> ( unsmob_element (gh_car (s)));
334 if (Item::breakable_b (c) && !c->line_l_)
345 Return all columns, but filter out any unused columns , since they might
346 disrupt the spacing problem.
348 Link_array<Score_element>
349 Line_of_score::column_l_arr ()const
351 Link_array<Score_element> acs
352 = Pointer_group_interface__extract_elements (this, (Score_element*) 0, "columns");
354 for (int i= acs.size (); i -- ; )
356 bool brb = Item::breakable_b (acs[i]);
357 bfound = bfound || brb;
360 the last column should be breakable. Weed out any columns that
361 seem empty. We need to retain breakable columns, in case
362 someone forced a breakpoint.
364 if (!bfound || !Paper_column::used_b (acs[i]))