source file of the GNU LilyPond music typesetter
- (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
-
*/
/*
}
+Real
+Beam::get_thickness (Grob * me)
+{
+ SCM th = me->get_grob_property ("thickness");
+ if (gh_number_p (th))
+ return gh_scm2double (th)* Staff_symbol_referencer::staff_space (me);
+ else
+ return 0.0;
+}
+
/* Return the translation between 2 adjoining beams. */
Real
Beam::get_beam_translation (Grob *me)
return m;
}
+
+/*
+ Space return space between beams.
+ */
MAKE_SCHEME_CALLBACK (Beam, space_function, 2);
SCM
Beam::space_function (SCM smob, SCM beam_count)
Real staff_space = Staff_symbol_referencer::staff_space (me);
Real line = me->get_paper ()->get_var ("linethickness");
- Real thickness = gh_scm2double (me->get_grob_property ("thickness"))
- * staff_space;
+ Real thickness = get_thickness (me);
Real beam_translation = gh_scm2int (beam_count) < 4
? (2*staff_space + line - thickness) / 2.0
SCM this_beaming = this_stem->get_grob_property ("beaming");
Direction this_dir = Directional_element_interface::get(this_stem);
- if (i > 0)
+ if (gh_pair_p (last_beaming) && gh_pair_p (this_beaming))
{
int start_point = position_with_maximal_common_beams
(last_beaming, this_beaming,
Real dy = pos.delta ();
Real dydx = dy && dx ? dy/dx : 0;
- Real thick = gh_scm2double (me->get_grob_property ("thickness"));
+ Real thick = get_thickness (me);
Real bdy = get_beam_translation (me);
SCM last_beaming = SCM_EOL;;
SCM gap = me->get_grob_property ("gap");
Molecule the_beam;
Real lt = me->get_paper ()->get_var ("linethickness");
+
for (int i = 0; i< stems.size(); i++)
{
Grob * st =stems[i];
Real xposn = st->relative_coordinate (xcommon, X_AXIS);
Real stem_width = gh_scm2double (st->get_grob_property ("thickness")) *lt;
+ /*
+ We do the space left of ST, with lfliebertjes pointing to the
+ right from the left stem, and rfliebertjes pointing left from
+ right stem.
+ */
if (i > 0)
{
SCM left = gh_cdr (last_beaming);
if (lfliebertjes.size() || rfliebertjes.size())
{
-
Real nw_f;
- if (!Stem::first_head (st))
- nw_f = 0;
- else
- {
- int t = Stem::duration_log (st);
- SCM proc = me->get_grob_property ("flag-width-function");
- SCM result = gh_call1 (proc, scm_int2num (t));
- nw_f = gh_scm2double (result);
- }
+ int t = Stem::duration_log (st);
+
+ SCM proc = me->get_grob_property ("flag-width-function");
+ SCM result = gh_call1 (proc, scm_int2num (t));
+ nw_f = gh_scm2double (result);
+
/* Half beam should be one note-width,
but let's make sure two half-beams never touch */
Molecule tm = Text_item::text2molecule (me, scm_makfrom0str (str.to_str0 ()), properties);
- the_beam.add_at_edge (Y_AXIS, UP, tm, 5.0);
+ the_beam.add_at_edge (Y_AXIS, UP, tm, 5.0, 0);
}
#endif
return SCM_UNSPECIFIED;
}
+
+/*
+ Compute a first approximation to the beam slope.
+ */
MAKE_SCHEME_CALLBACK (Beam, least_squares, 1);
SCM
Beam::least_squares (SCM smob)
concave *= dir;
concaveness2 = concave / (stems.size () - 2);
- /* ugh: this is the a kludge to get
- input/regression/beam-concave.ly to behave as
- baerenreiter. */
+ /*
+
+ ugh: this is the a kludge to get
+ input/regression/beam-concave.ly to behave as
+ baerenreiter.
+
+ */
/*
huh? we're dividing twice (which is not scalable) meaning that
&&gh_scm2double (me->get_grob_property ("gap")))
{
gap = true;
- thick = gh_scm2double (me->get_grob_property ("thickness"))
- * Staff_symbol_referencer::staff_space(me);
+ thick = get_thickness(me);
}
// ugh -> use commonx
if (Stem::invisible_b (s))
continue;
+
+ bool french = to_boolean (s->get_grob_property ("french-beaming"));
Real stem_y = calc_stem_y (me, s, common,
xl, xr,
pos, french && i > 0&& (i < stems.size () -1));
||(d == RIGHT && i == stems.size () -1))
continue;
-
- SCM beaming_prop = stems[i]->get_grob_property ("beaming");
+ Grob *st = stems[i];
+ SCM beaming_prop = st->get_grob_property ("beaming");
if (beaming_prop == SCM_EOL ||
index_get_cell (beaming_prop, d) == SCM_EOL)
{
int b = beaming->infos_.elem (i).beams_i_drul_[d];
- Stem::set_beaming (stems[i], b, d);
+ if (i>0
+ && i < stems.size() -1
+ && Stem::invisible_b (st))
+ b = b <? beaming->infos_.elem(i).beams_i_drul_[-d];
+
+ Stem::set_beaming (st, b, d);
}
}
while (flip (&d) != LEFT);
|| !Beam::visible_stem_count (beam))
return gh_double2scm (0.0);
- // make callback for rest from this.
- // todo: make sure this calced already.
-
- // Interval pos = ly_scm2interval (beam->get_grob_property ("positions"));
Interval pos (0, 0);
SCM s = beam->get_grob_property ("positions");
if (gh_pair_p (s) && gh_number_p (ly_car (s)))
Real dydx = dy && dx ? dy/dx : 0;
Direction d = Stem::get_direction (stem);
- Real beamy = (stem->relative_coordinate (0, X_AXIS) - x0) * dydx + pos[LEFT];
+ Real stem_y = (pos[LEFT]
+ + (stem->relative_coordinate (0, X_AXIS) - x0) * dydx)
+ * d;
+
+ Real beam_translation = get_beam_translation (beam);
+ Real beam_thickness = gh_scm2double (beam->get_grob_property ("thickness"));
+ int beam_count = get_direction_beam_count (beam, d);
+ Real height_of_my_beams = beam_thickness
+ + (beam_count - 1) * beam_translation;
+ Real beam_y = stem_y - height_of_my_beams + beam_thickness / 2.0;
Real staff_space = Staff_symbol_referencer::staff_space (rest);
-
- Real rest_dim = rest->extent (rest, Y_AXIS)[d]*2.0 / staff_space; // refp??
+ /* Better calculate relative-distance directly, rather than using
+ rest_dim? */
+ Grob *common_x = rest->common_refpoint (beam, Y_AXIS);
+ Real rest_dim = rest->extent (common_x, Y_AXIS)[d] / staff_space * d;
- Real minimum_dist
- = gh_scm2double (rest->get_grob_property ("minimum-beam-collision-distance"));
- Real dist =
- minimum_dist + -d * (beamy - rest_dim) >? 0;
+ Real minimum_distance = gh_scm2double
+ (rest->get_grob_property ("minimum-beam-collision-distance"));
+ Real distance = beam_y - rest_dim;
+ Real shift = 0;
+ if (distance < 0)
+ shift = minimum_distance - distance;
+ else if (minimum_distance > distance)
+ shift = minimum_distance - distance;
+
int stafflines = Staff_symbol_referencer::line_count (rest);
- // move discretely by half spaces.
- int discrete_dist = int (ceil (dist));
+ /* Always move discretely by half spaces */
+ Real discrete_shift = ceil (shift * 2.0) / 2.0;
- // move by whole spaces inside the staff.
- if (discrete_dist < stafflines+1)
- discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
+ /* Inside staff, move by whole spaces*/
+ if ((rest->extent (common_x, Y_AXIS)[d] + discrete_shift) * d
+ < stafflines / 2.0
+ ||(rest->extent (common_x, Y_AXIS)[-d] + discrete_shift) * -d
+ < stafflines / 2.0)
+ discrete_shift = ceil (discrete_shift);
- return gh_double2scm (-d * discrete_dist);
+ return gh_double2scm (-d * discrete_shift);
}
bool
ADD_INTERFACE (Beam, "beam-interface",
- "A beam.
-
-#'thickness= weight of beams, in staffspace
-
-
-We take the least squares line through the ideal-length stems, and
-then damp that using
-
- damped = tanh (slope)
-
-this gives an unquantized left and right position for the beam end.
-Then we take all combinations of quantings near these left and right
-positions, and give them a score (according to how close they are to
-the ideal slope, how close the result is to the ideal stems, etc.). We
-take the best scoring combination.
-
-",
- "french-beaming position-callbacks concaveness-gap concaveness-threshold dir-function quant-score auto-knee-gap gap chord-tremolo beamed-stem-shorten shorten least-squares-dy damping flag-width-function neutral-direction positions space-function thickness");
+ "A beam. \n\n"
+" "
+"#'thickness= weight of beams, in staffspace "
+" "
+" "
+"We take the least squares line through the ideal-length stems, and "
+"then damp that using "
+" \n"
+" damped = tanh (slope) \n"
+" \n"
+"this gives an unquantized left and right position for the beam end. "
+"Then we take all combinations of quantings near these left and right "
+"positions, and give them a score (according to how close they are to "
+"the ideal slope, how close the result is to the ideal stems, etc.). We "
+"take the best scoring combination. "
+,
+ "knee position-callbacks concaveness-gap concaveness-threshold dir-function quant-score auto-knee-gap gap chord-tremolo beamed-stem-shorten shorten least-squares-dy damping flag-width-function neutral-direction positions space-function thickness");