+/*
+ beam-quanting.cc -- implement Beam quanting functions
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ Jan Nieuwenhuizen <janneke@gnu.org>
+
+*/
+
+
+
#include <math.h>
#include "grob.hh"
static Real
-shrink_extra_weight (Real x)
+shrink_extra_weight (Real x, Real fac)
{
- return fabs (x) * ((x < 0) ? 1.5 : 1.0);
+ return fabs (x) * ((x < 0) ? fac : 1.0);
}
Real ss = Staff_symbol_referencer::staff_space (me);
Real thickness = gh_scm2double (me->get_grob_property ("thickness")) / ss;
- Real slt = me->paper_l ()->get_var ("linethickness") / ss;
+ Real slt = me->get_paper ()->get_var ("linethickness") / ss;
SCM sdy = me->get_grob_property ("least-squares-dy");
for (int i= 0; i < stems.size(); i++)
{
Grob*s = stems[i];
- stem_infos.push (Stem::calc_stem_info (s));
+ stem_infos.push (Stem::get_stem_info (s));
dirs_found[stem_infos.top ().dir_] = true;
bool f = french && i > 0&& (i < stems.size () -1);
*/
if (knee_b)
region_size += 2;
-
+
+ /*
+ Asymetry ? should run to <= region_size ?
+ */
for (int i = -region_size ; i < region_size; i++)
for (int j = 0; j < num_quants; j++)
{
qscores.push (qs);
}
- /*
- This is a longish function, but we don't separate this out into
- neat modular separate subfunctions, as the subfunctions would be
- called for many values of YL, YR. By precomputing various
- parameters outside of the loop, we can save a lot of time.
- */
-
+ /* This is a longish function, but we don't separate this out into
+ neat modular separate subfunctions, as the subfunctions would be
+ called for many values of YL, YR. By precomputing various
+ parameters outside of the loop, we can save a lot of time. */
for (int i = qscores.size (); i--;)
{
qscores[i].demerits
Real rad = Staff_symbol_referencer::staff_radius (me);
int beam_count = get_beam_count (me);
- Real beam_translation = beam_count < 4
- ? (2*ss + slt - thickness) / 2.0
- : (3*ss + slt - thickness) / 3.0;
+ Real beam_translation = get_beam_translation (me);
Real reasonable_score = (knee_b) ? 200000 : 100;
for (int i = qscores.size (); i--;)
beam_count, ldir, rdir);
}
-
+ ; /* silly gdb thinks best_idx is inside for loop. */
for (int i = qscores.size (); i--;)
if (qscores[i].demerits < reasonable_score)
{
qscores[i].yl, qscores[i].yr);
}
-
+ ; /* silly gdb thinks best_idx is inside for loop. */
int best_idx = best_quant_score_idx (qscores);
me->set_grob_property ("positions",
gh_cons (gh_double2scm (qscores[best_idx].yl),
// debug quanting
me->set_grob_property ("quant-score",
gh_double2scm (qscores[best_idx].demerits));
- me->set_grob_property ("best-idx", gh_int2scm (best_idx));
+ me->set_grob_property ("best-idx", scm_int2num (best_idx));
#endif
return SCM_UNSPECIFIED;
bool knee,
Real yl, Real yr)
{
- Real pen = STEM_LENGTH_LIMIT_PENALTY;
-
+ Real limit_penalty = STEM_LENGTH_LIMIT_PENALTY;
Drul_array<Real> score (0, 0);
Drul_array<int> count (0, 0);
+
for (int i=0; i < stems.size (); i++)
{
Grob* s = stems[i];
Real dx = xr-xl;
Real beam_y = yr *(x - xl)/dx + yl * ( xr - x)/dx;
Real current_y = beam_y + base_stem_ys[i];
+ Real length_pen = STEM_LENGTH_DEMERIT_FACTOR;
Stem_info info = stem_infos[i];
Direction d = info.dir_;
- score[d] += pen
- * (0 >? (d * (info.shortest_y_ - current_y)));
-
- Real ideal_score = shrink_extra_weight (d * current_y - d * info.ideal_y_);
+ score[d] += limit_penalty * (0 >? (d * (info.shortest_y_ - current_y)));
- /*
-
- we introduce a power, to make the scoring strictly
- convex. Otherwise a symmetric knee beam (up/down/up/down) does
- not have an optimum in the middle.
-
- */
+ Real ideal_diff = d * (current_y - info.ideal_y_);
+ Real ideal_score = shrink_extra_weight (ideal_diff, 1.5);
+
+ /* We introduce a power, to make the scoring strictly
+ convex. Otherwise a symmetric knee beam (up/down/up/down)
+ does not have an optimum in the middle. */
if (knee)
ideal_score = pow (ideal_score, 1.1);
- score[d] += STEM_LENGTH_DEMERIT_FACTOR * ideal_score;
+
+ score[d] += length_pen * ideal_score;
count[d] ++;
}
Real slope_penalty = IDEAL_SLOPE_FACTOR;
- /*
- Xstaff beams tend to use extreme slopes to get short stems. We
- put in a penalty here.
- */
+ /* Xstaff beams tend to use extreme slopes to get short stems. We
+ put in a penalty here. */
if (xstaff)
slope_penalty *= 10;
- dem += shrink_extra_weight (fabs (dy_damp) - fabs (dy))* slope_penalty;
+ /* Huh, why would a too steep beam be better than a too flat one ? */
+ dem += shrink_extra_weight (fabs (dy_damp) - fabs (dy), 1.5)
+ * slope_penalty;
return dem;
}
/*
Can't we simply compute the distance between the nearest
staffline and the secondary beam? That would get rid of the
- silly case analysis here (which is probably not when we have
- different beam-thicknesses.)
+ silly case analysis here (which is probably not valid when we
+ have different beam-thicknesses.)
--hwn
*/