2 tie.cc -- implement Tie
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "paper-def.hh"
13 #include "rhythmic-head.hh"
15 #include "paper-column.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "directional-element-interface.hh"
19 #include "molecule.hh"
20 #include "bezier-bow.hh"
24 Tie::set_head (Direction d, Item * head_l)
27 index_set_cell (get_elt_pointer ("heads"), d, head_l->self_scm_);
29 set_bound (d, head_l);
30 add_dependency (head_l);
36 set_elt_pointer ("heads", gh_cons (SCM_EOL, SCM_EOL));
37 dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = 0.0;
38 dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0;
43 Tie::head (Direction d) const
45 SCM c = get_elt_pointer ("heads");
46 c = index_cell (c, d);
48 return dynamic_cast<Rhythmic_head*> (unsmob_element (c));
52 Tie::position_f () const
55 ? Staff_symbol_referencer_interface (head (LEFT)).position_f ()
56 : Staff_symbol_referencer_interface (head (RIGHT)).position_f () ;
61 ugh: direction of the Tie is more complicated. See [Ross] p136 and further
64 Tie::get_default_dir () const
66 Stem * sl = head(LEFT) ? head (LEFT)->stem_l () :0;
67 Stem * sr = head(RIGHT) ? head (RIGHT)->stem_l () :0;
69 if (sl && Directional_element_interface (sl).get () == UP
70 && sr && Directional_element_interface (sr).get () == UP)
77 fixme must use spanned drul from heads elt property
81 Tie::do_add_processing()
83 if (!(head (LEFT) && head (RIGHT)))
84 warning (_ ("lonely tie"));
87 Drul_array<Rhythmic_head *> new_head_drul;
88 new_head_drul[LEFT] = head(LEFT);
89 new_head_drul[RIGHT] = head(RIGHT);
92 new_head_drul[d] = head((Direction)-d);
93 } while (flip(&d) != LEFT);
95 index_set_cell (get_elt_pointer ("heads"), LEFT, new_head_drul[LEFT]->self_scm_ );
96 index_set_cell (get_elt_pointer ("heads"), RIGHT, new_head_drul[RIGHT]->self_scm_ );
99 GLUE_SCORE_ELEMENT(Tie,after_line_breaking);
101 Tie::member_after_line_breaking ()
103 if (!head (LEFT) && !head (RIGHT))
105 programming_error ("Tie without heads.");
107 return SCM_UNDEFINED;
110 if (!Directional_element_interface (this).get ())
111 Directional_element_interface (this).set (get_default_dir ());
113 Real staff_space = Staff_symbol_referencer_interface (this).staff_space ();
114 Real half_space = staff_space / 2;
115 Real x_gap_f = paper_l ()->get_var ("tie_x_gap");
116 Real y_gap_f = paper_l ()->get_var ("tie_y_gap");
119 Slur and tie placement [OSU]
123 * x = inner vertical tangent - d * gap
129 OSU: not different for outer notes, so why all this code?
130 ie, can we drop this, or should it be made switchable.
133 dx_f_drul_[LEFT] = head (LEFT)->extent (X_AXIS).length ();
135 dx_f_drul_[LEFT] = get_broken_left_end_align ();
136 dx_f_drul_[LEFT] += x_gap_f;
137 dx_f_drul_[RIGHT] -= x_gap_f;
140 Slur and tie placement [OSU] -- check this
144 * y = dx < 5ss: horizontal tangent
145 y = dx >= 5ss: y next interline - d * 0.25 ss
147 which probably means that OSU assumes that
155 Real ypos = position_f ();
157 Real y_f = half_space * ypos;
158 int ypos_i = int (ypos);
160 Real dx_f = extent (X_AXIS).length () + dx_f_drul_[RIGHT] - dx_f_drul_[LEFT];
161 Direction dir = Directional_element_interface (this).get();
162 if (dx_f < paper_l ()->get_var ("tie_staffspace_length"))
164 if (abs (ypos_i) % 2)
165 y_f += dir * half_space;
166 y_f += dir * y_gap_f;
170 if (! (abs (ypos_i) % 2))
171 y_f += dir * half_space;
172 y_f += dir * half_space;
173 y_f -= dir * y_gap_f;
176 dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = y_f;
178 return SCM_UNDEFINED;
184 Tie::get_rods () const
189 r.item_l_drul_ [LEFT]=get_bound (LEFT);
190 r.item_l_drul_ [RIGHT]=get_bound (RIGHT);
192 r.distance_f_ = paper_l ()->get_var ("tie_x_minimum");
197 GLUE_SCORE_ELEMENT(Tie,brew_molecule);
200 Tie::member_brew_molecule () const
202 Real thick = paper_l ()->get_var ("tie_thickness");
203 Bezier one = get_curve ();
206 SCM d = get_elt_property ("dashed");
208 a = lookup_l ()->dashed_slur (one, thick, gh_scm2int (d));
210 a = lookup_l ()->slur (one, Directional_element_interface (this).get () * thick, thick);
212 return a.create_scheme();
218 Tie::get_curve () const
220 Direction d (Directional_element_interface (this).get ());
221 Bezier_bow b (get_encompass_offset_arr (), d);
223 Real staff_space = Staff_symbol_referencer_interface (this).staff_space ();
224 Real h_inf = paper_l ()->get_var ("tie_height_limit_factor") * staff_space;
225 Real r_0 = paper_l ()->get_var ("tie_ratio");
227 b.set_default_bezier (h_inf, r_0);
228 Bezier c = b.get_bezier ();
230 /* should do this for slurs as well. */
231 Array<Real> horizontal (c.solve_derivative (Offset (1,0)));
233 if (horizontal.size ())
236 ugh. Doesnt work for non-horizontal curves.
238 Real y = c.curve_point (horizontal[0])[Y_AXIS];
240 Real ry = rint (y/staff_space) * staff_space;
244 && fabs (diff) < paper_l ()->get_var ("tie_staffline_clearance"))
246 newy = ry - 0.5 * staff_space * sign (diff) ;
249 Real y0 = c.control_ [0][Y_AXIS];
250 c.control_[2][Y_AXIS] =
251 c.control_[1][Y_AXIS] =
252 (c.control_[1][Y_AXIS] - y0) * ((newy - y0) / (y - y0)) + y0;
255 programming_error ("Tie is nowhere horizontal");
260 Tie::get_encompass_offset_arr () const
262 Array<Offset> offset_arr;
263 offset_arr.push (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]));
264 offset_arr.push (Offset (spanner_length () + dx_f_drul_[RIGHT],