source file of the GNU LilyPond music typesetter
- (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
+#include <math.h>
+#include "lookup.hh"
#include "paper-def.hh"
#include "tie.hh"
#include "note-head.hh"
+#include "bezier.hh"
#include "paper-column.hh"
#include "debug.hh"
#include "staff-symbol-referencer.hh"
+#include "directional-element-interface.hh"
+#include "molecule.hh"
+#include "bezier-bow.hh"
+#include "stem.hh"
void
-Tie::set_head (Direction d, Note_head * head_l)
+Tie::set_head (Direction d, Item * head_l)
{
assert (!head (d));
- if (d == LEFT)
- gh_set_car_x (get_elt_property ("heads"), head_l->self_scm_ );
- else if (d == RIGHT)
- gh_set_cdr_x (get_elt_property ("heads"), head_l->self_scm_ );
+ index_set_cell (get_elt_property ("heads"), d, head_l->self_scm_);
set_bounds (d, head_l);
-
add_dependency (head_l);
}
Tie::Tie()
{
set_elt_property ("heads", gh_cons (SCM_EOL, SCM_EOL));
+ dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = 0.0;
+ dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0;
+
}
Note_head*
return dynamic_cast<Note_head*> (unsmob_element (c));
}
+Real
+Tie::position_f () const
+{
+ return head (LEFT)
+ ? staff_symbol_referencer (head (LEFT)).position_f ()
+ : staff_symbol_referencer (head (RIGHT)).position_f () ;
+}
+
/*
ugh: direction of the Tie is more complicated. See [Ross] p136 and further
Direction
Tie::get_default_dir () const
{
- Real p1 = Staff_symbol_referencer_interface (head (LEFT)).position_f () ;
- Real p2 = Staff_symbol_referencer_interface (head (RIGHT)).position_f () ;
-
- int m = int (p1 + p2);
+ Stem * sl = head(LEFT) ? head (LEFT)->stem_l () :0;
+ Stem * sr = head(RIGHT) ? head (RIGHT)->stem_l () :0;
- /*
- If dir is not determined: inverse of stem: down
- (see stem::get_default_dir ())
- */
- Direction neutral_dir = (Direction)(int)paper_l ()->get_var ("stem_default_neutral_direction");
- return (m == 0) ? other_dir (neutral_dir) : (m < 0) ? DOWN : UP;
+ if (sl && directional_element (sl).get () == UP
+ && sr && directional_element (sr).get () == UP)
+ return DOWN;
+ else
+ return UP;
}
void
new_head_drul[d] = head((Direction)-d);
} while (flip(&d) != LEFT);
- gh_set_car_x (get_elt_property ("heads"), new_head_drul[LEFT]->self_scm_ );
- gh_set_cdr_x (get_elt_property ("heads"), new_head_drul[RIGHT]->self_scm_ );
+ index_set_cell (get_elt_property ("heads"), LEFT, new_head_drul[LEFT]->self_scm_ );
+ index_set_cell (get_elt_property ("heads"), RIGHT, new_head_drul[RIGHT]->self_scm_ );
}
void
return;
}
- Real interline_f = paper_l ()->get_var ("interline");
- Real internote_f = interline_f / 2;
+ if (!directional_element (this).get ())
+ directional_element (this).set (get_default_dir ());
+
+ Real staff_space = staff_symbol_referencer (this).staff_space ();
+ Real half_space = staff_space / 2;
Real x_gap_f = paper_l ()->get_var ("tie_x_gap");
Real y_gap_f = paper_l ()->get_var ("tie_y_gap");
OSU: not different for outer notes, so why all this code?
ie, can we drop this, or should it be made switchable.
*/
-#if 0
- Direction d = LEFT;
- do
- {
- Real head_width_f = head (d)
- ? head (d)->extent (X_AXIS).length ()
- : 0;
- /*
- side attached to outer (upper or lower) notehead of chord
- */
- if (head (d)
- /*
-
- a~a~a;
-
- to second tie, middle notehead seems not extremal
-
- Getting scared a bit by score-element's comment:
- // is this a good idea?
- */
- && (head (d)->get_elt_property ("extremal")
- != SCM_UNDEFINED))
- {
- if (d == LEFT)
- dx_f_drul_[d] += head_width_f;
- dx_f_drul_[d] += -d * x_gap_f;
- }
- /*
- side attached to inner notehead
- */
- else
- {
- dx_f_drul_[d] += -d * head_width_f;
- }
- } while (flip (&d) != LEFT);
-
-#else
-
if (head (LEFT))
dx_f_drul_[LEFT] = head (LEFT)->extent (X_AXIS).length ();
else
dx_f_drul_[LEFT] += x_gap_f;
dx_f_drul_[RIGHT] -= x_gap_f;
-#endif
-
/*
Slur and tie placement [OSU] -- check this
*/
- Real ypos = head (LEFT)
- ? Staff_symbol_referencer_interface (head (LEFT)).position_f ()
- : Staff_symbol_referencer_interface (head (RIGHT)).position_f () ;
+ Real ypos = position_f ();
- Real y_f = internote_f * ypos;
+ Real y_f = half_space * ypos;
int ypos_i = int (ypos);
Real dx_f = extent (X_AXIS).length () + dx_f_drul_[RIGHT] - dx_f_drul_[LEFT];
+ Direction dir = directional_element (this).get();
if (dx_f < paper_l ()->get_var ("tie_staffspace_length"))
{
if (abs (ypos_i) % 2)
- y_f += get_direction () * internote_f;
- y_f += get_direction () * y_gap_f;
+ y_f += dir * half_space;
+ y_f += dir * y_gap_f;
}
else
{
if (! (abs (ypos_i) % 2))
- y_f += get_direction () * internote_f;
- y_f += get_direction () * internote_f;
- y_f -= get_direction () * y_gap_f;
+ y_f += dir * half_space;
+ y_f += dir * half_space;
+ y_f -= dir * y_gap_f;
}
dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = y_f;
return a;
}
+
+
+
+Molecule
+Tie::do_brew_molecule () const
+{
+ Real thick = paper_l ()->get_var ("tie_thickness");
+ Bezier one = get_curve ();
+
+ Molecule a;
+ SCM d = get_elt_property ("dashed");
+ if (gh_number_p (d))
+ a = lookup_l ()->dashed_slur (one, thick, gh_scm2int (d));
+ else
+ a = lookup_l ()->slur (one, directional_element (this).get () * thick, thick);
+
+ return a;
+}
+
+
+
+Bezier
+Tie::get_curve () const
+{
+ Direction d (directional_element (this).get ());
+ Bezier_bow b (get_encompass_offset_arr (), d);
+
+ Real staff_space = staff_symbol_referencer (this).staff_space ();
+ Real h_inf = paper_l ()->get_var ("tie_height_limit_factor") * staff_space;
+ Real r_0 = paper_l ()->get_var ("tie_ratio");
+
+ b.set_default_bezier (h_inf, r_0);
+ Bezier c = b.get_bezier ();
+
+ /* should do this for slurs as well. */
+ Array<Real> horizontal (c.solve_derivative (Offset (1,0)));
+
+ if (horizontal.size ())
+ {
+ /*
+ ugh. Doesnt work for non-horizontal curves.
+ */
+ Real y = c.curve_point (horizontal[0])[Y_AXIS];
+
+ Real ry = rint (y/staff_space) * staff_space;
+ Real diff = ry - y;
+ Real newy = y;
+ if (fabs (y) <= 2.0
+ && fabs (diff) < paper_l ()->get_var ("tie_staffline_clearance"))
+ {
+ newy = ry - 0.5 * staff_space * sign (diff) ;
+ }
+
+ Real y0 = c.control_ [0][Y_AXIS];
+ c.control_[2][Y_AXIS] =
+ c.control_[1][Y_AXIS] =
+ (c.control_[1][Y_AXIS] - y0) * ((newy - y0) / (y - y0)) + y0;
+ }
+ else
+ programming_error ("Tie is nowhere horizontal");
+ return c;
+}
+
+Array<Offset>
+Tie::get_encompass_offset_arr () const
+{
+ Array<Offset> offset_arr;
+ offset_arr.push (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]));
+ offset_arr.push (Offset (spanner_length () + dx_f_drul_[RIGHT],
+ dy_f_drul_[RIGHT]));
+
+ return offset_arr;
+}
+
+