#include <math.h>
-#include "new-beaming.hh"
+#include "chord-tremolo.hh"
+#include "beaming.hh"
#include "proto.hh"
#include "dimensions.hh"
#include "beam.hh"
Beam::add_stem (Stem*s)
{
#if 0
+ /*
+ should figure out why this didn't work.
+
+ --hwn.
+ */
if (!stems_.size ())
{
- dim_cache_[Y_AXIS]->parent_l_ = s->dim_cache_[Y_AXIS];
+ set_parent (s, Y_AXIS);
}
#endif
stems_.push (s);
mol_p->add_molecule (sb);
}
mol_p->translate_axis (x0
- - spanned_drul_[LEFT]->absolute_coordinate (X_AXIS), X_AXIS);
+ - spanned_drul_[LEFT]->relative_coordinate (0, X_AXIS), X_AXIS);
return mol_p;
}
si.stem_l_->staff_line_leading_f ()/2);
}
+/*
+ Simplistic auto-knees; only consider vertical gap between two
+ adjacent chords
+ */
+bool
+Beam::auto_knee (SCM gap, bool interstaff_b)
+{
+ bool knee = false;
+ int knee_y = 0;
+ Real internote_f = stems_[0]->staff_line_leading_f ()/2;
+ if (gap != SCM_BOOL_F)
+ {
+ int auto_gap_i = gh_scm2int (SCM_CDR (gap));
+ for (int i=1; i < stems_.size (); i++)
+ {
+ bool is_b = (bool)(sinfo_[i].interstaff_f_ - sinfo_[i-1].interstaff_f_);
+ int l_y = (int)(stems_[i-1]->chord_start_f () / internote_f)
+ + (int)sinfo_[i-1].interstaff_f_;
+ int r_y = (int)(stems_[i]->chord_start_f () / internote_f)
+ + (int)sinfo_[i].interstaff_f_;
+ int gap_i = r_y - l_y;
+
+ /*
+ Forced stem directions are ignored. If you don't want auto-knees,
+ don't set, or unset autoKneeGap/autoInterstaffKneeGap.
+ */
+ if ((abs (gap_i) >= auto_gap_i) && (!interstaff_b || is_b))
+ {
+ knee_y = (r_y + l_y) / 2;
+ knee = true;
+ break;
+ }
+ }
+ }
+ if (knee)
+ {
+ for (int i=0; i < stems_.size (); i++)
+ {
+ int y = (int)(stems_[i]->chord_start_f () / internote_f)
+ + (int)sinfo_[i].interstaff_f_;
+ stems_[i]->dir_ = y < knee_y ? UP : DOWN;
+ stems_[i]->set_elt_property (dir_forced_scm_sym, SCM_BOOL_T);
+ }
+ }
+ return knee;
+}
+
+bool
+Beam::auto_knees ()
+{
+ if (auto_knee (get_elt_property (auto_interstaff_knee_gap_scm_sym), true))
+ return true;
+
+ return auto_knee (get_elt_property (auto_knee_gap_scm_sym), false);
+}
+
+
void
Beam::do_pre_processing ()
{
+ /*
+ urg: it seems that info on whether beam (voice) dir was forced
+ is being junked here?
+ */
if (!dir_)
dir_ = get_default_dir ();
-
set_direction (dir_);
}
Beam::do_print () const
{
#ifndef NPRINT
- DOUT << "slope_f_ " << slope_f_ << "left ypos " << left_y_;
+ DEBUG_OUT << "slope_f_ " << slope_f_ << "left ypos " << left_y_;
Spanner::do_print ();
#endif
}
{
warning (_ ("beam with less than two stems"));
set_elt_property (transparent_scm_sym, SCM_BOOL_T);
- return ;
+ return;
+ }
+ set_steminfo ();
+ if (auto_knees ())
+ {
+ /*
+ if auto-knee did its work, most probably stem directions
+ have changed, so we must recalculate all.
+ */
+ dir_ = get_default_dir ();
+ set_direction (dir_);
+
+ /* auto-knees used to only work for slope = 0
+ anyway, should be able to set slope per beam
+ set_elt_property (damping_scm_sym, gh_int2scm(1000));
+ */
+
+ sinfo_.clear ();
+ set_steminfo ();
}
calculate_slope ();
set_stemlens ();
count[UP] = count[DOWN] = 0;
Direction d = DOWN;
- Direction beamdir;
for (int i=0; i <stems_.size (); i++)
do {
Stem *s = stems_[i];
If dir is not determined: up (see stem::get_default_dir ())
*/
+ Direction beam_dir;
+ Direction neutral_dir = (Direction)(int)paper_l ()->get_var ("stem_default_neutral_direction");
+
Dir_algorithm a = (Dir_algorithm)rint(paper_l ()->get_var ("beam_dir_algorithm"));
switch (a)
{
case MAJORITY:
- beamdir = (count[UP] >= count[DOWN]) ? UP : DOWN;
+ beam_dir = (count[UP] == count[DOWN]) ? neutral_dir
+ : (count[UP] > count[DOWN]) ? UP : DOWN;
break;
case MEAN:
// mean center distance
- beamdir = (total[UP] >= total[DOWN]) ? UP : DOWN;
+ beam_dir = (total[UP] == total[DOWN]) ? neutral_dir
+ : (total[UP] > total[DOWN]) ? UP : DOWN;
break;
default:
case MEDIAN:
// median center distance
- if (!count[DOWN])
- beamdir = UP;
- if (!count[UP])
- beamdir = DOWN;
+ if (!count[DOWN] || !count[UP])
+ {
+ beam_dir = (count[UP] == count[DOWN]) ? neutral_dir
+ : (count[UP] > count[DOWN]) ? UP : DOWN;
+ }
else
- beamdir = (total[UP] / count[UP] >= total[DOWN] / count[DOWN]) ? UP : DOWN;
+ {
+ beam_dir = (total[UP] / count[UP] == total[DOWN] / count[DOWN])
+ ? neutral_dir
+ : (total[UP] / count[UP] > total[DOWN] / count[DOWN]) ? UP : DOWN;
+ }
break;
}
- return beamdir;
+ return beam_dir;
}
void
Beam::solve_slope ()
{
assert (sinfo_.size () > 1);
- DOUT << "Beam::solve_slope: \n";
+ DEBUG_OUT << "Beam::solve_slope: \n";
Least_squares l;
for (int i=0; i < sinfo_.size (); i++)
{
// when all too short, normal stems win..
if (dy_f < -epsilon_f)
- warning (_ ("weird beam shift, check your knees"));
- dy_f = dy_f >? sinfo_[i].miny_f_ - y;
+ warning (_ ("weird beam vertical offset"));
+ dy_f = dy_f >? sinfo_[i].miny_f_ - y;
}
}
return dy_f;
return;
assert (multiple_i_);
+
int total_count_i = 0;
int forced_count_i = 0;
for (int i=0; i < stems_.size (); i++)
for (int i=0; i < stems_.size (); i++)
{
Stem *s = stems_[i];
- if (s->invisible_b ())
- continue;
+ /*
+ Chord tremolo needs to beam over invisible stems of wholes
+ */
+ if (!dynamic_cast<Chord_tremolo*> (this))
+ {
+ if (s->invisible_b ())
+ continue;
+ }
Stem_info info (s, multiple_i_);
if (leftx == 0)
void
Beam::calculate_slope ()
{
- set_steminfo ();
if (!sinfo_.size ())
slope_f_ = left_y_ = 0;
else if (sinfo_[0].idealy_f_ == sinfo_.top ().idealy_f_)
Molecule rightbeams;
// UGH
- Real nw_f = paper_l ()->note_width () * 0.8;
+ Real nw_f;
+ if (!here->head_l_arr_.size ())
+ nw_f = 0;
+ else if (here->type_i ()== 1)
+ nw_f = paper_l ()->get_var ("wholewidth");
+ else if (here->type_i () == 2)
+ nw_f = paper_l ()->note_width () * 0.8;
+ else
+ nw_f = paper_l ()->get_var ("quartwidth");
/* half beams extending to the left. */
if (prev)
SCM gap = get_elt_property (beam_gap_scm_sym);
if (gap != SCM_BOOL_F)
{
- int gap_i = gh_scm2int (gap);
+ int gap_i = gh_scm2int (SCM_CDR (gap));
int nogap = rwholebeams - gap_i;
for (; j < nogap; j++)
for (; j < rwholebeams; j++)
{
Molecule b (a);
- b.translate (Offset (gap_f, -dir_ * dy * j));
+ if (!here->invisible_b ())
+ b.translate (Offset (gap_f, -dir_ * dy * j));
+ else
+ b.translate (Offset (0, -dir_ * dy * j));
rightbeams.add_molecule (b);
}