/*
This file is part of LilyPond, the GNU music typesetter.
- Copyright (C) 1996--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ Copyright (C) 1996--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
TODO: This is way too hairy
SCM lst = index_get_cell (pair, d);
- int len = scm_ilength (lst);
+ int len = scm_ilength (lst); // -1 for dotted lists!
return max (len, 0);
}
Real
Stem::chord_start_y (Grob *me)
{
- Interval hp = head_positions (me);
- if (!hp.is_empty ())
- return hp[get_grob_direction (me)] * Staff_symbol_referencer::staff_space (me)
- * 0.5;
+ if (head_count (me))
+ return Staff_symbol_referencer::get_position (last_head (me))
+ * Staff_symbol_referencer::staff_space (me) * 0.5;
+
return 0;
}
// todo: margins
Direction d = get_grob_direction (me);
- Grob *beam = unsmob_grob (me->get_object ("beam"));
+ Grob *beam = unsmob<Grob> (me->get_object ("beam"));
if (d && d * head_positions (me)[get_grob_direction (me)] >= se * d)
me->warning (_ ("weird stem size, check for narrow beams"));
- Interval height = me->pure_height (me, 0, INT_MAX);
+ // trigger note collision mechanisms
+ Real stem_beg = internal_calc_stem_begin_position (me, false);
Real staff_space = Staff_symbol_referencer::staff_space (me);
Real half_space = staff_space * 0.5;
+ Interval height;
+ height[-d] = stem_beg * half_space;
height[d] = se * half_space + beam_end_corrective (me);
Real stemlet_length = robust_scm2double (me->get_property ("stemlet-length"),
Grob *n = heads[i];
int p = Staff_symbol_referencer::get_rounded_position (n);
- Direction d = LEFT;
- do
+ for (LEFT_and_RIGHT (d))
{
if (d * p > d * extpos[d])
{
extpos[d] = p;
}
}
- while (flip (&d) != DOWN);
}
return exthead;
}
-/* The positions, in ascending order. */
+/* The staff positions, in ascending order.
+ * If FILTER, include the main column of noteheads only */
vector<int>
-Stem::note_head_positions (Grob *me)
+Stem::note_head_positions (Grob *me, bool filter)
{
vector<int> ps;
extract_grob_set (me, "note-heads", heads);
+ Grob *xref = common_refpoint_of_array (heads, me, X_AXIS);
for (vsize i = heads.size (); i--;)
{
Grob *n = heads[i];
- int p = Staff_symbol_referencer::get_rounded_position (n);
+ if (filter
+ && n->relative_coordinate (xref, X_AXIS) != 0.0)
+ continue;
+ int p = Staff_symbol_referencer::get_rounded_position (n);
ps.push_back (p);
}
{
n->set_object ("stem", me->self_scm ());
- if (Note_head::has_interface (n))
+ if (has_interface<Note_head> (n))
Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"), n);
- else if (Rest::has_interface (n))
+ else if (has_interface<Rest> (n))
Pointer_group_interface::add_grob (me, ly_symbol2scm ("rests"), n);
}
bool
Stem::is_invisible (Grob *me)
{
- return !is_normal_stem (me)
- && (robust_scm2double (me->get_property ("stemlet-length"),
- 0.0) == 0.0);
+ if (is_normal_stem (me))
+ return false;
+ else if (head_count (me))
+ return true;
+ else // if there are no note-heads, we might want stemlets
+ return 0.0 == robust_scm2double (me->get_property ("stemlet-length"), 0.0);
}
bool
Stem::is_normal_stem (Grob *me)
{
- return head_count (me) && scm_to_int (me->get_property ("duration-log")) >= 1;
+ if (!head_count (me))
+ return false;
+
+ return scm_to_int (me->get_property ("duration-log")) >= 1;
}
MAKE_SCHEME_CALLBACK (Stem, pure_height, 3)
SCM /* start */,
SCM /* end */)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
return ly_interval2scm (internal_pure_height (me, true));
}
if (!is_normal_stem (me))
return Interval (0.0, 0.0);
- Grob *beam = unsmob_grob (me->get_object ("beam"));
+ Grob *beam = unsmob<Grob> (me->get_object ("beam"));
Interval iv = internal_height (me, false);
if (!beam)
return iv;
- if (!to_boolean (me->get_property ("cross-staff")) && calc_beam)
+ if (calc_beam)
{
Interval overshoot;
Direction dir = get_grob_direction (me);
- Direction d = DOWN;
- do
+ for (DOWN_and_UP (d))
overshoot[d] = d == dir ? dir * infinity_f : iv[d];
- while (flip (&d) != DOWN);
vector<Interval> heights;
vector<Grob *> my_stems;
extract_grob_set (beam, "normal-stems", normal_stems);
for (vsize i = 0; i < normal_stems.size (); i++)
- if (normal_stems[i] != me && get_grob_direction (normal_stems[i]) == dir)
+ if (get_grob_direction (normal_stems[i]) == dir)
{
- heights.push_back (Stem::internal_pure_height (normal_stems[i], false));
+ if (normal_stems[i] != me)
+ heights.push_back (Stem::internal_pure_height (normal_stems[i], false));
+ else
+ heights.push_back (iv);
my_stems.push_back (normal_stems[i]);
- iv.unite (heights.back ());
}
+ //iv.unite (heights.back ());
+ // look for cross staff effects
+ vector<Real> coords;
+ Grob *common = common_refpoint_of_array (my_stems, me, Y_AXIS);
+ Real min_pos = infinity_f;
+ Real max_pos = -infinity_f;
+ for (vsize i = 0; i < my_stems.size (); i++)
+ {
+ coords.push_back (my_stems[i]->pure_relative_y_coordinate (common, 0, INT_MAX));
+ min_pos = min (min_pos, coords[i]);
+ max_pos = max (max_pos, coords[i]);
+ }
+ for (vsize i = 0; i < heights.size (); i++)
+ {
+ heights[i][dir] += dir == DOWN
+ ? coords[i] - max_pos
+ : coords[i] - min_pos;
+ }
+
+ for (vsize i = 0; i < heights.size (); i++) iv.unite (heights[i]);
+
for (vsize i = 0; i < my_stems.size (); i++)
cache_pure_height (my_stems[i], iv, heights[i]);
iv.intersect (overshoot);
{
Interval overshoot;
Direction dir = get_grob_direction (me);
- Direction d = DOWN;
- do
+ for (DOWN_and_UP (d))
overshoot[d] = d == dir ? dir * infinity_f : my_iv[d];
- while (flip (&d) != DOWN);
iv.intersect (overshoot);
dynamic_cast<Item *> (me)->cache_pure_height (iv);
SCM
Stem::calc_stem_end_position (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
return scm_from_double (internal_calc_stem_end_position (me, true));
}
SCM, /* start */
SCM /* end */)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
return scm_from_double (internal_calc_stem_end_position (me, false));
}
length *= robust_scm2double (me->get_property ("length-fraction"), 1.0);
/* Tremolo stuff. */
- Grob *t_flag = unsmob_grob (me->get_object ("tremolo-flag"));
- if (t_flag && (!unsmob_grob (me->get_object ("beam")) || !calc_beam))
+ Grob *t_flag = unsmob<Grob> (me->get_object ("tremolo-flag"));
+ if (t_flag && (!unsmob<Grob> (me->get_object ("beam")) || !calc_beam))
{
/* Crude hack: add extra space if tremolo flag is there.
SCM
Stem::calc_positioning_done (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
if (!head_count (me))
return SCM_BOOL_T;
bool is_harmonic_centered = false;
for (vsize i = 0; i < heads.size (); i++)
is_harmonic_centered = is_harmonic_centered
- || heads[i]->get_property ("style") == ly_symbol2scm ("harmonic");
+ || scm_is_eq (heads[i]->get_property ("style"),
+ ly_symbol2scm ("harmonic"));
is_harmonic_centered = is_harmonic_centered && is_invisible (me);
Real w = hed->extent (hed, X_AXIS)[dir];
= hed->extent (hed, X_AXIS).linear_combination (CENTER)
- heads[i]->extent (heads[i], X_AXIS).linear_combination (CENTER);
- heads[i]->translate_axis (amount, X_AXIS);
+ if (!isnan (amount)) // empty heads can produce NaN
+ heads[i]->translate_axis (amount, X_AXIS);
}
bool parity = true;
Real lastpos = Real (Staff_symbol_referencer::get_position (heads[0]));
+ int threshold = robust_scm2int (me->get_property ("note-collision-threshold"), 1);
for (vsize i = 1; i < heads.size (); i++)
{
Real p = Staff_symbol_referencer::get_position (heads[i]);
dy should always be 0.5, 0.0, 1.0, but provide safety margin
for rounding errors.
*/
- if (dy < 1.1)
+ if (dy < 0.1 + threshold)
{
if (parity)
{
stem 100% whereas reversed heads only overlaps the
stem 50%
*/
-
Real reverse_overlap = 0.5;
- heads[i]->translate_axis ((ell - thick * reverse_overlap) * d,
- X_AXIS);
+
+ /*
+ However, the first reverse head has to be shifted even
+ more than the full reverse overlap if it is the same
+ height as the first head or there will be a gap
+ because of the head slant (issue 346).
+ */
+
+ if (i == 1 && dy < 0.1)
+ reverse_overlap = 1.1;
if (is_invisible (me))
- heads[i]->translate_axis (-thick * (2 - reverse_overlap) * d,
- X_AXIS);
+ {
+ // Semibreves and longer are tucked in considerably
+ // to be recognizable as chorded rather than
+ // parallel voices. During the course of issue 346
+ // there was a discussion to change this for unisons
+ // (dy < 0.1) to reduce overlap but without reaching
+ // agreement and with Gould being rather on the
+ // overlapping front.
+ reverse_overlap = 2;
+ }
+
+ heads[i]->translate_axis ((ell - thick * reverse_overlap) * d,
+ X_AXIS);
/* TODO:
SCM
Stem::calc_direction (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
Direction dir = CENTER;
- if (Grob *beam = unsmob_grob (me->get_object ("beam")))
+ if (Grob *beam = unsmob<Grob> (me->get_object ("beam")))
{
SCM ignore_me = beam->get_property ("direction");
(void) ignore_me;
SCM
Stem::calc_default_direction (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
Direction dir = CENTER;
int staff_center = 0;
- Interval hp = head_positions (me);
- if (!hp.is_empty ())
+ if (head_count (me))
{
+ Interval hp = head_positions (me);
int udistance = (int) (UP * hp[UP] - staff_center);
int ddistance = (int) (DOWN * hp[DOWN] - staff_center);
SCM
Stem::height (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
return ly_interval2scm (internal_height (me, true));
}
Real
Stem::beam_end_corrective (Grob *me)
{
- Grob *beam = unsmob_grob (me->get_object ("beam"));
+ Grob *beam = unsmob<Grob> (me->get_object ("beam"));
Direction dir = get_grob_direction (me);
if (beam)
{
Stem::internal_height (Grob *me, bool calc_beam)
{
Grob *beam = get_beam (me);
- if (!is_valid_stem (me) && ! beam)
+ if (!is_valid_stem (me) && !beam)
return Interval ();
Direction dir = get_grob_direction (me);
(void) beam->get_property ("quantized-positions");
}
+ /*
+ If there is a beam but no stem, slope calculations depend on this
+ routine to return where the stem end /would/ be.
+ */
+ if (calc_beam && !beam && !unsmob<Stencil> (me->get_property ("stencil")))
+ return Interval ();
+
Real y1 = robust_scm2double ((calc_beam
? me->get_property ("stem-begin-position")
: me->get_pure_property ("stem-begin-position", 0, INT_MAX)),
SCM
Stem::width (SCM e)
{
- Grob *me = unsmob_grob (e);
+ Grob *me = unsmob<Grob> (e);
Interval r;
SCM
Stem::calc_stem_begin_position (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
return scm_from_double (internal_calc_stem_begin_position (me, true));
}
SCM, /* start */
SCM /* end */)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
return scm_from_double (internal_calc_stem_begin_position (me, false));
}
Real y_attach = Note_head::stem_attachment_coordinate (head, Y_AXIS);
y_attach = head_height.linear_combination (y_attach);
- pos += d * y_attach * 2 / ss;
+ if (!isinf (y_attach) && !isnan (y_attach)) // empty heads
+ pos += d * y_attach * 2 / ss;
}
return pos;
}
+
+MAKE_SCHEME_CALLBACK (Stem, pure_calc_length, 3);
+SCM
+Stem::pure_calc_length (SCM smob, SCM /*start*/, SCM /*end*/)
+{
+ Grob *me = unsmob<Grob> (smob);
+ Real beg = robust_scm2double (me->get_pure_property ("stem-begin-position", 0, INT_MAX), 0.0);
+ Real res = fabs (internal_calc_stem_end_position (me, false) - beg);
+ return scm_from_double (res);
+}
+
+MAKE_SCHEME_CALLBACK (Stem, calc_length, 1);
+SCM
+Stem::calc_length (SCM smob)
+{
+ Grob *me = unsmob<Grob> (smob);
+ if (unsmob<Grob> (me->get_object ("beam")))
+ {
+ me->programming_error ("ly:stem::calc-length called but will not be used for beamed stem.");
+ return scm_from_double (0.0);
+ }
+
+ Real beg = robust_scm2double (me->get_property ("stem-begin-position"), 0.0);
+ Real res = fabs (internal_calc_stem_end_position (me, true) - beg);
+ return scm_from_double (res);
+}
+
bool
Stem::is_valid_stem (Grob *me)
{
/* TODO: make the stem start a direction ?
This is required to avoid stems passing in tablature chords. */
+ if (!me)
+ return false;
Grob *lh = get_reference_head (me);
- Grob *beam = unsmob_grob (me->get_object ("beam"));
+ Grob *beam = unsmob<Grob> (me->get_object ("beam"));
if (!lh && !beam)
return false;
- if (lh && robust_scm2int (lh->get_property ("duration-log"), 0) < 1)
- return false;
-
if (is_invisible (me))
return false;
SCM
Stem::print (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
if (!is_valid_stem (me))
return SCM_EOL;
SCM
Stem::offset_callback (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
extract_grob_set (me, "rests", rests);
if (rests.size ())
{
Grob *rest = rests.back ();
- Real r = rest->extent (rest, X_AXIS).center ();
+ Real r = robust_relative_extent (rest, rest, X_AXIS).center ();
return scm_from_double (r);
}
Direction d = get_grob_direction (me);
Real real_attach = head_wid.linear_combination (d * attach);
- Real r = real_attach;
+ Real r = isnan(real_attach)? 0.0: real_attach;
/* If not centered: correct for stem thickness. */
string style = robust_symbol2string (f->get_property ("style"), "default");
Stem::get_beam (Grob *me)
{
SCM b = me->get_object ("beam");
- return dynamic_cast<Spanner *> (unsmob_grob (b));
+ return unsmob<Spanner> (b);
}
Stem_info
SCM
Stem::calc_stem_info (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = unsmob<Grob> (smob);
Direction my_dir = get_grob_direction (me);
if (!my_dir)
: 0.0);
Real height_of_my_trem = 0.0;
- Grob *trem = unsmob_grob (me->get_object ("tremolo-flag"));
+ Grob *trem = unsmob<Grob> (me->get_object ("tremolo-flag"));
if (trem)
{
height_of_my_trem
bool
Stem::is_cross_staff (Grob *stem)
{
- Grob *beam = unsmob_grob (stem->get_object ("beam"));
+ Grob *beam = unsmob<Grob> (stem->get_object ("beam"));
return beam && Beam::is_cross_staff (beam);
}
SCM
Stem::calc_cross_staff (SCM smob)
{
- return scm_from_bool (is_cross_staff (unsmob_grob (smob)));
+ return scm_from_bool (is_cross_staff (unsmob<Grob> (smob)));
}
Grob *
Stem::flag (Grob *me)
{
- return unsmob_grob (me->get_object ("flag"));
+ return unsmob<Grob> (me->get_object ("flag"));
}
/* FIXME: Too many properties */
"default-direction "
"details "
"direction "
+ "double-stem-separation "
"duration-log "
"flag "
"french-beaming "
"neutral-direction "
"no-stem-extend "
"note-heads "
+ "note-collision-threshold "
"positioning-done "
"rests "
"stem-begin-position "
"stemlet-length "
"thickness "
"tremolo-flag "
+ "tuplet-start "
);
/****************************************************************/