source file of the GNU LilyPond music typesetter
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ Jan Nieuwenhuizen <janneke@gnu.org>
- TODO
+*/
- Less hairy code. knee: ([\stem 1; c8 \stem -1; c8]
-*/
+/*
+ [TODO]
+ * center beam symbol
+ * less hairy code
+ * redo grouping
+
+TODO:
+
+The relationship Stem <-> Beam is way too hairy. Let's figure who
+needs what, and what information should be available when.
+
+ */
#include <math.h>
-#include "p-col.hh"
-#include "varray.hh"
+#include "beaming.hh"
#include "proto.hh"
-#include "dimen.hh"
+#include "dimensions.hh"
#include "beam.hh"
-#include "abbreviation-beam.hh"
#include "misc.hh"
#include "debug.hh"
-#include "atom.hh"
#include "molecule.hh"
#include "leastsquares.hh"
#include "stem.hh"
#include "paper-def.hh"
#include "lookup.hh"
-#include "grouping.hh"
-#include "stem-info.hh"
-#include "main.hh" // experimental features
-
-
-IMPLEMENT_IS_TYPE_B1 (Beam, Spanner);
-
-// ugh, hardcoded
-const Real MINIMUM_STEMLEN[] = {
- 0, // just in case
- 5,
- 4,
- 3,
- 2,
- 2,
-};
Beam::Beam ()
{
slope_f_ = 0;
- left_y_ = 0.0;
- damping_i_ = 1;
- quantisation_ = NORMAL;
+ left_y_ = 0;
multiple_i_ = 0;
}
void
-Beam::add (Stem*s)
+Beam::add_stem (Stem*s)
{
+#if 0
+ /*
+ should figure out why this didn't work.
+
+ --hwn.
+ */
+ if (!stems_.size ())
+ {
+ set_parent (s, Y_AXIS);
+ }
+#endif
stems_.push (s);
s->add_dependency (this);
+
+ assert (!s->beam_l_);
s->beam_l_ = this;
if (!spanned_drul_[LEFT])
set_bounds (RIGHT,s);
}
+Stem_info
+Beam::get_stem_info (Stem *s)
+{
+ Stem_info i;
+ for (int i=0; i < sinfo_.size (); i++)
+ {
+ if (sinfo_[i].stem_l_ == s)
+ return sinfo_[i];
+ }
+ assert (false);
+ return i;
+}
+
Molecule*
-Beam::brew_molecule_p () const
+Beam::do_brew_molecule_p () const
{
Molecule *mol_p = new Molecule;
- Real inter_f = paper ()->internote_f ();
+ if (!sinfo_.size ())
+ return mol_p;
+
Real x0 = stems_[0]->hpos_f ();
for (int j=0; j <stems_.size (); j++)
{
Molecule sb = stem_beams (i, next, prev);
Real x = i->hpos_f ()-x0;
- sb.translate (Offset (x, (x * slope_f_ + left_y_)* inter_f));
- mol_p->add (sb);
+ sb.translate (Offset (x, (x * slope_f_ + left_y_) *
+ i->staff_line_leading_f ()/2 ));
+ mol_p->add_molecule (sb);
}
- mol_p->translate_axis (x0 - spanned_drul_[LEFT]->absolute_coordinate (X_AXIS), X_AXIS);
+ mol_p->translate_axis (x0
+ - spanned_drul_[LEFT]->relative_coordinate (0, X_AXIS), X_AXIS);
+
return mol_p;
}
Offset
Beam::center () const
{
- Real w= (paper ()->note_width () + width ().length ())/2.0;
- return Offset (w, (left_y_ + w* slope_f_)*paper ()->internote_f ());
+ Stem_info si = sinfo_[0];
+
+ Real w= (si.stem_l_->note_delta_f () + extent (X_AXIS).length ())/2.0;
+ return Offset (w, ( w* slope_f_) *
+ 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_UNDEFINED)
+ {
+ int auto_gap_i = gh_scm2int (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]->set_direction ( y < knee_y ? UP : DOWN);
+ stems_[i]->set_elt_property ("dir-forced", SCM_BOOL_T);
+ }
+ }
+ return knee;
+}
+
+bool
+Beam::auto_knees ()
+{
+ if (auto_knee (get_elt_property ("auto-interstaff-knee-gap"), true))
+ return true;
+
+ return auto_knee (get_elt_property ("auto-knee-gap"), false);
+}
+
+
void
Beam::do_pre_processing ()
{
- if (!dir_)
- set_default_dir ();
+ /*
+ urg: it seems that info on whether beam (voice) dir was forced
+ is being junked here?
+ */
+ if (!get_direction ())
+ set_direction ( get_default_dir ());
+
+ set_direction (get_direction ());
}
void
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
}
{
if (stems_.size () < 2)
{
- warning (_ ("Beam with less than 2 stems"));
- transparent_b_ = true;
- return ;
+ warning (_ ("beam with less than two stems"));
+ set_elt_property ("transparent", SCM_BOOL_T);
+ return;
+ }
+ set_steminfo ();
+ if (auto_knees ())
+ {
+ /*
+ if auto-knee did its work, most probably stem directions
+ have changed, so we must recalculate all.
+ */
+ set_direction ( get_default_dir ());
+ set_direction (get_direction ());
+
+ /* auto-knees used to only work for slope = 0
+ anyway, should be able to set slope per beam
+ set_elt_property ("damping", gh_int2scm(1000));
+ */
+
+ sinfo_.clear ();
+ set_steminfo ();
}
- solve_slope ();
+ calculate_slope ();
set_stemlens ();
}
void
-Beam::do_substitute_dependent (Score_elem*o,Score_elem*n)
+Beam::do_substitute_element_pointer (Score_element*o,Score_element*n)
{
- if (o->is_type_b (Stem::static_name ()))
- stems_.substitute ((Stem*)o->item (), n? (Stem*) n->item ():0);
+ if (Stem * os = dynamic_cast<Stem*> (o))
+ stems_.substitute (os,
+ dynamic_cast<Stem *> (n));
}
Interval
stems_.top ()->hpos_f ());
}
-void
-Beam::set_default_dir ()
+Direction
+Beam::get_default_dir () const
{
Drul_array<int> total;
total[UP] = total[DOWN] = 0;
Drul_array<int> count;
count[UP] = count[DOWN] = 0;
Direction d = DOWN;
-
+
for (int i=0; i <stems_.size (); i++)
do {
Stem *s = stems_[i];
- int current = s->dir_
- ? (1 + d * s->dir_)/2
+ int current = s->get_direction ()
+ ? (1 + d * s->get_direction ())/2
: s->get_center_distance ((Direction)-d);
if (current)
} while (flip(&d) != DOWN);
- do {
- if (!total[d])
- count[d] = 1;
- } while (flip(&d) != DOWN);
-
/*
-
[Ross] states that the majority of the notes dictates the
direction (and not the mean of "center distance")
- */
- dir_ = (total[UP] > total[DOWN]) ? UP : DOWN;
+ But is that because it really looks better, or because he wants
+ to provide some real simple hands-on rules?
+
+ We have our doubts, so we simply provide all sensible alternatives.
+
+ If dir is not determined: up (see stem::get_default_dir ()) */
+
+ Direction beam_dir = CENTER;
+ Direction neutral_dir = (Direction)(int)paper_l ()->get_var ("stem_default_neutral_direction");
+
+ SCM a = get_elt_property ("beam-dir-algorithm");
+
+ if (a == gh_symbol2scm ("majority")) // should get default from paper.
+ beam_dir = (count[UP] == count[DOWN]) ? neutral_dir
+ : (count[UP] > count[DOWN]) ? UP : DOWN;
+ else if (a == gh_symbol2scm ("mean"))
+ // mean center distance
+ beam_dir = (total[UP] == total[DOWN]) ? neutral_dir
+ : (total[UP] > total[DOWN]) ? UP : DOWN;
+ else if (a == gh_symbol2scm ("median"))
+ {
+ // median center distance
+ if (count[DOWN] && count[UP])
+ {
+ beam_dir = (total[UP] / count[UP] == total[DOWN] / count[DOWN])
+ ? neutral_dir
+ : (total[UP] / count[UP] > total[DOWN] / count[DOWN]) ? UP : DOWN;
+ }
+ else
+ {
+ beam_dir = (count[UP] == count[DOWN]) ? neutral_dir
+ : (count[UP] > count[DOWN]) ? UP : DOWN;
+ }
+ }
+
+ return beam_dir;
+}
+
+void
+Beam::set_direction (Direction d)
+{
+ set_direction ( d);
for (int i=0; i <stems_.size (); i++)
{
- Stem *sl = stems_[i];
- sl->dir_ = dir_;
+ Stem *s = stems_[i];
+ s->set_elt_property ("beam-dir", gh_int2scm (d));
+
+ SCM force = s->remove_elt_property ("dir-forced");
+ if (force == SCM_UNDEFINED)
+ s->set_direction ( d);
}
}
/*
- should use minimum energy formulation (cf linespacing)
-*/
+ See Documentation/tex/fonts.doc
+ */
+
void
Beam::solve_slope ()
{
- Array<Stem_info> sinfo;
- for (int j=0; j <stems_.size (); j++)
- {
- Stem *i = stems_[j];
-
- i->set_default_extents ();
- if (i->invisible_b ())
- continue;
+ assert (sinfo_.size () > 1);
- Stem_info info (i);
- sinfo.push (info);
- }
- if (! sinfo.size ())
- slope_f_ = left_y_ = 0;
- else if (sinfo.size () == 1)
+ Least_squares l;
+ for (int i=0; i < sinfo_.size (); i++)
{
- slope_f_ = 0;
- left_y_ = sinfo[0].idealy_f_;
+ l.input.push (Offset (sinfo_[i].x_, sinfo_[i].idealy_f_));
}
- else
+ l.minimise (slope_f_, left_y_);
+}
+
+/*
+ ugh. Naming: this doesn't check, but sets as well.
+ */
+
+Real
+Beam::check_stemlengths_f (bool set_b)
+{
+ Real interbeam_f = paper_l ()->interbeam_f (multiple_i_);
+
+ Real beam_f = paper_l ()->get_var ("beam_thickness");;
+ Real staffline_f = paper_l ()-> get_var ("stafflinethickness");
+ Real epsilon_f = staffline_f / 8;
+ Real dy_f = 0.0;
+ for (int i=0; i < sinfo_.size (); i++)
{
+ Real y = sinfo_[i].x_ * slope_f_ + left_y_;
- Real leftx = sinfo[0].x;
- Least_squares l;
- for (int i=0; i < sinfo.size (); i++)
+ // correct for knee
+ if (get_direction () != sinfo_[i].get_direction ())
{
- sinfo[i].x -= leftx;
- l.input.push (Offset (sinfo[i].x, sinfo[i].idealy_f_));
+ Real internote_f = sinfo_[i].stem_l_->staff_line_leading_f ()/2;
+ y -= get_direction () * (beam_f / 2
+ + (sinfo_[i].mult_i_ - 1) * interbeam_f) / internote_f;
+ if (!i && sinfo_[i].stem_l_->staff_symbol_l () !=
+ sinfo_.top ().stem_l_->staff_symbol_l ())
+ y += get_direction () * (multiple_i_ - (sinfo_[i].stem_l_->flag_i_ - 2) >? 0)
+ * interbeam_f / internote_f;
}
- l.minimise (slope_f_, left_y_);
+ if (set_b)
+ sinfo_[i].stem_l_->set_stemend (y - sinfo_[i].interstaff_f_);
+
+ y *= get_direction ();
+ if (y > sinfo_[i].maxy_f_)
+ dy_f = dy_f <? sinfo_[i].maxy_f_ - y;
+ if (y < sinfo_[i].miny_f_)
+ {
+ // when all too short, normal stems win..
+ if (dy_f < -epsilon_f)
+ warning (_ ("weird beam vertical offset"));
+ dy_f = dy_f >? sinfo_[i].miny_f_ - y;
+ }
}
+ return dy_f;
+}
+
+void
+Beam::set_steminfo ()
+{
+ if(!stems_.size ())
+ return;
+
+ assert (multiple_i_);
- Real dy = 0.0;
- for (int i=0; i < sinfo.size (); i++)
+ int total_count_i = 0;
+ int forced_count_i = 0;
+ for (int i=0; i < stems_.size (); i++)
{
- Real y = sinfo[i].x * slope_f_ + left_y_;
- Real my = sinfo[i].miny_f_;
+ Stem *s = stems_[i];
- if (my - y > dy)
- dy = my -y;
+ s->set_default_extents ();
+ if (s->invisible_b ())
+ continue;
+ if (((int)s->chord_start_f ()) && (s->get_direction () != s->get_default_dir ()))
+ forced_count_i++;
+ total_count_i++;
}
- left_y_ += dy;
- left_y_ *= dir_;
- slope_f_ *= dir_;
+ bool grace_b = get_elt_property ("grace") == SCM_BOOL_T;
+ String type_str = grace_b ? "grace_" : "";
+ int stem_max = (int)rint(paper_l ()->get_var ("stem_max"));
+ Real shorten_f = paper_l ()->get_var (type_str + "forced_stem_shorten"
+ + to_str (multiple_i_ <? stem_max));
+
+ Real leftx = 0;
+ for (int i=0; i < stems_.size (); i++)
+ {
+ Stem *s = stems_[i];
+ /*
+ Chord tremolo needs to beam over invisible stems of wholes
+ */
+ SCM trem = get_elt_property ("chord-tremolo");
+ if (gh_boolean_p (trem) && gh_scm2bool (trem))
+ {
+ if (s->invisible_b ())
+ continue;
+ }
- /*
- This neat trick is by Werner Lemberg, damped = tanh (slope_f_) corresponds
- with some tables in [Wanske]
- */
- if (damping_i_)
- slope_f_ = 0.6 * tanh (slope_f_) / damping_i_;
+ Stem_info info (s, multiple_i_);
+ if (leftx == 0)
+ leftx = info.x_;
+ info.x_ -= leftx;
+ if (info.get_direction () == get_direction ())
+ {
+ if (forced_count_i == total_count_i)
+ info.idealy_f_ -= shorten_f;
+ else if (forced_count_i > total_count_i / 2)
+ info.idealy_f_ -= shorten_f / 2;
+ }
+ sinfo_.push (info);
+ }
+}
- quantise_yspan ();
+void
+Beam::calculate_slope ()
+{
+ if (!sinfo_.size ())
+ slope_f_ = left_y_ = 0;
+ else if (sinfo_[0].idealy_f_ == sinfo_.top ().idealy_f_)
+ {
+ slope_f_ = 0;
+ left_y_ = sinfo_[0].idealy_f_;
+ left_y_ *= get_direction ();
+ }
+ else
+ {
+ solve_slope ();
+ Real solved_slope_f = slope_f_;
+
+ /*
+ steep slope running against lengthened stem is suspect
+ */
+ Real dx_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
+
+ // urg, these y internote-y-dimensions
+ Real internote_f = stems_[0]->staff_line_leading_f ()/2;
+
+ Real lengthened = paper_l ()->get_var ("beam_lengthened") / internote_f;
+ Real steep = paper_l ()->get_var ("beam_steep_slope") / internote_f;
+ if (((left_y_ - sinfo_[0].idealy_f_ > lengthened)
+ && (slope_f_ > steep))
+ || ((left_y_ + slope_f_ * dx_f - sinfo_.top ().idealy_f_ > lengthened)
+ && (slope_f_ < -steep)))
+ {
+ slope_f_ = 0;
+ }
- // y-values traditionally use internote dimension: therefore slope = (y/in)/x
- // but mf and beam-lookup use PT dimension for y (as used for x-values)
- // ugh --- there goes our simplified but careful quantisation
- Real sl = slope_f_ * paper ()->internote_f ();
- paper ()->lookup_l ()->beam (sl, 20 PT, 1 PT);
- slope_f_ = sl / paper ()->internote_f ();
+ /*
+ This neat trick is by Werner Lemberg,
+ damped = tanh (slope_f_)
+ corresponds with some tables in [Wanske]
+ */
+ SCM damp = remove_elt_property ("damping");
+ int damping = 1; // ugh.
+ if (damp!= SCM_UNDEFINED)
+ damping = gh_int2scm (damp);
+
+ if (damping)
+ slope_f_ = 0.6 * tanh (slope_f_) / damping;
+
+ quantise_dy ();
+
+ Real damped_slope_dy_f = (solved_slope_f - slope_f_) * dx_f / 2;
+ left_y_ += damped_slope_dy_f;
+
+ left_y_ *= get_direction ();
+ slope_f_ *= get_direction ();
+ }
}
void
-Beam::quantise_yspan ()
+Beam::quantise_dy ()
{
/*
[Ross] (simplification of)
Try to set slope_f_ complying with y-span of:
- zero
- - beam_thickness / 2 + staffline_thickness / 2
- - beam_thickness + staffline_thickness
+ - beam_f / 2 + staffline_f / 2
+ - beam_f + staffline_f
+ n * interline
*/
- if (!quantisation_)
+ SCM q = get_elt_property ("slope-quantisation");
+
+ if (q == gh_symbol2scm ("none"))
return;
- Real interline_f = paper ()->interline_f ();
+ Real interline_f = stems_[0]->staff_line_leading_f ();
Real internote_f = interline_f / 2;
- Real staffline_thickness = paper ()->rule_thickness ();
- Real beam_thickness = 0.48 * (interline_f - staffline_thickness);
-
- const int QUANTS = 3;
- Real qdy[QUANTS] = {
- 0,
- beam_thickness / 2 + staffline_thickness / 2,
- beam_thickness + staffline_thickness
- };
-
- Real xspan_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
- // y-values traditionally use internote dimension: therefore slope = (y/in)/x
- Real yspan_f = xspan_f * abs (slope_f_ * internote_f);
- int yspan_i = (int)(yspan_f / interline_f);
- Real q = (yspan_f / interline_f - yspan_i) * interline_f;
- int i = 0;
- for (; i < QUANTS - 1; i++)
- if ((q >= qdy[i]) && (q <= qdy[i + 1]))
- {
- if (q - qdy[i] < qdy[i + 1] - q)
- break;
- else
- {
- i++;
- break;
- }
- }
- q = qdy[i];
+ Real staffline_f = paper_l ()->get_var ("stafflinethickness");
+ Real beam_f = paper_l ()->get_var ("beam_thickness");;
+
+ Real dx_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
+
+ // dim(y) = internote; so slope = (y/internote)/x
+ Real dy_f = dx_f * abs (slope_f_ * internote_f);
+
+ Real quanty_f = 0.0;
+
+ Array<Real> allowed_fraction (3);
+ allowed_fraction[0] = 0;
+ allowed_fraction[1] = (beam_f / 2 + staffline_f / 2);
+ allowed_fraction[2] = (beam_f + staffline_f);
+
+
+ Interval iv = quantise_iv (allowed_fraction, interline_f, dy_f);
+ quanty_f = (dy_f - iv[SMALLER] <= iv[BIGGER] - dy_f)
+ ? iv[SMALLER]
+ : iv[BIGGER];
+
- yspan_f = (Real)yspan_i * interline_f + q;
- // y-values traditionally use internote dimension: therefore slope = (y/in)/x
- slope_f_ = yspan_f / xspan_f / internote_f * sign (slope_f_);
+ slope_f_ = (quanty_f / dx_f) / internote_f * sign (slope_f_);
}
+/*
+
+ Prevent interference from stafflines and beams. See Documentation/tex/fonts.doc
+
+ */
void
-Beam::quantise_left_y (Beam::Pos pos, bool extend_b)
+Beam::quantise_left_y (bool extend_b)
{
+ /*
+ we only need to quantise the start of the beam as dy is quantised too
+ if extend_b then stems must *not* get shorter
+ */
+ SCM q = get_elt_property ("slope-quantisation");
+
+
/*
- quantising left y should suffice, as slope is quantised too
- if extend then stems must not get shorter
+ ----------------------------------------------------------
+ ########
+ ########
+ ########
+ --------------########------------------------------------
+ ########
+
+ hang straddle sit inter hang
*/
- if (!quantisation_)
- return;
+ Real space = stems_[0]->staff_line_leading_f ();
+ Real internote_f = space /2;
+ Real staffline_f = paper_l ()->get_var ("stafflinethickness");
+ Real beam_f = paper_l ()->get_var ("beam_thickness");;
- Real interline_f = paper ()->interline_f ();
- Real internote_f = interline_f / 2;
- Real staffline_thickness = paper ()->rule_thickness ();
- Real beam_thickness = 0.48 * (interline_f - staffline_thickness);
-
- const int QUANTS = 7;
- Real qy[QUANTS] =
- {
- 0,
- beam_thickness / 2,
- beam_thickness,
- interline_f / 2 + beam_thickness / 2 + staffline_thickness / 2,
- interline_f,
- interline_f + beam_thickness / 2,
- interline_f + beam_thickness
- };
- /*
- ugh, using i triggers gcc 2.7.2.1 internal compiler error (far down):
- for (int i = 0; i < QUANTS; i++)
+ /*
+ [TODO]
+ it would be nice to have all allowed positions in a runtime matrix:
+ (multiplicity, minimum_beam_dy, maximum_beam_dy)
+ */
+
+ Real straddle = 0;
+ Real sit = beam_f / 2 - staffline_f / 2;
+ Real hang = space - beam_f / 2 + staffline_f / 2;
+
+ /*
+ Put all allowed positions into an array.
+ Whether a position is allowed or not depends on
+ strictness of quantisation, multiplicity and direction.
+
+ For simplicity, we'll assume dir = UP and correct if
+ dir = DOWN afterwards.
*/
+ // isn't this asymmetric ? --hwn
- // fixme!
- for (int ii = 0; ii < QUANTS; ii++)
- qy[ii] -= 0.5 *beam_thickness;
- Pos qpos[QUANTS] =
- {
- HANG,
- STRADDLE,
- SIT,
- INTER,
- HANG,
- STRADDLE,
- SIT
- };
-
- // y-values traditionally use internote dimension
- Real y = left_y_ * internote_f;
- int y_i = (int)floor(y / interline_f);
- y = (y / interline_f - y_i) * interline_f;
-
- if (y < 0)
- for (int ii = 0; ii < QUANTS; ii++)
- qy[ii] -= interline_f;
-
- int lower_i = 0;
- int i = 0;
- for (; i < QUANTS; i++)
+ // dim(left_y_) = internote
+ Real dy_f = get_direction () * left_y_ * internote_f;
+
+ Real beamdx_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
+ Real beamdy_f = beamdx_f * slope_f_ * internote_f;
+
+ Array<Real> allowed_position;
+ if (q == gh_symbol2scm ("normal"))
{
- if (qy[i] > y)
- break;
- // found if lower_i is allowed, and nearer (from below) y than new pos
- if ((pos & qpos[lower_i]) && (y - qy[lower_i] < y - qy[i]))
- break;
- // if new pos is allowed or old pos isn't: assign new pos
- if ((pos & qpos[i]) || !(pos & qpos[lower_i]))
- lower_i = i;
+ if ((multiple_i_ <= 2) || (abs (beamdy_f) >= staffline_f / 2))
+ allowed_position.push (straddle);
+ if ((multiple_i_ <= 1) || (abs (beamdy_f) >= staffline_f / 2))
+ allowed_position.push (sit);
+ allowed_position.push (hang);
}
-
- int upper_i = QUANTS - 1;
- for (i = QUANTS - 1; i >= 0; i--)
+ else if (q == gh_symbol2scm ("traditional"))
{
- if (qy[i] < y)
- break;
- // found if upper_i is allowed, and nearer (from above) y than new pos
- if ((pos & qpos[upper_i]) && (qy[upper_i] - y < qy[i] - y))
- break;
- // if new pos is allowed or old pos isn't: assign new pos
- if ((pos & qpos[i]) || !(pos & qpos[upper_i]))
- upper_i = i;
+ // TODO: check and fix TRADITIONAL
+ if ((multiple_i_ <= 2) || (abs (beamdy_f) >= staffline_f / 2))
+ allowed_position.push (straddle);
+ if ((multiple_i_ <= 1) && (beamdy_f <= staffline_f / 2))
+ allowed_position.push (sit);
+ if (beamdy_f >= -staffline_f / 2)
+ allowed_position.push (hang);
}
- // y-values traditionally use internote dimension
- Real upper_y = (qy[upper_i] + interline_f * y_i) / internote_f;
- Real lower_y = (qy[lower_i] + interline_f * y_i) / internote_f;
+ Interval iv = quantise_iv (allowed_position, space, dy_f);
+
+ Real quanty_f = dy_f - iv[SMALLER] <= iv[BIGGER] - dy_f ? iv[SMALLER] : iv[BIGGER];
if (extend_b)
- left_y_ = (dir_ > 0 ? upper_y : lower_y);
- else
- left_y_ = (upper_y - y < y - lower_y ? upper_y : lower_y);
+ quanty_f = iv[BIGGER];
+
+ // dim(left_y_) = internote
+ left_y_ = get_direction () * quanty_f / internote_f;
}
void
Beam::set_stemlens ()
{
- Real x0 = stems_[0]->hpos_f ();
- Real dy = 0;
-
- Real interline_f = paper ()->interline_f ();
- Real internote_f = interline_f / 2;
- Real staffline_thickness = paper ()->rule_thickness ();
- Real beam_thickness = 0.48 * (interline_f - staffline_thickness);
- Real interbeam_f = paper ()->interbeam_f ();
- if (multiple_i_ > 3)
- interbeam_f += 2.0 * staffline_thickness / 4;
- Real xspan_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
- /*
- ugh, y values are in "internote" dimension
- */
- Real yspan_f = xspan_f * abs (slope_f_ * internote_f);
- int yspan_i = (int)(yspan_f / interline_f);
-
- Pos left_pos = NONE;
-
- if ((yspan_f < staffline_thickness / 2) || (quantisation_ == NORMAL))
- left_pos = (Pos)(STRADDLE | SIT | HANG);
- else
- left_pos = (Pos) (sign (slope_f_) > 0 ? STRADDLE | HANG
- : SIT | STRADDLE);
+ Real staffline_f = paper_l ()->get_var ("stafflinethickness");
+ // enge floots
+ Real epsilon_f = staffline_f / 8;
- /*
- ugh, slope currently mangled by availability mf chars...
- be more generous regarding beam position between stafflines
- */
- Real q = (yspan_f / interline_f - yspan_i) * interline_f;
- if (q < interline_f / 3 - beam_thickness / 2)
- left_pos = (Pos) (left_pos | INTER);
-
- if (multiple_i_ > 1)
- left_pos = (Pos) (dir_ > 0 ? HANG : SIT);
- // ugh, rounding problems!
- const Real EPSILON = interline_f / 10;
- do
+ // je bent zelf eng --hwn.
+ Real dy_f = check_stemlengths_f (false);
+ for (int i = 0; i < 2; i++) // 2 ?
{
- left_y_ += dy * dir_;
- quantise_left_y (left_pos, dy);
- dy = 0;
- for (int j=0; j < stems_.size (); j++)
- {
- Stem *s = stems_[j];
- if (s->transparent_b_)
- continue;
+ left_y_ += dy_f * get_direction ();
+ quantise_left_y (dy_f);
+ dy_f = check_stemlengths_f (true);
+ if (abs (dy_f) <= epsilon_f)
+ {
+ break;
+ }
+ }
+}
- Real x = s->hpos_f () - x0;
- s->set_stemend (left_y_ + slope_f_ * x);
- Real y = s->stem_length_f ();
- int mult = max (stems_[j]->beams_left_i_, stems_[j]->beams_right_i_);
- if (mult > 1)
- // dim(y) = internote
- y -= (Real)(mult - 1) * interbeam_f / internote_f;
- if (y < MINIMUM_STEMLEN[mult])
- dy = dy >? (MINIMUM_STEMLEN[mult] - y);
+void
+Beam::set_beaming (Beaming_info_list *beaming)
+{
+ Direction d = LEFT;
+ for (int i=0; i < stems_.size (); i++)
+ {
+ do
+ {
+ if (stems_[i]->beams_i_drul_[d] < 0)
+ stems_[i]->beams_i_drul_[d] = beaming->infos_.elem (i).beams_i_drul_[d];
}
- } while (abs (dy) > EPSILON);
+ while (flip (&d) != LEFT);
+ }
}
+
void
-Beam::set_grouping (Rhythmic_grouping def, Rhythmic_grouping cur)
+Beam::do_add_processing ()
{
- def.OK ();
- cur.OK ();
- assert (cur.children.size () == stems_.size ());
-
- cur.split (def);
-
- Array<int> b;
- {
- Array<int> flags;
- for (int j=0; j <stems_.size (); j++)
- {
- Stem *s = stems_[j];
-
- int f = s->flag_i_ - 2;
- assert (f>0);
- flags.push (f);
- }
- int fi =0;
- b= cur.generate_beams (flags, fi);
- b.insert (0,0);
- b.push (0);
- assert (stems_.size () == b.size ()/2);
- }
-
- for (int j=0, i=0; i < b.size () && j <stems_.size (); i+= 2, j++)
+ for (int i=0; i < stems_.size () ; i++)
+ {
+ Direction d = LEFT;
+ do {
+ multiple_i_ = multiple_i_ >? stems_[i]->beams_i_drul_[d];
+ } while ((flip (&d)) != LEFT);
+ }
+
+ if (stems_.size ())
{
- Stem *s = stems_[j];
- s->beams_left_i_ = b[i];
- s->beams_right_i_ = b[i+1];
- multiple_i_ = multiple_i_ >? (b[i] >? b[i+1]);
+ stems_[0]->beams_i_drul_[LEFT] =0;
+ stems_.top()->beams_i_drul_[RIGHT] =0;
}
}
+
+
/*
beams to go with one stem.
+
+ clean me up.
*/
Molecule
Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
{
- assert (!next || next->hpos_f () > here->hpos_f ());
- assert (!prev || prev->hpos_f () < here->hpos_f ());
-
- Real staffline_thickness = paper ()->rule_thickness ();
- Real interbeam_f = paper ()->interbeam_f ();
- Real internote_f =paper ()->internote_f ();
- Real interline_f = 2 * internote_f;
- Real beamheight_f = 0.48 * (interline_f - staffline_thickness);
- if (multiple_i_ > 3)
- interbeam_f += 2.0 * staffline_thickness / 4;
+ if ((next && !(next->hpos_f () > here->hpos_f ())) ||
+ (prev && !(prev->hpos_f () < here->hpos_f ())))
+ programming_error ("Beams are not left-to-right");
+
+ Real staffline_f = paper_l ()->get_var ("stafflinethickness");
+ Real interbeam_f = paper_l ()->interbeam_f (multiple_i_);
+
+ Real internote_f = here->staff_line_leading_f ()/2;
+ Real beam_f = paper_l ()->get_var ("beam_thickness");;
+
Real dy = interbeam_f;
- Real stemdx = staffline_thickness;
+ Real stemdx = staffline_f;
Real sl = slope_f_* internote_f;
- paper ()->lookup_l ()->beam (sl, 20 PT, 1 PT);
Molecule leftbeams;
Molecule rightbeams;
+ // UGH
+ 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 ()->get_var ("notewidth") * 0.8;
+ else
+ nw_f = paper_l ()->get_var ("quartwidth");
+
/* half beams extending to the left. */
if (prev)
{
- int lhalfs= lhalfs = here->beams_left_i_ - prev->beams_right_i_ ;
- int lwholebeams= here->beams_left_i_ <? prev->beams_right_i_ ;
- Real w = (here->hpos_f () - prev->hpos_f ())/4 <? paper ()->note_width ();;
- Atom a;
+ int lhalfs= lhalfs = here->beams_i_drul_[LEFT] - prev->beams_i_drul_[RIGHT] ;
+ int lwholebeams= here->beams_i_drul_[LEFT] <? prev->beams_i_drul_[RIGHT] ;
+ /*
+ Half beam should be one note-width,
+ but let's make sure two half-beams never touch
+ */
+ Real w = here->hpos_f () - prev->hpos_f ();
+ w = w/2 <? nw_f;
+ Molecule a;
if (lhalfs) // generates warnings if not
- a = paper ()->lookup_l ()->beam (sl, w, beamheight_f);
+ a = lookup_l ()->beam (sl, w, beam_f);
a.translate (Offset (-w, -w * sl));
for (int j = 0; j < lhalfs; j++)
{
- Atom b (a);
- b.translate_axis (-dir_ * dy * (lwholebeams+j), Y_AXIS);
- leftbeams.add (b);
+ Molecule b (a);
+ b.translate_axis (-get_direction () * dy * (lwholebeams+j), Y_AXIS);
+ leftbeams.add_molecule (b);
}
}
if (next)
{
- int rhalfs = here->beams_right_i_ - next->beams_left_i_;
- int rwholebeams = here->beams_right_i_ <? next->beams_left_i_;
+ int rhalfs = here->beams_i_drul_[RIGHT] - next->beams_i_drul_[LEFT];
+ int rwholebeams = here->beams_i_drul_[RIGHT] <? next->beams_i_drul_[LEFT];
Real w = next->hpos_f () - here->hpos_f ();
- Atom a = paper ()->lookup_l ()->beam (sl, w + stemdx, beamheight_f);
+ Molecule a = lookup_l ()->beam (sl, w + stemdx, beam_f);
a.translate_axis( - stemdx/2, X_AXIS);
int j = 0;
Real gap_f = 0;
- if (here->beam_gap_i_)
+
+ SCM gap = get_elt_property ("beam-gap");
+ if (gap != SCM_UNDEFINED)
{
- int nogap = rwholebeams - here->beam_gap_i_;
+ int gap_i = gh_scm2int ( (gap));
+ int nogap = rwholebeams - gap_i;
+
for (; j < nogap; j++)
{
- Atom b (a);
- b.translate_axis (-dir_ * dy * j, Y_AXIS);
- rightbeams.add (b);
+ Molecule b (a);
+ b.translate_axis (-get_direction () * dy * j, Y_AXIS);
+ rightbeams.add_molecule (b);
}
// TODO: notehead widths differ for different types
- gap_f = paper ()->note_width () / 2;
+ gap_f = nw_f / 2;
w -= 2 * gap_f;
- a = paper ()->lookup_l ()->beam (sl, w + stemdx, beamheight_f);
+ a = lookup_l ()->beam (sl, w + stemdx, beam_f);
}
for (; j < rwholebeams; j++)
{
- Atom b (a);
- b.translate (Offset (gap_f, -dir_ * dy * j));
- rightbeams.add (b);
+ Molecule b (a);
+ if (!here->invisible_b ())
+ b.translate (Offset (gap_f, -get_direction () * dy * j));
+ else
+ b.translate (Offset (0, -get_direction () * dy * j));
+ rightbeams.add_molecule (b);
}
- w = w/4 <? paper ()->note_width ();
+ w = w/2 <? nw_f;
if (rhalfs)
- a = paper ()->lookup_l ()->beam (sl, w, beamheight_f);
+ a = lookup_l ()->beam (sl, w, beam_f);
for (; j < rwholebeams + rhalfs; j++)
{
- Atom b (a);
- b.translate_axis (-dir_ * dy * j, Y_AXIS);
- rightbeams.add (b);
+ Molecule b (a);
+ b.translate_axis (-get_direction () * dy * j, Y_AXIS);
+ rightbeams.add_molecule (b);
}
}
- leftbeams.add (rightbeams);
+ leftbeams.add_molecule (rightbeams);
/*
Does beam quanting think of the asymetry of beams?
Refpoint is on bottom of symbol. (FIXTHAT) --hwn.
*/
- if (experimental_features_global_b && dir_ < 0)
- leftbeams.translate_axis (-beamheight_f, Y_AXIS);
return leftbeams;
}
+
+