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_pointer ("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_pointer ("heads", gh_cons (SCM_EOL, SCM_EOL));
46 Tie::head (Score_element*me, Direction d)
48 SCM c = me->get_elt_pointer ("heads");
49 c = index_cell (c, d);
51 return dynamic_cast<Rhythmic_head*> (unsmob_element (c));
55 Tie::position_f (Score_element*me)
58 ? Staff_symbol_referencer_interface (head (me,LEFT)).position_f ()
59 : Staff_symbol_referencer_interface (head (me,RIGHT)).position_f () ;
64 ugh: direction of the Tie is more complicated. See [Ross] p136 and further
67 Tie::get_default_dir (Score_element*me)
69 Stem * sl = head(me,LEFT) ? head (me,LEFT)->stem_l () :0;
70 Stem * sr = head(me,RIGHT) ? head (me,RIGHT)->stem_l () :0;
72 if (sl && Directional_element_interface (sl).get () == UP
73 && sr && Directional_element_interface (sr).get () == UP)
81 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Tie,after_line_breaking);
83 Tie::after_line_breaking (SCM smob)
85 Tie*me = dynamic_cast<Tie*> (unsmob_element (smob));
87 if (!head (me,LEFT) && !head (me,RIGHT))
89 programming_error ("Tie without heads.");
94 if (!Directional_element_interface (me).get ())
95 Directional_element_interface (me).set (Tie::get_default_dir (me));
97 Real staff_space = Staff_symbol_referencer_interface (me).staff_space ();
98 Real half_space = staff_space / 2;
99 Real x_gap_f = me->paper_l ()->get_var ("tie_x_gap");
100 Real y_gap_f = me->paper_l ()->get_var ("tie_y_gap");
103 Slur and tie placement [OSU]
107 * x = inner vertical tangent - d * gap
113 OSU: not different for outer notes, so why all me code?
114 ie, can we drop me, or should it be made switchable.
117 me->dx_f_drul_[LEFT] = Tie::head (me,LEFT)->extent (X_AXIS).length ();
119 me->dx_f_drul_[LEFT] = dynamic_cast<Spanner*>(me)->get_broken_left_end_align ();
120 me->dx_f_drul_[LEFT] += x_gap_f;
121 me->dx_f_drul_[RIGHT] -= x_gap_f;
124 Slur and tie placement [OSU] -- check me
128 * y = dx < 5ss: horizontal tangent
129 y = dx >= 5ss: y next interline - d * 0.25 ss
131 which probably means that OSU assumes that
139 Real ypos = Tie::position_f (me);
141 Real y_f = half_space * ypos;
142 int ypos_i = int (ypos);
144 Real dx_f = me->extent (X_AXIS).length () + me->dx_f_drul_[RIGHT] - me->dx_f_drul_[LEFT];
145 Direction dir = Directional_element_interface (me).get();
146 if (dx_f < me->paper_l ()->get_var ("tie_staffspace_length"))
148 if (abs (ypos_i) % 2)
149 y_f += dir * half_space;
150 y_f += dir * y_gap_f;
154 if (! (abs (ypos_i) % 2))
155 y_f += dir * half_space;
156 y_f += dir * half_space;
157 y_f -= dir * y_gap_f;
160 me->dy_f_drul_[LEFT] = me->dy_f_drul_[RIGHT] = y_f;
162 return SCM_UNDEFINED;
168 Tie::get_rods () const
173 r.item_l_drul_ [LEFT]=get_bound (LEFT);
174 r.item_l_drul_ [RIGHT]=get_bound (RIGHT);
176 r.distance_f_ = paper_l ()->get_var ("tie_x_minimum");
181 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Tie,brew_molecule);
184 Tie::brew_molecule (SCM smob)
186 Score_element*me = unsmob_element (smob);
187 Real thick = me->paper_l ()->get_var ("tie_thickness");
188 Bezier one = dynamic_cast<Tie*> (me)->get_curve ();
191 SCM d = me->get_elt_property ("dashed");
193 a = me->lookup_l ()->dashed_slur (one, thick, gh_scm2int (d));
195 a = me->lookup_l ()->slur (one, Directional_element_interface (me).get () * thick, thick);
197 return a.create_scheme();
203 Tie::get_curve () const
205 Score_element*me = (Score_element*)this;
206 Direction d (Directional_element_interface (me).get ());
207 Bezier_bow b (get_encompass_offset_arr (), d);
209 Real staff_space = Staff_symbol_referencer_interface (me).staff_space ();
210 Real h_inf = paper_l ()->get_var ("tie_height_limit_factor") * staff_space;
211 Real r_0 = paper_l ()->get_var ("tie_ratio");
213 b.set_default_bezier (h_inf, r_0);
214 Bezier c = b.get_bezier ();
216 /* should do me for slurs as well. */
217 Array<Real> horizontal (c.solve_derivative (Offset (1,0)));
219 if (horizontal.size ())
222 ugh. Doesnt work for non-horizontal curves.
224 Real y = c.curve_point (horizontal[0])[Y_AXIS];
226 Real ry = rint (y/staff_space) * staff_space;
230 && fabs (diff) < paper_l ()->get_var ("tie_staffline_clearance"))
232 newy = ry - 0.5 * staff_space * sign (diff) ;
235 Real y0 = c.control_ [0][Y_AXIS];
236 c.control_[2][Y_AXIS] =
237 c.control_[1][Y_AXIS] =
238 (c.control_[1][Y_AXIS] - y0) * ((newy - y0) / (y - y0)) + y0;
241 programming_error ("Tie is nowhere horizontal");
246 Tie::get_encompass_offset_arr () const
248 Array<Offset> offset_arr;
249 offset_arr.push (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]));
250 offset_arr.push (Offset (spanner_length () + dx_f_drul_[RIGHT],