2 scoreline.cc -- implement Line_of_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "input-smob.hh"
10 #include "axis-group-interface.hh"
12 #include "line-of-score.hh"
14 #include "paper-column.hh"
15 #include "paper-def.hh"
16 #include "paper-outputter.hh"
17 #include "paper-score.hh"
20 #include "dimensions.hh"
21 #include "molecule.hh"
22 #include "all-font-metrics.hh"
26 fixup_refpoints (SCM s)
28 for (; gh_pair_p (s); s = ly_cdr (s))
30 Grob::fixup_refpoint (ly_car (s));
35 Line_of_score::Line_of_score (SCM s)
40 Axis_group_interface::set_interface (this);
41 Axis_group_interface::set_axes (this, Y_AXIS,X_AXIS);
45 Line_of_score::element_count () const
47 return scm_ilength (get_grob_property ("all-elements"));
51 Line_of_score::typeset_grob (Grob * elem_p)
53 elem_p->pscore_l_ = pscore_l_;
54 Pointer_group_interface::add_element (this, ly_symbol2scm ("all-elements"),elem_p);
55 scm_gc_unprotect_object (elem_p->self_scm ());
59 Line_of_score::output_lines ()
61 for (SCM s = get_grob_property ("all-elements");
62 gh_pair_p (s); s = ly_cdr (s))
64 unsmob_grob (ly_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 Grob *se = broken_into_l_arr_[i];
74 SCM all = se->get_grob_property ("all-elements");
75 for (SCM s = all; gh_pair_p (s); s = ly_cdr (s))
77 fixup_refpoint (ly_car (s));
79 count += scm_ilength (all);
83 needed for doing items.
85 fixup_refpoints (get_grob_property ("all-elements"));
88 for (SCM s = get_grob_property ("all-elements");
89 gh_pair_p (s); s = ly_cdr (s))
91 unsmob_grob (ly_car (s))->handle_broken_dependencies ();
93 handle_broken_dependencies ();
96 progress_indication (_f ("Element count %d.", count + element_count ()));
99 for (int i=0; i < broken_into_l_arr_.size (); i++)
101 Line_of_score *line_l = dynamic_cast<Line_of_score*> (broken_into_l_arr_[i]);
103 if (verbose_global_b)
104 progress_indication ("[");
105 line_l->post_processing (i+1 == broken_into_l_arr_.size ());
107 if (verbose_global_b)
109 progress_indication (to_str (i));
110 progress_indication ("]");
113 if (i < broken_into_l_arr_.size () - 1)
115 SCM lastcol = ly_car (line_l->get_grob_property ("columns"));
116 Grob* e = unsmob_grob (lastcol);
118 SCM between = ly_symbol2scm ("between-system-string");
119 SCM inter = e->internal_get_grob_property (between);
120 if (gh_string_p (inter))
122 pscore_l_->outputter_l_
123 ->output_scheme (scm_list_n (between,
124 inter, SCM_UNDEFINED));
131 Find the loose columns in POSNS, and drape them around the columns
132 specified in BETWEEN-COLS. */
134 set_loose_columns (Line_of_score* which, Column_x_positions const *posns)
136 for (int i = 0; i<posns->loose_cols_.size (); i++)
139 Item *loose = dynamic_cast<Item*> (posns->loose_cols_[i]);
140 Paper_column* col = dynamic_cast<Paper_column*> (loose);
150 SCM between = loose->get_grob_property ("between-cols");
151 if (!gh_pair_p (between))
156 left = dynamic_cast<Item*> (unsmob_grob (ly_car (between)));
157 left = left->column_l ();
160 loose = dynamic_cast<Item*> (unsmob_grob (ly_cdr (between)));
161 loose = loose->column_l ();
166 Real rx = right->relative_coordinate (right->get_parent (X_AXIS), X_AXIS);
167 Real lx = left->relative_coordinate (left->get_parent (X_AXIS), X_AXIS);
173 SCM between = loose->get_grob_property ("between-cols");
174 if (!gh_pair_p (between))
177 Paper_column *thiscol = dynamic_cast<Paper_column*> (loose);
179 thiscol->line_l_ = which;
180 thiscol->translate_axis (lx + j*(rx - lx)/divide_over, X_AXIS);
183 loose = dynamic_cast<Item*> (unsmob_grob (ly_cdr (between)));
191 Line_of_score::break_into_pieces (Array<Column_x_positions> const &breaking)
193 for (int i=0; i < breaking.size (); i++)
195 Line_of_score *line_l = dynamic_cast <Line_of_score*> (clone ());
197 // line_l->set_immutable_grob_property ("rank", gh_int2scm (i));
198 Link_array<Grob> c (breaking[i].cols_);
199 pscore_l_->typeset_line (line_l);
201 line_l->set_bound (LEFT,c[0]);
202 line_l->set_bound (RIGHT,c.top ());
203 for (int j=0; j < c.size (); j++)
205 c[j]->translate_axis (breaking[i].config_[j],X_AXIS);
206 dynamic_cast<Paper_column*> (c[j])->line_l_ = line_l;
208 set_loose_columns (line_l, &breaking[i]);
209 broken_into_l_arr_.push (line_l);
214 #define GLOBAL_SYMBOL(cname, name) \
217 cname ## _init_func () \
219 cname = ly_symbol2scm (name); \
220 scm_permanent_object (cname); \
222 ADD_SCM_INIT_FUNC (cname,cname ## _init_func);\
225 GLOBAL_SYMBOL (offset_sym , "translate-molecule");
226 GLOBAL_SYMBOL (placebox_sym , "placebox");
227 GLOBAL_SYMBOL (combine_sym , "combine-molecule");
228 GLOBAL_SYMBOL (no_origin_sym , "no-origin");
229 GLOBAL_SYMBOL (define_origin_sym , "define-origin");
234 Line_of_score::output_molecule (SCM expr, Offset o)
239 if (!gh_pair_p (expr))
242 SCM head =ly_car (expr);
243 if (unsmob_input (head))
245 Input * ip = unsmob_input (head);
248 pscore_l_->outputter_l_->output_scheme (scm_list_n (define_origin_sym,
249 ly_str02scm (ip->file_str ().ch_C ()),
250 gh_int2scm (ip->line_number ()),
251 gh_int2scm (ip->column_number ()),
253 expr = ly_cadr (expr);
255 else if (head == no_origin_sym)
257 pscore_l_->outputter_l_->output_scheme (scm_list_n (no_origin_sym, SCM_UNDEFINED));
258 expr = ly_cadr (expr);
260 else if (head == offset_sym)
262 o += ly_scm2offset (ly_cadr (expr));
263 expr = ly_caddr (expr);
265 else if (head == combine_sym)
267 output_molecule (ly_cadr (expr), o);
268 expr = ly_caddr (expr);
272 pscore_l_->outputter_l_->
273 output_scheme (scm_list_n (placebox_sym,
274 gh_double2scm (o[X_AXIS]),
275 gh_double2scm (o[Y_AXIS]),
285 Line_of_score::output_scheme (SCM s)
287 pscore_l_->outputter_l_->output_scheme (s);
291 Line_of_score::add_column (Paper_column*p)
294 SCM cs = me->get_grob_property ("columns");
295 Grob * prev = gh_pair_p (cs) ? unsmob_grob (ly_car (cs)) : 0;
297 p->rank_i_ = prev ? Paper_column::rank_i (prev) + 1 : 0;
299 me->set_grob_property ("columns", gh_cons (p->self_scm (), cs));
301 Axis_group_interface::add_element (me, p);
307 TODO: use scm_map iso. for loops.
310 Line_of_score::pre_processing ()
312 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
313 unsmob_grob (ly_car (s))->discretionary_processing ();
315 if (verbose_global_b)
316 progress_indication (_f ("Element count %d ", element_count ()));
319 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
320 unsmob_grob (ly_car (s))->handle_prebroken_dependencies ();
322 fixup_refpoints (get_grob_property ("all-elements"));
324 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
326 Grob* sc = unsmob_grob (ly_car (s));
327 sc->calculate_dependencies (PRECALCED, PRECALCING, ly_symbol2scm ("before-line-breaking-callback"));
330 progress_indication ("\n" + _ ("Calculating column positions...") + " ");
331 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
333 Grob * e = unsmob_grob (ly_car (s));
334 SCM proc = e->get_grob_property ("spacing-procedure");
335 if (gh_procedure_p (proc))
336 gh_call1 (proc, e->self_scm ());
341 Line_of_score::post_processing (bool last_line)
343 for (SCM s = get_grob_property ("all-elements");
344 gh_pair_p (s); s = ly_cdr (s))
346 Grob* sc = unsmob_grob (ly_car (s));
347 sc->calculate_dependencies (POSTCALCED, POSTCALCING,
348 ly_symbol2scm ("after-line-breaking-callback"));
351 Interval i (extent (this, Y_AXIS));
353 programming_error ("Huh? Empty Line_of_score?");
355 translate_axis (- i[MAX], Y_AXIS);
357 Real height = i.length ();
360 programming_error ("Improbable system height");
365 generate all molecules to trigger all font loads.
367 (ugh. This is not very memory efficient.) */
368 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
370 unsmob_grob (ly_car (s))->get_molecule ();
375 SCM font_names = ly_quote_scm (paper_l ()->font_descriptions ());
376 output_scheme (scm_list_n (ly_symbol2scm ("define-fonts"),
383 output_scheme (scm_list_n (ly_symbol2scm ("start-line"),
384 gh_double2scm (height),
387 /* Output elements in three layers, 0, 1, 2.
388 The default layer is 1. */
389 for (int i = 0; i < 3; i++)
390 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s);
393 Grob *sc = unsmob_grob (ly_car (s));
394 Molecule *m = sc->get_molecule ();
398 SCM s = sc->get_grob_property ("layer");
399 int layer = gh_number_p (s) ? gh_scm2int (s) : 1;
403 Offset o (sc->relative_coordinate (this, X_AXIS),
404 sc->relative_coordinate (this, Y_AXIS));
406 SCM e = sc->get_grob_property ("extra-offset");
409 o[X_AXIS] += gh_scm2double (ly_car (e));
410 o[Y_AXIS] += gh_scm2double (ly_cdr (e));
413 output_molecule (m->get_expr (), o);
418 output_scheme (scm_list_n (ly_symbol2scm ("stop-last-line"), SCM_UNDEFINED));
422 output_scheme (scm_list_n (ly_symbol2scm ("stop-line"), SCM_UNDEFINED));
428 Line_of_score::broken_col_range (Item const*l, Item const*r) const
430 Link_array<Item> ret;
434 SCM s = get_grob_property ("columns");
436 while (gh_pair_p (s) && ly_car (s) != r->self_scm ())
442 while (gh_pair_p (s) && ly_car (s) != l->self_scm ())
444 Paper_column*c = dynamic_cast<Paper_column*> (unsmob_grob (ly_car (s)));
445 if (Item::breakable_b (c) && !c->line_l_)
456 Return all columns, but filter out any unused columns , since they might
457 disrupt the spacing problem.
460 Line_of_score::column_l_arr ()const
463 = Pointer_group_interface__extract_elements (this, (Grob*) 0, "columns");
465 for (int i= acs.size (); i -- ;)
467 bool brb = Item::breakable_b (acs[i]);
468 bfound = bfound || brb;
471 the last column should be breakable. Weed out any columns that
472 seem empty. We need to retain breakable columns, in case
473 someone forced a breakpoint.
475 if (!bfound || !Paper_column::used_b (acs[i]))