]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-column-format.cc
* The grand 2005-2006 replace.
[lilypond.git] / lily / tie-column-format.cc
1 /*
2   tie-column-format.cc -- implement formatting routines for Tie_column
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
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"
21
22 #include <set>
23
24
25 void
26 shift_small_ties (Ties_configuration *tie_configs,
27                   Grob *staff_referencer,
28                   Tie_details const &details)
29 {
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_)));
33
34   for (int i = 0; i < tie_configs->size (); i++)
35     {
36       Tie_configuration * conf = &tie_configs->elem_ref (i);
37
38       /*
39         on staff line and small enough, translate a little further 
40       */
41       Real h = conf->height (details);
42       bool next_free = positions_taken.find (int (rint (conf->position_ + conf->dir_)))
43         == positions_taken.end ();
44
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);
47       
48       if (next_free)
49         if (on_line && h < 0.4 * details.staff_space_)
50           {
51             positions_taken.insert (int (rint (conf->position_ + conf->dir_)));
52             conf->delta_y_ += 0.2 * details.staff_space_ * conf->dir_;
53           }
54         else if (!on_line && h > 0.6 * details.staff_space_)
55           {
56             positions_taken.insert (int (rint (conf->position_ + conf->dir_)));
57             conf->delta_y_ += 0.5 * details.staff_space_ * conf->dir_;
58           }
59     }
60 }
61
62
63 void
64 final_shape_adjustment (Tie_configuration &conf,
65                         Tie_formatting_problem const &problem,
66                         Grob *staff_referencer)
67 {
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_;
75
76   Real y = conf.position_ * details.staff_space_ * 0.5
77     + line_dy;
78   
79   conf.attachment_x_ = problem.get_attachment (y);
80   conf.attachment_x_.intersect (problem.get_attachment (y + conf.dir_ * details.staff_space_ * 0.5));
81
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);
87 }
88
89