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 (Score_element*me,Direction d, Item * head_l)
26 assert (!head (me,d));
27 index_set_cell (me->get_elt_property ("heads"), d, head_l->self_scm_);
29 dynamic_cast<Spanner*> (me)->set_bound (d, head_l);
30 me->add_dependency (head_l);
36 dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = 0.0;
37 dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0;
40 Tie::set_interface (Score_element*me)
42 me->set_elt_property ("heads", gh_cons (SCM_EOL, SCM_EOL));
43 me->set_interface (ly_symbol2scm ("tie-interface"));
46 Tie::has_interface (Score_element*me)
48 return me->has_interface (ly_symbol2scm ("tie-interface"));
52 Tie::head (Score_element*me, Direction d)
54 SCM c = me->get_elt_property ("heads");
55 c = index_cell (c, d);
57 return unsmob_element (c);
61 Tie::position_f (Score_element*me)
63 Direction d = head (me,LEFT) ? LEFT:RIGHT;
64 return Staff_symbol_referencer::position_f (head (me,d));
69 ugh: direction of the Tie is more complicated. See [Ross] p136 and further
72 Tie::get_default_dir (Score_element*me)
74 Item * sl = head(me,LEFT) ? Rhythmic_head::stem_l (head (me,LEFT)) :0;
75 Item * sr = head(me,RIGHT) ? Rhythmic_head::stem_l (head (me,RIGHT)) :0;
77 if (sl && Directional_element_interface (sl).get () == UP
78 && sr && Directional_element_interface (sr).get () == UP)
86 MAKE_SCHEME_CALLBACK(Tie,after_line_breaking);
88 Tie::after_line_breaking (SCM smob)
90 Tie*me = dynamic_cast<Tie*> (unsmob_element (smob));
92 if (!head (me,LEFT) && !head (me,RIGHT))
94 programming_error ("Tie without heads.");
99 if (!Directional_element_interface (me).get ())
100 Directional_element_interface (me).set (Tie::get_default_dir (me));
102 Real staff_space = Staff_symbol_referencer::staff_space (me);
103 Real half_space = staff_space / 2;
104 Real x_gap_f = me->paper_l ()->get_var ("tie_x_gap");
105 Real y_gap_f = me->paper_l ()->get_var ("tie_y_gap");
108 Slur and tie placement [OSU]
112 * x = inner vertical tangent - d * gap
118 OSU: not different for outer notes, so why all me code?
119 ie, can we drop me, or should it be made switchable.
122 me->dx_f_drul_[LEFT] = Tie::head (me,LEFT)->extent (X_AXIS).length ();
124 me->dx_f_drul_[LEFT] = dynamic_cast<Spanner*>(me)->get_broken_left_end_align ();
125 me->dx_f_drul_[LEFT] += x_gap_f;
126 me->dx_f_drul_[RIGHT] -= x_gap_f;
129 Slur and tie placement [OSU] -- check me
133 * y = dx < 5ss: horizontal tangent
134 y = dx >= 5ss: y next interline - d * 0.25 ss
136 which probably means that OSU assumes that
144 Real ypos = Tie::position_f (me);
146 Real y_f = half_space * ypos;
147 int ypos_i = int (ypos);
149 Real dx_f = me->extent (X_AXIS).length () + me->dx_f_drul_[RIGHT] - me->dx_f_drul_[LEFT];
150 Direction dir = Directional_element_interface (me).get();
151 if (dx_f < me->paper_l ()->get_var ("tie_staffspace_length"))
153 if (abs (ypos_i) % 2)
154 y_f += dir * half_space;
155 y_f += dir * y_gap_f;
159 if (! (abs (ypos_i) % 2))
160 y_f += dir * half_space;
161 y_f += dir * half_space;
162 y_f -= dir * y_gap_f;
165 me->dy_f_drul_[LEFT] = me->dy_f_drul_[RIGHT] = y_f;
167 return SCM_UNDEFINED;
171 MAKE_SCHEME_CALLBACK(Tie,set_spacing_rods);
173 Tie::set_spacing_rods (SCM smob)
175 Score_element*me = unsmob_element (smob);
176 Spanner*sp = dynamic_cast<Spanner*> (me);
179 r.item_l_drul_ [LEFT]=sp->get_bound (LEFT);
180 r.item_l_drul_ [RIGHT]=sp->get_bound (RIGHT);
182 r.distance_f_ = me->paper_l ()->get_var ("tie_x_minimum");
184 return SCM_UNDEFINED;
192 MAKE_SCHEME_CALLBACK(Tie,brew_molecule);
194 Tie::brew_molecule (SCM smob)
196 Score_element*me = unsmob_element (smob);
197 Real thick = me->paper_l ()->get_var ("tie_thickness");
198 Bezier one = dynamic_cast<Tie*> (me)->get_curve ();
201 SCM d = me->get_elt_property ("dashed");
203 a = me->lookup_l ()->dashed_slur (one, thick, gh_scm2int (d));
205 a = me->lookup_l ()->slur (one, Directional_element_interface (me).get () * thick, thick);
207 return a.create_scheme();
213 Tie::get_curve () const
215 Score_element*me = (Score_element*)this;
216 Direction d (Directional_element_interface (me).get ());
217 Bezier_bow b (get_encompass_offset_arr (), d);
219 Real staff_space = Staff_symbol_referencer::staff_space (me);
220 Real h_inf = paper_l ()->get_var ("tie_height_limit_factor") * staff_space;
221 Real r_0 = paper_l ()->get_var ("tie_ratio");
223 b.set_default_bezier (h_inf, r_0);
224 Bezier c = b.get_bezier ();
227 Avoid colliding of the horizontal part with stafflines.
229 should do me for slurs as well.
232 Array<Real> horizontal (c.solve_derivative (Offset (1,0)));
235 if (horizontal.size ())
238 ugh. Doesnt work for non-horizontal curves.
240 Real y = c.curve_point (horizontal[0])[Y_AXIS];
242 Real ry = rint (y/staff_space) * staff_space;
246 && fabs (diff) < paper_l ()->get_var ("tie_staffline_clearance"))
248 newy = ry - 0.5 * staff_space * sign (diff) ;
251 Real y0 = c.control_ [0][Y_AXIS];
252 c.control_[2][Y_AXIS] =
253 c.control_[1][Y_AXIS] =
254 (c.control_[1][Y_AXIS] - y0) * ((newy - y0) / (y - y0)) + y0;
257 programming_error ("Tie is nowhere horizontal");
262 Tie::get_encompass_offset_arr () const
264 Array<Offset> offset_arr;
265 offset_arr.push (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]));
266 offset_arr.push (Offset (spanner_length () + dx_f_drul_[RIGHT],