SCM
Beam::calc_normal_stems (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = Grob::unsmob (smob);
extract_grob_set (me, "stems", stems);
SCM val = Grob_array::make_array ();
- Grob_array *ga = unsmob_grob_array (val);
+ Grob_array *ga = Grob_array::unsmob (val);
for (vsize i = 0; i < stems.size (); i++)
if (Stem::is_normal_stem (stems[i]))
ga->add (stems[i]);
SCM
Beam::calc_direction (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = Grob::unsmob (smob);
/* Beams with less than 2 two stems don't make much sense, but could happen
when you do
SCM
Beam::calc_beaming (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = Grob::unsmob (smob);
extract_grob_set (me, "stems", stems);
{
/* ugh, this has a side-effect that we need to ensure that
Stem #'beaming is correct */
- Grob *me_grob = unsmob_grob (smob);
+ Grob *me_grob = Grob::unsmob (smob);
(void) me_grob->get_property ("beaming");
Spanner *me = dynamic_cast<Spanner *> (me_grob);
SCM
Beam::calc_x_positions (SCM smob)
{
- Spanner *me = unsmob_spanner (smob);
+ Spanner *me = Spanner::unsmob (smob);
SCM segments = me->get_property ("beam-segments");
Interval x_positions;
x_positions.set_empty ();
SCM
Beam::print (SCM grob)
{
- Spanner *me = unsmob_spanner (grob);
+ Spanner *me = Spanner::unsmob (grob);
/*
TODO - mild code dup for all the commonx calls.
Some use just common_refpoint_of_array, some (in print and
Direction stem_dir = stems.size () ? to_dir (stems[0]->get_property ("direction")) : UP;
- Stencil score = *unsmob_stencil (Text_interface::interpret_markup
+ Stencil score = *Stencil::unsmob (Text_interface::interpret_markup
(me->layout ()->self_scm (), properties, annotation));
if (!score.is_empty ())
SCM
Beam::calc_stem_shorten (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = Grob::unsmob (smob);
/*
shortening looks silly for x staff beams
SCM
Beam::quanting (SCM smob, SCM ys_scm, SCM align_broken_intos)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = Grob::unsmob (smob);
Drul_array<Real> ys = robust_scm2drul (ys_scm, Drul_array<Real> (infinity_f, -infinity_f));
bool cbs = to_boolean (align_broken_intos);
SCM
Beam::set_stem_lengths (SCM smob)
{
- Grob *me = unsmob_grob (smob);
+ Grob *me = Grob::unsmob (smob);
/* trigger callbacks. */
(void) me->get_property ("direction");
SCM
Beam::rest_collision_callback (SCM smob, SCM prev_offset)
{
- Grob *rest = unsmob_grob (smob);
+ Grob *rest = Grob::unsmob (smob);
if (scm_is_number (rest->get_property ("staff-position")))
return scm_from_int (0);
Real offset = robust_scm2double (prev_offset, 0.0);
- Grob *st = unsmob_grob (rest->get_object ("stem"));
+ Grob *st = Grob::unsmob (rest->get_object ("stem"));
Grob *stem = st;
if (!stem)
return scm_from_double (0.0);
- Grob *beam = unsmob_grob (stem->get_object ("beam"));
+ Grob *beam = Grob::unsmob (stem->get_object ("beam"));
if (!beam
|| !Beam::has_interface (beam)
|| !Beam::normal_stem_count (beam))
/*
Estimate the position of a rest under a beam,
- as the average position of its neighboring heads.
+ using the average position of its neighboring heads.
*/
MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Beam, pure_rest_collision_callback, 4, 1, "");
SCM
{
Real previous = robust_scm2double (prev_offset, 0.0);
- Grob *me = unsmob_grob (smob);
- Grob *stem = unsmob_grob (me->get_object ("stem"));
+ Grob *me = Grob::unsmob (smob);
+ Grob *stem = Grob::unsmob (me->get_object ("stem"));
if (!stem)
return scm_from_double (previous);
- Grob *beam = unsmob_grob (stem->get_object ("beam"));
+ Grob *beam = Grob::unsmob (stem->get_object ("beam"));
if (!beam
|| !Beam::normal_stem_count (beam)
|| !is_direction (beam->get_property_data ("direction")))
Real ss = Staff_symbol_referencer::staff_space (me);
- /*
- This gives the extrema of rest positions.
- Even with noteheads on ledgers, beams typically remain within the staff,
- and push rests at most one staff-space (2 positions) from the staff.
- */
- Grob *staff = Staff_symbol_referencer::get_staff_symbol (me);
- Interval rest_max_pos = staff ? Staff_symbol::line_span (staff) : Interval (0.0, 0.0);
- rest_max_pos.widen (2);
-
extract_grob_set (beam, "stems", stems);
vector<Grob *> my_stems;
right = my_stems[idx + 1];
}
- /* In stems with several heads, use the one closest to the beam. */
+ /* Estimate the closest beam to be four positions away from the heads, */
Direction beamdir = get_grob_direction (beam);
- Real shift = min (max ( (Stem::head_positions (left)[beamdir]
- + Stem::head_positions (right)[beamdir]) / 2.0,
- rest_max_pos[DOWN]),
- rest_max_pos[UP]
- ) * ss / 2.0
- - previous;
-
- // So that ceil below kicks in for rests that would otherwise brush
- // up against a beam quanted to a ledger line, add a bit of space
- // between the beam and the rest.
- shift += (0.01 * beamdir);
-
- /* Always move by a whole number of staff spaces */
- shift = ceil (fabs (shift / ss)) * ss * sign (shift);
-
- return scm_from_double (previous + shift);
+ Real beam_pos = (Stem::head_positions (left)[beamdir]
+ + Stem::head_positions (right)[beamdir]) / 2.0
+ + 4.0 * beamdir; // four staff-positions
+ /* and that the closest beam never crosses staff center by more than two positions */
+ beam_pos = max (-2.0, beam_pos * beamdir) * beamdir;
+
+ Real minimum_distance
+ = ss * (robust_scm2double (stem->get_property ("stemlet-length"), 0.0)
+ + robust_scm2double (me->get_property ("minimum-distance"), 0.0));
+ Real offset = beam_pos * ss / 2.0
+ - minimum_distance * beamdir
+ - me->extent (me, Y_AXIS)[beamdir];
+
+ /* Always move by a whole number of staff spaces, always away from the beam */
+ offset = floor (min (0.0, (offset - previous) / ss * beamdir))
+ * ss * beamdir + previous;
+
+ return scm_from_double (offset);
}
bool
SCM
Beam::calc_cross_staff (SCM smob)
{
- return scm_from_bool (is_cross_staff (unsmob_grob (smob)));
+ return scm_from_bool (is_cross_staff (Grob::unsmob (smob)));
}
int