]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-column.cc
* lily/tie.cc: remove minimum-length
[lilypond.git] / lily / tie-column.cc
1 /*
2   tie-column.cc -- implement Tie_column
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "tie-column.hh"
10 #include "paper-column.hh"
11 #include "spanner.hh"
12 #include "pointer-group-interface.hh"
13 #include "tie.hh"
14 #include "directional-element-interface.hh"
15 #include "rhythmic-head.hh"
16
17 /*
18   tie dir depends on what Tie_column does.
19 */
20 /*
21   TODO: this doesn't follow standard pattern. Regularize.
22 */
23 void
24 Tie_column::add_tie (Grob *me, Grob *tie)
25 {
26   if (tie->get_parent (Y_AXIS)
27       && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
28     return;
29
30   if (!Pointer_group_interface::count (me, ly_symbol2scm ("ties")))
31     {
32       dynamic_cast<Spanner *> (me)->set_bound (LEFT, Tie::head (tie, LEFT));
33       dynamic_cast<Spanner *> (me)->set_bound (RIGHT, Tie::head (tie, RIGHT));
34     }
35
36   tie->set_parent (me, Y_AXIS);
37   Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
38   tie->add_dependency (me);
39 }
40
41 void
42 Tie_column::set_directions (Grob *me)
43 {
44   werner_directions (me);
45 }
46
47 int
48 tie_compare (Grob *const &s1,
49              Grob *const &s2)
50 {
51   return sign (Tie::get_position (s1) - Tie::get_position (s2));
52 }
53
54 #if 0
55 /*
56   Werner:
57
58   . The algorithm to choose the direction of the ties doesn't work
59   properly.  I suggest the following for applying ties sequentially
60   from top to bottom:
61
62   + The topmost tie is always `up'.
63
64   + If there is a vertical gap to the last note above larger than
65   or equal to a fifth (or sixth?), the tie is `up', otherwise it
66   is `down'.
67
68   + The bottommost tie is always `down'.
69 */
70 void
71 Tie_column::werner_directions (Grob *me)
72 {
73   extract_grob_set (me, "ties", ro_ties);
74   Link_array<Grob> ties (ro_ties);
75   if (!ties.size ())
76     return;
77
78   ties.sort (tie_compare);
79
80   Direction d = get_grob_direction (me);
81   if (d)
82     {
83       for (int i = ties.size (); i--;)
84         {
85           Grob *t = ties[i];
86           if (!get_grob_direction (t))
87             set_grob_direction (t, d);
88         }
89       return;
90     }
91
92   if (ties.size () == 1)
93     {
94       Grob *t = ties[0];
95       if (t->is_live ()
96           && !get_grob_direction (t))
97         set_grob_direction (t, Tie::get_default_dir (t));
98       return;
99     }
100
101   Real last_down_pos = 10000;
102   if (!get_grob_direction (ties[0]))
103     set_grob_direction (ties[0], DOWN);
104
105   /*
106     Go downward.
107   */
108   Grob *last_tie = 0;
109   for (int i = ties.size (); i--;)
110     {
111       Grob *t = ties[i];
112
113       Direction d = get_grob_direction (t);
114       Real p = Tie::get_position (t);
115       if (!d)
116         {
117           if (last_tie
118               && Tie::get_column_rank (t, LEFT)
119               < Tie::get_column_rank (last_tie, LEFT))
120             d = DOWN;
121           else if (last_down_pos - p > 5)
122             d = UP;
123           else
124             d = DOWN;
125
126           set_grob_direction (t, d);
127         }
128
129       if (d == DOWN)
130         last_down_pos = p;
131
132       last_tie = t;
133     }
134
135   return;
136 }
137 #endif
138
139 MAKE_SCHEME_CALLBACK (Tie_column, after_line_breaking, 1);
140 SCM
141 Tie_column::after_line_breaking (SCM smob)
142 {
143   werner_directions (unsmob_grob (smob));
144   return SCM_UNSPECIFIED;
145 }
146
147 /*
148   Extend the spanner over its Tie constituents.
149 */
150 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
151 SCM
152 Tie_column::before_line_breaking (SCM smob)
153 {
154   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
155   for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
156     {
157       Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
158       Direction dir = LEFT;
159       do
160         {
161           if (dir * tie->get_bound (dir)->get_column ()->get_rank ()
162               > dir * me->get_bound (dir)->get_column ()->get_rank ())
163             me->set_bound (dir, Tie::head (tie, dir));
164         }
165       while (flip (&dir) != LEFT);
166     }
167   return SCM_UNSPECIFIED;
168 }
169
170 ADD_INTERFACE (Tie_column, "tie-column-interface",
171                "Object that sets directions of multiple ties in a tied chord",
172                "direction");
173
174