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 "note-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<Note_head*> (unsmob_element (c));
52 Tie::position_f () const
55 ? staff_symbol_referencer (head (LEFT)).position_f ()
56 : staff_symbol_referencer (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 (sl).get () == UP
70 && sr && directional_element (sr).get () == UP)
77 Tie::do_add_processing()
79 if (!(head (LEFT) && head (RIGHT)))
80 warning (_ ("lonely tie"));
83 Drul_array<Note_head *> new_head_drul;
84 new_head_drul[LEFT] = head(LEFT);
85 new_head_drul[RIGHT] = head(RIGHT);
88 new_head_drul[d] = head((Direction)-d);
89 } while (flip(&d) != LEFT);
91 index_set_cell (get_elt_pointer ("heads"), LEFT, new_head_drul[LEFT]->self_scm_ );
92 index_set_cell (get_elt_pointer ("heads"), RIGHT, new_head_drul[RIGHT]->self_scm_ );
95 GLUE_SCORE_ELEMENT(Tie,after_line_breaking);
97 Tie::member_after_line_breaking ()
99 if (!head (LEFT) && !head (RIGHT))
101 programming_error ("Tie without heads.");
103 return SCM_UNDEFINED;
106 if (!directional_element (this).get ())
107 directional_element (this).set (get_default_dir ());
109 Real staff_space = staff_symbol_referencer (this).staff_space ();
110 Real half_space = staff_space / 2;
111 Real x_gap_f = paper_l ()->get_var ("tie_x_gap");
112 Real y_gap_f = paper_l ()->get_var ("tie_y_gap");
115 Slur and tie placement [OSU]
119 * x = inner vertical tangent - d * gap
125 OSU: not different for outer notes, so why all this code?
126 ie, can we drop this, or should it be made switchable.
129 dx_f_drul_[LEFT] = head (LEFT)->extent (X_AXIS).length ();
131 dx_f_drul_[LEFT] = get_broken_left_end_align ();
132 dx_f_drul_[LEFT] += x_gap_f;
133 dx_f_drul_[RIGHT] -= x_gap_f;
136 Slur and tie placement [OSU] -- check this
140 * y = dx < 5ss: horizontal tangent
141 y = dx >= 5ss: y next interline - d * 0.25 ss
143 which probably means that OSU assumes that
151 Real ypos = position_f ();
153 Real y_f = half_space * ypos;
154 int ypos_i = int (ypos);
156 Real dx_f = extent (X_AXIS).length () + dx_f_drul_[RIGHT] - dx_f_drul_[LEFT];
157 Direction dir = directional_element (this).get();
158 if (dx_f < paper_l ()->get_var ("tie_staffspace_length"))
160 if (abs (ypos_i) % 2)
161 y_f += dir * half_space;
162 y_f += dir * y_gap_f;
166 if (! (abs (ypos_i) % 2))
167 y_f += dir * half_space;
168 y_f += dir * half_space;
169 y_f -= dir * y_gap_f;
172 dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = y_f;
174 return SCM_UNDEFINED;
180 Tie::get_rods () const
185 r.item_l_drul_ [LEFT]=get_bound (LEFT);
186 r.item_l_drul_ [RIGHT]=get_bound (RIGHT);
188 r.distance_f_ = paper_l ()->get_var ("tie_x_minimum");
193 GLUE_SCORE_ELEMENT(Tie,brew_molecule);
196 Tie::member_brew_molecule () const
198 Real thick = paper_l ()->get_var ("tie_thickness");
199 Bezier one = get_curve ();
202 SCM d = get_elt_property ("dashed");
204 a = lookup_l ()->dashed_slur (one, thick, gh_scm2int (d));
206 a = lookup_l ()->slur (one, directional_element (this).get () * thick, thick);
208 return a.create_scheme();
214 Tie::get_curve () const
216 Direction d (directional_element (this).get ());
217 Bezier_bow b (get_encompass_offset_arr (), d);
219 Real staff_space = staff_symbol_referencer (this).staff_space ();
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 ();
226 /* should do this for slurs as well. */
227 Array<Real> horizontal (c.solve_derivative (Offset (1,0)));
229 if (horizontal.size ())
232 ugh. Doesnt work for non-horizontal curves.
234 Real y = c.curve_point (horizontal[0])[Y_AXIS];
236 Real ry = rint (y/staff_space) * staff_space;
240 && fabs (diff) < paper_l ()->get_var ("tie_staffline_clearance"))
242 newy = ry - 0.5 * staff_space * sign (diff) ;
245 Real y0 = c.control_ [0][Y_AXIS];
246 c.control_[2][Y_AXIS] =
247 c.control_[1][Y_AXIS] =
248 (c.control_[1][Y_AXIS] - y0) * ((newy - y0) / (y - y0)) + y0;
251 programming_error ("Tie is nowhere horizontal");
256 Tie::get_encompass_offset_arr () const
258 Array<Offset> offset_arr;
259 offset_arr.push (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]));
260 offset_arr.push (Offset (spanner_length () + dx_f_drul_[RIGHT],