* The grand 2005-2006 replace.
[lilypond/patrick.git] / lily / tie-column-format.cc
blob39c7286877908a5cba05879d278c12d2e73f6207
1 /*
2 tie-column-format.cc -- implement formatting routines for Tie_column
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
10 #include "stem.hh"
11 #include "note-head.hh"
12 #include "tie.hh"
13 #include "parray.hh"
14 #include "spanner.hh"
15 #include "item.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "directional-element-interface.hh"
18 #include "rhythmic-head.hh"
19 #include "tie-formatting-problem.hh"
20 #include "tie-configuration.hh"
22 #include <set>
25 void
26 shift_small_ties (Ties_configuration *tie_configs,
27 Grob *staff_referencer,
28 Tie_details const &details)
30 set<int> positions_taken;
31 for (int i = 0; i < tie_configs->size (); i++)
32 positions_taken.insert (int (rint (tie_configs->elem (i).position_)));
34 for (int i = 0; i < tie_configs->size (); i++)
36 Tie_configuration * conf = &tie_configs->elem_ref (i);
39 on staff line and small enough, translate a little further
41 Real h = conf->height (details);
42 bool next_free = positions_taken.find (int (rint (conf->position_ + conf->dir_)))
43 == positions_taken.end ();
45 int rounded_pos = int (rint (conf->position_ + conf->delta_y_ / details.staff_space_));
46 bool on_line = Staff_symbol_referencer::on_staffline (staff_referencer, rounded_pos);
48 if (next_free)
49 if (on_line && h < 0.4 * details.staff_space_)
51 positions_taken.insert (int (rint (conf->position_ + conf->dir_)));
52 conf->delta_y_ += 0.2 * details.staff_space_ * conf->dir_;
54 else if (!on_line && h > 0.6 * details.staff_space_)
56 positions_taken.insert (int (rint (conf->position_ + conf->dir_)));
57 conf->delta_y_ += 0.5 * details.staff_space_ * conf->dir_;
63 void
64 final_shape_adjustment (Tie_configuration &conf,
65 Tie_formatting_problem const &problem,
66 Grob *staff_referencer)
68 Tie_details const &details (problem.details_);
69 Real line_dy = 0.0;
70 bool on_line = Staff_symbol_referencer::on_staffline (staff_referencer,
71 int (rint (conf.position_)));
72 if (on_line)
73 line_dy = - sign (conf.height (details) - 0.6 * details.staff_space_)
74 * 0.2 * details.staff_space_ * conf.dir_;
76 Real y = conf.position_ * details.staff_space_ * 0.5
77 + line_dy;
79 conf.attachment_x_ = problem.get_attachment (y);
80 conf.attachment_x_.intersect (problem.get_attachment (y + conf.dir_ * details.staff_space_ * 0.5));
82 conf.delta_y_ += line_dy;
83 conf.attachment_x_.widen (-details.x_gap_);
84 if (!on_line
85 && Staff_symbol_referencer::staff_radius (staff_referencer) * details.staff_space_ > y)
86 conf.center_tie_vertically (details);