2 system.cc -- implement System
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "input-smob.hh"
10 #include "axis-group-interface.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 System::System (SCM s)
42 System::element_count () const
44 return scm_ilength (get_grob_property ("all-elements"));
48 System::typeset_grob (Grob * elem_p)
50 elem_p->pscore_l_ = pscore_l_;
51 Pointer_group_interface::add_grob (this, ly_symbol2scm ("all-elements"),elem_p);
52 scm_gc_unprotect_object (elem_p->self_scm ());
56 System::output_lines ()
58 for (SCM s = get_grob_property ("all-elements");
59 gh_pair_p (s); s = ly_cdr (s))
61 unsmob_grob (ly_car (s))->do_break_processing ();
65 fixups must be done in broken line_of_scores, because new elements
66 are put over there. */
68 for (int i=0; i < broken_into_l_arr_.size (); i++)
70 Grob *se = broken_into_l_arr_[i];
71 SCM all = se->get_grob_property ("all-elements");
72 for (SCM s = all; gh_pair_p (s); s = ly_cdr (s))
74 fixup_refpoint (ly_car (s));
76 count += scm_ilength (all);
80 needed for doing items.
82 fixup_refpoints (get_grob_property ("all-elements"));
85 for (SCM s = get_grob_property ("all-elements");
86 gh_pair_p (s); s = ly_cdr (s))
88 unsmob_grob (ly_car (s))->handle_broken_dependencies ();
90 handle_broken_dependencies ();
93 progress_indication (_f ("Element count %d.", count + element_count ()));
96 for (int i=0; i < broken_into_l_arr_.size (); i++)
98 System *line_l = dynamic_cast<System*> (broken_into_l_arr_[i]);
100 if (verbose_global_b)
101 progress_indication ("[");
102 line_l->post_processing (i+1 == broken_into_l_arr_.size ());
104 if (verbose_global_b)
106 progress_indication (to_str (i));
107 progress_indication ("]");
110 if (i < broken_into_l_arr_.size () - 1)
112 SCM lastcol = ly_car (line_l->get_grob_property ("columns"));
113 Grob* e = unsmob_grob (lastcol);
115 SCM between = ly_symbol2scm ("between-system-string");
116 SCM inter = e->internal_get_grob_property (between);
117 if (gh_string_p (inter))
119 pscore_l_->outputter_l_
120 ->output_scheme (scm_list_n (between,
121 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 (System* 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))
155 Item * l=dynamic_cast<Item*> (unsmob_grob (ly_car (between)));
156 Item * r=dynamic_cast<Item*> (unsmob_grob (ly_cdr (between)));
163 left = l->column_l ();
168 loose = right = r->column_l ();
174 Real rx = right->relative_coordinate (right->get_parent (X_AXIS), X_AXIS);
175 Real lx = left->relative_coordinate (left->get_parent (X_AXIS), X_AXIS);
178 divide space equally over loose columns.
184 SCM between = loose->get_grob_property ("between-cols");
185 if (!gh_pair_p (between))
188 Paper_column *thiscol = dynamic_cast<Paper_column*> (loose);
190 thiscol->line_l_ = which;
191 thiscol->translate_axis (lx + j*(rx - lx)/divide_over, X_AXIS);
194 loose = dynamic_cast<Item*> (unsmob_grob (ly_cdr (between)));
198 We divide the remaining space of the column over the left and
199 right side. At the moment, we
202 Grob * common = right->common_refpoint (left, X_AXIS);
204 Real rx = right->extent(common, X_AXIS)[LEFT];
205 Real lx = left->extent(common, X_AXIS)[RIGHT];
206 Real total_dx = rx - lx;
207 Interval cval =col->extent (col, X_AXIS);
211 We put it in the middle. This is not an ideal solution -- the
212 break alignment code inserts a fixed space before the clef
213 (about 1 SS), while the space following the clef is
214 flexible. In tight situations, the clef will almost be on top
215 of the following note.
218 Real dx = rx-lx - cval.length ();
219 if (total_dx < 2* cval.length ())
222 todo: this is discontinuous. I'm too tired to
223 invent a sliding mechanism. Duh.
232 col->line_l_ = which;
233 col->translate_axis (lx + dx - cval[LEFT], X_AXIS);
240 System::break_into_pieces (Array<Column_x_positions> const &breaking)
242 for (int i=0; i < breaking.size (); i++)
244 System *line_l = dynamic_cast <System*> (clone ());
246 // line_l->set_immutable_grob_property ("rank", gh_int2scm (i));
247 Link_array<Grob> c (breaking[i].cols_);
248 pscore_l_->typeset_line (line_l);
250 line_l->set_bound (LEFT,c[0]);
251 line_l->set_bound (RIGHT,c.top ());
252 for (int j=0; j < c.size (); j++)
254 c[j]->translate_axis (breaking[i].config_[j],X_AXIS);
255 dynamic_cast<Paper_column*> (c[j])->line_l_ = line_l;
257 set_loose_columns (line_l, &breaking[i]);
258 broken_into_l_arr_.push (line_l);
264 System::output_molecule (SCM expr, Offset o)
269 if (!gh_pair_p (expr))
272 SCM head =ly_car (expr);
273 if (unsmob_input (head))
275 Input * ip = unsmob_input (head);
278 pscore_l_->outputter_l_->output_scheme (scm_list_n (ly_symbol2scm ("define-origin"),
279 ly_str02scm (ip->file_str ().ch_C ()),
280 gh_int2scm (ip->line_number ()),
281 gh_int2scm (ip->column_number ()),
283 expr = ly_cadr (expr);
285 else if (head == ly_symbol2scm ("no-origin"))
287 pscore_l_->outputter_l_->output_scheme (scm_list_n (head, SCM_UNDEFINED));
288 expr = ly_cadr (expr);
290 else if (head == ly_symbol2scm ("translate-molecule"))
292 o += ly_scm2offset (ly_cadr (expr));
293 expr = ly_caddr (expr);
295 else if (head == ly_symbol2scm ("combine-molecule"))
297 output_molecule (ly_cadr (expr), o);
298 expr = ly_caddr (expr);
302 pscore_l_->outputter_l_->
303 output_scheme (scm_list_n (ly_symbol2scm ("placebox"),
304 gh_double2scm (o[X_AXIS]),
305 gh_double2scm (o[Y_AXIS]),
315 System::output_scheme (SCM s)
317 pscore_l_->outputter_l_->output_scheme (s);
321 System::add_column (Paper_column*p)
324 SCM cs = me->get_grob_property ("columns");
325 Grob * prev = gh_pair_p (cs) ? unsmob_grob (ly_car (cs)) : 0;
327 p->rank_i_ = prev ? Paper_column::rank_i (prev) + 1 : 0;
329 me->set_grob_property ("columns", gh_cons (p->self_scm (), cs));
331 Axis_group_interface::add_element (me, p);
337 TODO: use scm_map iso. for loops.
340 System::pre_processing ()
342 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
343 unsmob_grob (ly_car (s))->discretionary_processing ();
345 if (verbose_global_b)
346 progress_indication (_f ("Element count %d ", element_count ()));
349 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
350 unsmob_grob (ly_car (s))->handle_prebroken_dependencies ();
352 fixup_refpoints (get_grob_property ("all-elements"));
354 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
356 Grob* sc = unsmob_grob (ly_car (s));
357 sc->calculate_dependencies (PRECALCED, PRECALCING, ly_symbol2scm ("before-line-breaking-callback"));
360 progress_indication ("\n" + _ ("Calculating column positions...") + " ");
361 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
363 Grob * e = unsmob_grob (ly_car (s));
364 SCM proc = e->get_grob_property ("spacing-procedure");
365 if (gh_procedure_p (proc))
366 gh_call1 (proc, e->self_scm ());
371 System::post_processing (bool last_line)
373 for (SCM s = get_grob_property ("all-elements");
374 gh_pair_p (s); s = ly_cdr (s))
376 Grob* sc = unsmob_grob (ly_car (s));
377 sc->calculate_dependencies (POSTCALCED, POSTCALCING,
378 ly_symbol2scm ("after-line-breaking-callback"));
381 Interval i (extent (this, Y_AXIS));
383 programming_error ("Huh? Empty System?");
385 translate_axis (- i[MAX], Y_AXIS);
387 Real height = i.length ();
390 programming_error ("Improbable system height");
395 generate all molecules to trigger all font loads.
397 (ugh. This is not very memory efficient.) */
398 this->get_molecule();
399 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s); s = ly_cdr (s))
401 unsmob_grob (ly_car (s))->get_molecule ();
406 SCM font_names = ly_quote_scm (paper_l ()->font_descriptions ());
407 output_scheme (scm_list_n (ly_symbol2scm ("define-fonts"),
414 output_scheme (scm_list_n (ly_symbol2scm ("start-system"),
415 gh_double2scm (height),
418 /* Output elements in three layers, 0, 1, 2.
419 The default layer is 1. */
422 Molecule *m = this->get_molecule();
424 output_molecule (m->get_expr (), Offset(0,0));
427 for (int i = 0; i < 3; i++)
428 for (SCM s = get_grob_property ("all-elements"); gh_pair_p (s);
431 Grob *sc = unsmob_grob (ly_car (s));
432 Molecule *m = sc->get_molecule ();
436 SCM s = sc->get_grob_property ("layer");
437 int layer = gh_number_p (s) ? gh_scm2int (s) : 1;
441 Offset o (sc->relative_coordinate (this, X_AXIS),
442 sc->relative_coordinate (this, Y_AXIS));
444 SCM e = sc->get_grob_property ("extra-offset");
447 o[X_AXIS] += gh_scm2double (ly_car (e));
448 o[Y_AXIS] += gh_scm2double (ly_cdr (e));
451 output_molecule (m->get_expr (), o);
458 output_scheme (scm_list_n (ly_symbol2scm ("stop-last-system"), SCM_UNDEFINED));
462 output_scheme (scm_list_n (ly_symbol2scm ("stop-system"), SCM_UNDEFINED));
468 System::broken_col_range (Item const*l, Item const*r) const
470 Link_array<Item> ret;
474 SCM s = get_grob_property ("columns");
476 while (gh_pair_p (s) && ly_car (s) != r->self_scm ())
482 while (gh_pair_p (s) && ly_car (s) != l->self_scm ())
484 Paper_column*c = dynamic_cast<Paper_column*> (unsmob_grob (ly_car (s)));
485 if (Item::breakable_b (c) && !c->line_l_)
496 Return all columns, but filter out any unused columns , since they might
497 disrupt the spacing problem.
500 System::column_l_arr ()const
503 = Pointer_group_interface__extract_grobs (this, (Grob*) 0, "columns");
505 for (int i= acs.size (); i -- ;)
507 bool brb = Item::breakable_b (acs[i]);
508 bfound = bfound || brb;
511 the last column should be breakable. Weed out any columns that
512 seem empty. We need to retain breakable columns, in case
513 someone forced a breakpoint.
515 if (!bfound || !Paper_column::used_b (acs[i]))
524 ADD_INTERFACE (System,"system-interface",
525 "Super grob, parent of all:
527 The columns of a score that form one line. The toplevel grob. Any
528 grob has a Line_of_score as both X and Y reference point. The
529 Paper_score contains one grob of this type. Control enters the
530 Grob dependency calculation from this single Line_of_score
532 "between-system-string all-elements columns");