*** empty log message ***
[lilypond.git] / lily / tie-column.cc
blob9f8bf74fb949502925090cb01df5279142768080
1 /*
2 tie-column.cc -- implement Tie_column
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "tie-column.hh"
10 #include "paper-column.hh"
11 #include "spanner.hh"
12 #include "group-interface.hh"
13 #include "tie.hh"
14 #include "directional-element-interface.hh"
15 #include "rhythmic-head.hh"
18 tie dir depends on what Tie_column does.
21 TODO: this doesn't follow standard pattern. Regularize.
23 void
24 Tie_column::add_tie (Grob *me, Grob *tie)
26 if (tie->get_parent (Y_AXIS)
27 && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
28 return;
30 if (!Pointer_group_interface::count (me, ly_symbol2scm ("ties")))
32 dynamic_cast<Spanner *> (me)->set_bound (LEFT, Tie::head (tie, LEFT));
33 dynamic_cast<Spanner *> (me)->set_bound (RIGHT, Tie::head (tie, RIGHT));
36 tie->set_parent (me, Y_AXIS);
37 Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
38 tie->add_dependency (me);
41 void
42 Tie_column::set_directions (Grob *me)
44 werner_directions (me);
47 int
48 tie_compare (Grob *const &s1,
49 Grob *const &s2)
51 return sign (Tie::get_position (s1) - Tie::get_position (s2));
55 Werner:
57 . The algorithm to choose the direction of the ties doesn't work
58 properly. I suggest the following for applying ties sequentially
59 from top to bottom:
61 + The topmost tie is always `up'.
63 + If there is a vertical gap to the last note above larger than
64 or equal to a fifth (or sixth?), the tie is `up', otherwise it
65 is `down'.
67 + The bottommost tie is always `down'.
69 void
70 Tie_column::werner_directions (Grob *me)
72 Link_array<Grob> ties
73 = extract_grob_array (me, ly_symbol2scm ("ties"));
75 if (!ties.size ())
76 return;
78 ties.sort (tie_compare);
80 Direction d = get_grob_direction (me);
81 if (d)
83 for (int i = ties.size (); i--;)
85 Grob *t = ties[i];
86 if (!get_grob_direction (t))
87 set_grob_direction (t, d);
89 return;
92 if (ties.size () == 1)
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;
101 Real last_down_pos = 10000;
102 if (!get_grob_direction (ties[0]))
103 set_grob_direction (ties[0], DOWN);
106 Go downward.
108 Grob *last_tie = 0;
109 for (int i = ties.size (); i--;)
111 Grob *t = ties[i];
113 Direction d = get_grob_direction (t);
114 Real p = Tie::get_position (t);
115 if (!d)
117 if (last_tie
118 && Tie::get_column_rank (t, LEFT)
119 < Tie::get_column_rank (last_tie, LEFT))
121 d = DOWN;
123 else if (last_down_pos - p > 5)
125 d = UP;
127 else
129 d = DOWN;
132 set_grob_direction (t, d);
135 if (d == DOWN)
136 last_down_pos = p;
138 last_tie = t;
141 return;
144 MAKE_SCHEME_CALLBACK (Tie_column, after_line_breaking, 1);
146 Tie_column::after_line_breaking (SCM smob)
148 werner_directions (unsmob_grob (smob));
149 return SCM_UNSPECIFIED;
153 Extend the spanner over its Tie constituents.
155 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
157 Tie_column::before_line_breaking (SCM smob)
159 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
160 for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
162 Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
163 Direction dir = LEFT;
166 if (dir * Paper_column::get_rank (tie->get_bound (dir)->get_column ())
167 > dir * Paper_column::get_rank (me->get_bound (dir)->get_column ()))
169 me->set_bound (dir, Tie::head (tie, dir));
172 while (flip (&dir) != LEFT);
174 return SCM_UNSPECIFIED;
177 ADD_INTERFACE (Tie_column, "tie-column-interface",
178 "Object that sets directions of multiple ties in a tied chord",
179 "direction");