*** empty log message ***
[lilypond.git] / lily / tie-column.cc
blob17ea197241e26f86137e55214eb8a17443dec393
1 /*
2 tie-column.cc -- implement Tie_column
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "spanner.hh"
11 #include "tie-column.hh"
12 #include "group-interface.hh"
13 #include "tie.hh"
14 #include "directional-element-interface.hh"
15 #include "rhythmic-head.hh"
23 tie dir depends on what Tie_column does.
26 TODO: this doesn't follow standard pattern. Regularize.
28 void
29 Tie_column::add_tie (Grob*me,Grob *s)
31 if (s->get_parent (Y_AXIS)
32 && Tie_column::has_interface (s->get_parent (Y_AXIS)))
33 return ;
35 if (! Pointer_group_interface::count (me, "ties"))
37 dynamic_cast<Spanner*> (me)->set_bound (LEFT, Tie::head (s,LEFT));
38 dynamic_cast<Spanner*> (me)->set_bound (RIGHT, Tie::head (s,RIGHT));
40 s->set_parent (me, Y_AXIS);
41 Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), s);
42 s->add_dependency (me);
46 void
47 Tie_column::set_directions (Grob*me)
49 werner_directions (me);
52 int
53 tie_compare (Grob* const & s1,
54 Grob* const & s2)
56 return sign (Tie::get_position (s1) - Tie::get_position (s2));
60 See [Ross p. 138].
63 In normal chord cases, the outer ties point outwards, and the
64 direction of the rest is determined by their staff position.
66 Ross forgets about the tie that is *on* the middle staff line. We
67 assume it goes UP. (TODO: make me settable) */
68 void
69 Tie_column::old_directions (Grob*me)
71 Link_array<Grob> ties =
72 Pointer_group_interface__extract_grobs (me, (Grob*)0, "ties");
74 for (int i = ties.size (); i--;)
75 if (get_grob_direction (ties[i]))
76 ties.del (i);
78 if (!ties.size ())
79 return ;
81 Direction d = get_grob_direction (me);
82 if (d)
84 for (int i = ties.size (); i--;)
86 Grob * t = ties[i];
87 set_grob_direction (t, d);
89 return;
92 if (ties.size () == 1)
94 Grob * t = ties[0];
95 set_grob_direction (t,Tie::get_default_dir (t));
96 return;
99 ties.sort (tie_compare);
100 set_grob_direction (ties[0], DOWN);
101 ties.del (0);
103 set_grob_direction (ties.pop (), UP);
104 for (int i=ties.size (); i--;)
106 Grob * t = ties[i];
107 Real p = Tie::get_position (t);
108 Direction d = (Direction) sign (p);
109 if (!d)
110 d = UP;
111 set_grob_direction (t, d);
118 % . The algorithm to choose the direction of the ties doesn't work
119 % properly. I suggest the following for applying ties sequentially
120 % from top to bottom:
122 % + The topmost tie is always `up'.
124 % + If there is a vertical gap to the last note above larger than
125 % or equal to a fifth (or sixth?), the tie is `up', otherwise it
126 % is `down'.
128 % + The bottommost tie is always `down'.
131 void
132 Tie_column::werner_directions (Grob *me)
134 Link_array<Grob> ties =
135 Pointer_group_interface__extract_grobs (me, (Grob*)0, "ties");
137 if (!ties.size ())
138 return ;
140 ties.sort (tie_compare);
142 Direction d = get_grob_direction (me);
143 if (d)
145 for (int i = ties.size (); i--;)
147 Grob * t = ties[i];
148 if (!get_grob_direction (t))
149 set_grob_direction (t, d);
151 return ;
154 if (ties.size () == 1)
156 Grob * t = ties[0];
157 if (t->live ()
158 && !get_grob_direction (t))
159 set_grob_direction (t,Tie::get_default_dir (t));
160 return ;
163 Real last_down_pos = 10000;
164 if (!get_grob_direction (ties[0]))
165 set_grob_direction (ties[0], DOWN);
167 for (int i = ties.size (); i--;)
169 Grob *t = ties[i];
171 Direction d = get_grob_direction (t);
172 Real p = Tie::get_position (t);
173 if (!d)
175 if (last_down_pos - p > 5)
177 d = UP;
179 else
181 d = DOWN;
184 set_grob_direction (t, d);
187 if (d == DOWN)
188 last_down_pos = p;
191 return ;
195 MAKE_SCHEME_CALLBACK (Tie_column,after_line_breaking,1);
197 Tie_column::after_line_breaking (SCM smob)
199 werner_directions (unsmob_grob (smob));
200 return SCM_UNSPECIFIED;
205 ADD_INTERFACE (Tie_column,"tie-column-interface",
206 "Object that sets directions of multiple ties in a tied chord",
207 "direction");