source file of the GNU LilyPond music typesetter
- (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
*/
#include "beam.hh"
#include <algorithm>
-#include <math.h>
+using namespace std;
#include "warn.hh"
#include "staff-symbol-referencer.hh"
get_detail (SCM alist, SCM sym, Real def)
{
SCM entry = scm_assq (sym, alist);
-
+
if (scm_is_pair (entry))
- {
- return robust_scm2double (scm_cdr (entry), def);
- }
+ return robust_scm2double (scm_cdr (entry), def);
return def;
}
Beam_quant_parameters::fill (Grob *him)
{
SCM details = him->get_property ("details");
-
+
INTER_QUANT_PENALTY = get_detail (details, ly_symbol2scm ("inter-quant-penalty"), 1000.0);
SECONDARY_BEAM_DEMERIT = get_detail (details, ly_symbol2scm ("secondary-beam-demerit"), 10.0);
STEM_LENGTH_DEMERIT_FACTOR = get_detail (details, ly_symbol2scm ("stem-length-demerit-factor"), 5);
return best_idx;
}
-MAKE_SCHEME_CALLBACK (Beam, quanting, 1);
+MAKE_SCHEME_CALLBACK (Beam, quanting, 2);
SCM
-Beam::quanting (SCM smob)
+Beam::quanting (SCM smob, SCM posns)
{
Grob *me = unsmob_grob (smob);
-
Beam_quant_parameters parameters;
parameters.fill (me);
-
- SCM s = me->get_property ("positions");
- Real yl = scm_to_double (scm_car (s));
- Real yr = scm_to_double (scm_cdr (s));
+
+ Real yl = scm_to_double (scm_car (posns));
+ Real yr = scm_to_double (scm_cdr (posns));
/*
Calculations are relative to a unit-scaled staff, i.e. the quants are
bool is_knee = dirs_found[LEFT] && dirs_found[RIGHT];
int region_size = (int) parameters.REGION_SIZE;
-
+
/*
Knees are harder, lets try some more possibilities for knees.
*/
}
int best_idx = best_quant_score_idx (qscores);
-
+
#if DEBUG_QUANTING
SCM inspect_quants = me->get_property ("inspect-quants");
- if ( to_boolean (me->get_layout ()->lookup_variable (ly_symbol2scm ("debug-beam-quanting")))
+ if (to_boolean (me->layout ()->lookup_variable (ly_symbol2scm ("debug-beam-quanting")))
&& scm_is_pair (inspect_quants))
{
Drul_array<Real> ins = ly_scm2interval (inspect_quants);
programming_error ("can't find quant");
}
#endif
+
+ Interval final_positions;
if (best_idx < 0)
{
warning (_ ("no feasible beam position"));
- me->set_property ("positions", ly_interval2scm (Interval (0,0)));
+ final_positions = Interval (0, 0);
}
else
- me->set_property ("positions",
- ly_interval2scm (Drul_array<Real> (qscores[best_idx].yl,
- qscores[best_idx].yr)));
+ {
+ final_positions = Drul_array<Real> (qscores[best_idx].yl,
+ qscores[best_idx].yr);
+ }
+
#if DEBUG_QUANTING
if (best_idx >= 0
- && to_boolean (me->get_layout ()->lookup_variable (ly_symbol2scm ("debug-beam-quanting"))))
+ && to_boolean (me->layout ()->lookup_variable (ly_symbol2scm ("debug-beam-quanting"))))
{
qscores[best_idx].score_card_ += to_string ("i%d", best_idx);
}
#endif
- return SCM_UNSPECIFIED;
+ return ly_interval2scm (final_positions);
}
Real
bool knee,
Real yl, Real yr,
- Beam_quant_parameters const*parameters
- )
+ Beam_quant_parameters const *parameters)
{
Real limit_penalty = parameters->STEM_LENGTH_LIMIT_PENALTY;
Drul_array<Real> score (0, 0);
Stem_info info = stem_infos[i];
Direction d = info.dir_;
- score[d] += limit_penalty * max (0.0, (d * (info.shortest_y_ - current_y)));
+ score[d] += limit_penalty * max (0.0, (d * (info.shortest_y_ - current_y)));
Real ideal_diff = d * (current_y - info.ideal_y_);
Real ideal_score = shrink_extra_weight (ideal_diff, 1.5);
Direction d = DOWN;
do
- {
- score[d] /= max (count[d], 1);
- }
- while (flip (&d) != DOWN);
+ score[d] /= max (count[d], 1);
+ while (flip (&d) != DOWN)
+ ;
return score[LEFT] + score[RIGHT];
}
Real dy_mus, Real dy_damp,
Real dx,
bool xstaff,
-
- Beam_quant_parameters const*parameters)
+
+ Beam_quant_parameters const *parameters)
{
Real dy = yr - yl;
Real dem = 0.0;
*/
if (fabs (dy / dx) > parameters->ROUND_TO_ZERO_SLOPE
&& sign (dy_damp) != sign (dy))
- {
- dem += parameters->DAMPING_DIRECTION_PENALTY;
- }
+ dem += parameters->DAMPING_DIRECTION_PENALTY;
- dem += parameters->MUSICAL_DIRECTION_FACTOR * max (0.0, (fabs (dy) - fabs (dy_mus)));
+ dem += parameters->MUSICAL_DIRECTION_FACTOR
+ * max (0.0, (fabs (dy) - fabs (dy_mus)));
Real slope_penalty = parameters->IDEAL_SLOPE_FACTOR;
Real thickness, Real beam_translation,
Drul_array<int> beam_counts,
Direction ldir, Direction rdir,
-
- Beam_quant_parameters const*parameters)
+
+ Beam_quant_parameters const *parameters)
{
Real dy = yr - yl;
Drul_array<Real> y (yl, yr);