Stencil
Stem::flag (Grob *me)
{
- /* TODO: maybe property stroke-style should take different values,
- e.g. "" (i.e. no stroke), "single" and "double" (currently, it's
- '() or "grace"). */
+ int log = duration_log (me);
+ if (log < 3
+ || unsmob_grob (me->get_object ("beam")))
+ return Stencil ();
+
+ /*
+ TODO: maybe property stroke-style should take different values,
+ e.g. "" (i.e. no stroke), "single" and "double" (currently, it's
+ '() or "grace"). */
String flag_style;
SCM flag_style_scm = me->get_property ("flag-style");
char dir = (get_direction (me) == UP) ? 'u' : 'd';
String font_char = flag_style
- + to_string (dir) + staffline_offs + to_string (duration_log (me));
+ + to_string (dir) + staffline_offs + to_string (log);
Font_metric *fm = Font_interface::get_default_font (me);
Stencil flag = fm->find_by_name ("flags." + font_char);
if (flag.is_empty ())
Stencil ss = Lookup::round_filled_box (b, blot);
mol.add_stencil (ss);
- if (!get_beam (me) && abs (duration_log (me)) > 2)
+ mol.add_stencil (get_translated_flag (me));
+
+ return mol.smobbed_copy ();
+}
+
+Stencil
+Stem::get_translated_flag (Grob *me)
+{
+ Stencil fl = flag (me);
+ if (!fl.is_empty ())
{
- Stencil fl = flag (me);
- fl.translate_axis (stem_y[d] * half_space - d * blot / 2, Y_AXIS);
+ Direction d = get_direction (me);
+ Real blot
+ = me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter"));
+ Real stem_width = thickness (me);
+ Real half_space = Staff_symbol_referencer::staff_space (me) * 0.5;
+ Real y2 = stem_end_position (me);
+ fl.translate_axis (y2 * half_space - d * blot / 2, Y_AXIS);
fl.translate_axis (stem_width / 2, X_AXIS);
- mol.add_stencil (fl);
}
-
- return mol.smobbed_copy ();
+ return fl;
}
+
/*
move the stem to right of the notehead if it is up.
*/
}
}
-/*
- TODO: we should also use thickness for computing the clearance
- between head and tie. Very thick ties will now touch the note head.
-*/
-SCM
-Tie::get_control_points (SCM smob)
-{
- Spanner *me = unsmob_spanner (smob);
- Direction headdir = CENTER;
- if (head (me, LEFT))
- headdir = LEFT;
- else if (head (me, RIGHT))
- headdir = RIGHT;
- else
- {
- programming_error ("tie without heads");
- me->suicide ();
- return SCM_EOL;
- }
-
- set_direction (me);
-
- Direction dir = get_grob_direction (me);
-
- Real staff_space = Staff_symbol_referencer::staff_space (me);
-
- Real x_gap_f = robust_scm2double (me->get_property ("x-gap"), 0);
-
- Grob *l = me->get_bound (LEFT);
- Grob *r = me->get_bound (RIGHT);
-
- Grob *commonx = me->common_refpoint (l, X_AXIS);
- commonx = me->common_refpoint (r, X_AXIS);
-
- Real left_x;
-
- /*
- the tie has to be long enough to be visible, but should not go
- through key sigs. In the 1.5 series the pref.matter - note
- distance is fixed , so this won't be a problem anymore.
- */
- Real lambda = 0.9;
-
- if (Note_head::has_interface (l))
- {
- Real where = RIGHT;
-
- /*
- This correction is due te the shape of the black note head.
- */
- if (Rhythmic_head::duration_log (l) == 2)
- where += dir * 0.2;
- left_x = l->extent (l, X_AXIS).linear_combination (where)
- + x_gap_f;
- }
- else
- left_x = l->extent (l, X_AXIS).linear_combination (lambda);
-
- Real width;
- if (Note_head::has_interface (l) && Note_head::has_interface (r))
- {
- width
- = + r->extent (commonx, X_AXIS)[LEFT]
- - l->extent (commonx, X_AXIS)[RIGHT]
- -2 * x_gap_f;
- }
- else
- {
- if (Note_head::has_interface (l))
- width = r->relative_coordinate (commonx, X_AXIS)
- - l->extent (commonx, X_AXIS)[RIGHT]
- - 2 * x_gap_f;
- else
- width
- = -l->extent (commonx, X_AXIS).linear_combination (lambda)
- + r->extent (commonx, X_AXIS)[LEFT]
- - 2 * x_gap_f;
- }
-
- SCM details = me->get_property ("details");
-
- SCM lim // groetjes aan de chirurgendochter.
- = scm_assq (ly_symbol2scm ("height-limit"), details);
-
- Real h_inf = scm_to_double (scm_cdr (lim)) * staff_space;
- Real r_0 = scm_to_double (scm_cdr (scm_assq (ly_symbol2scm ("ratio"), details)));
-
- Bezier b = slur_shape (width, h_inf, r_0);
-
- /*
- I think this better, particularly for small ties. It always allows
- the user to move ties if they seem in the wrong place
-
- TODO: what if 2 heads have different size.
-
- */
-
- Real ypos = Tie::get_position (me) * staff_space / 2
- + dir * scm_to_double (me->get_property ("y-offset"));;
-
- /*
- Make sure we don't start on a dots
- */
- if (Note_head::has_interface (l) && Rhythmic_head::get_dots (l))
- {
- Grob *dots = Rhythmic_head::get_dots (l);
- if (fabs (staff_space * Staff_symbol_referencer::get_position (dots) / 2
- - ypos) < 0.5)
- ypos += 0.5 * dir;
- }
-
- /*
- todo: prevent ending / staffline collision.
-
- todo: tie / stem collision
- */
-
- b = slur_shape (width, h_inf, r_0);
- b.scale (1, dir);
- b.translate (Offset (left_x, ypos));
-
- /*
- Avoid colliding of the horizontal part with stafflines.
-
-
- TODO: redo this, heuristic is half-baken, and ties often look ugly
- as a result.
-
- TODO: doesn't work when on staff with even number of lines.
- */
- Array<Real> horizontal (b.solve_derivative (Offset (1, 0)));
- if (horizontal.size ())
- {
- /*
- ugh. Doesnt work for non-horizontal curves.
- */
- Real y = b.curve_point (horizontal[0])[Y_AXIS];
-
- Real ry = rint (y / staff_space) * staff_space;
- Real diff = ry - y;
- Real newy = y;
-
- Real clear = staff_space * scm_to_double (me->get_property ("staffline-clearance"));
-
- if (fabs (y)
- <= Staff_symbol_referencer::staff_radius (me) * staff_space + clear
- && fabs (diff) < clear)
- {
- Real y1 = ry + clear;
- Real y2 = ry - clear;
-
- /*
- ugh, we shove the 0.5 out of our sleeves.
-
- Any way. This test is to make sure that staffline
- collision avoidance does not result in completely flat
- ties.
- */
- if (fabs (y1 - ypos) < 0.5)
- y1 = y2;
- else if (fabs (y2 - ypos) < 0.5)
- y2 = y1;
-
- newy = (fabs (y1 - y) < fabs (y2 - y)) ? y1 : y2;
-
- // newy = ry - 0.5 * staff_space * sign (diff) ;
-
- /*
- we don't want horizontal ties
- */
- if (fabs (newy - b.control_[0][Y_AXIS]) < 1e-2)
- newy = newy + dir * staff_space;
- }
-
- Real y0 = b.control_ [0][Y_AXIS];
- b.control_[2][Y_AXIS]
- = b.control_[1][Y_AXIS]
- = (b.control_[1][Y_AXIS] - y0) * ((newy - y0) / (y - y0)) + y0;
- }
- else
- programming_error ("tie is nowhere horizontal");
-
- SCM controls = SCM_EOL;
- for (int i = 4; i--;)
- controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
- return controls;
-}
-
MAKE_SCHEME_CALLBACK (Tie, print, 1);
SCM
Tie::print (SCM smob)