source file of the GNU LilyPond music typesetter
- (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
*/
* move paper vars to scm
*/
+
+
#include <math.h> // tanh.
#include "directional-element-interface.hh"
#include "beam.hh"
#include "misc.hh"
#include "debug.hh"
-#include "leastsquares.hh"
+#include "least-squares.hh"
#include "stem.hh"
#include "paper-def.hh"
#include "lookup.hh"
assert (!s->beam_l ());
s->set_elt_property ("beam", self_scm_);
- if (!spanned_drul_[LEFT])
- set_bounds (LEFT,s);
+ if (!get_bound (LEFT))
+ set_bound (LEFT,s);
else
- set_bounds (RIGHT,s);
+ set_bound (RIGHT,s);
}
int
their beam, during 'final-pre-processing'.]
*/
void
-Beam::do_pre_processing ()
+Beam::before_line_breaking ()
{
// Why?
if (visible_stem_count () < 2)
{
warning (_ ("beam has less than two stems"));
- set_elt_property ("transparent", SCM_BOOL_T);
+ // set_elt_property ("transparent", SCM_BOOL_T);
}
if (!directional_element (this).get ())
auto_knees ();
set_stem_directions ();
-
set_stem_shorten ();
}
Adjust stem lengths to reach beam.
*/
void
-Beam::do_post_processing ()
+Beam::after_line_breaking ()
{
/* first, calculate y, dy */
Real y, dy;
calc_position_and_height (&y, &dy);
- if (suspect_slope_b (y, dy))
- dy = 0;
+ if (visible_stem_count ())
+ {
+ if (suspect_slope_b (y, dy))
+ dy = 0;
- Real damped_dy = calc_slope_damping_f (dy);
- Real quantised_dy = quantise_dy_f (damped_dy);
+ Real damped_dy = calc_slope_damping_f (dy);
+ Real quantised_dy = quantise_dy_f (damped_dy);
- y += (dy - quantised_dy) / 2;
- dy = quantised_dy;
-
+ y += (dy - quantised_dy) / 2;
+ dy = quantised_dy;
+ }
/*
until here, we used only stem_info, which acts as if dir=up
*/
y *= directional_element (this).get ();
dy *= directional_element (this).get ();
- /* set or read dy as necessary */
- SCM s = get_elt_property ("height");
+ Staff_symbol_referencer_interface st (this);
+ Real half_space = st.staff_space () / 2;
+
+ /* check for user-override of dy */
+ SCM s = remove_elt_property ("height-hs");
if (gh_number_p (s))
- dy = gh_scm2double (s);
- else
- set_elt_property ("height", gh_double2scm (dy));
+ {
+ dy = gh_scm2double (s) * half_space;
+ }
+ set_elt_property ("height", gh_double2scm (dy));
- /* set or read y as necessary */
- s = get_elt_property ("y-position");
+ /* check for user-override of y */
+ s = remove_elt_property ("y-position-hs");
if (gh_number_p (s))
{
- y = gh_scm2double (s);
- set_stem_length (y, dy);
+ y = gh_scm2double (s) * half_space;
}
else
{
set_stem_length (y, dy);
y_shift = check_stem_length_f (y, dy);
- Staff_symbol_referencer_interface st (this);
- Real half_space = st.staff_space () / 2;
if (y_shift > half_space / 4)
{
y += y_shift;
if (abs (y_shift) > half_space / 2)
quant_dir = sign (y_shift) * directional_element (this).get ();
y = quantise_y_f (y, dy, quant_dir);
- set_stem_length (y, dy);
}
-
- set_elt_property ("y-position", gh_double2scm (y));
}
+ // UGH. Y is not in staff position unit?
+ // Ik dacht datwe daar juist van weg wilden?
+ set_stem_length (y, dy);
+ set_elt_property ("y-position", gh_double2scm (y));
}
/*
return;
}
- Least_squares ls;
+ Array<Offset> ideals;
Real x0 = first_visible_stem ()->hpos_f ();
for (int i=0; i < stem_count (); i++)
{
Stem* s = stem (i);
if (s->invisible_b ())
continue;
- ls.input.push (Offset (s->hpos_f () - x0,
- s->calc_stem_info ().idealy_f_));
+ ideals.push (Offset (s->hpos_f () - x0,
+ s->calc_stem_info ().idealy_f_));
}
Real dydx;
- ls.minimise (dydx, *y); // duh, takes references
+ minimise_least_squares (&dydx, y, ideals); // duh, takes references
Real dx = last_visible_stem ()->hpos_f () - x0;
*dy = dydx * dx;
bool
Beam::suspect_slope_b (Real y, Real dy) const
{
+ /* first, calculate y, dy */
/*
steep slope running against lengthened stem is suspect
*/
Real interbeam_f = paper_l ()->interbeam_f (multiplicity);
- Real thick = gh_scm2double (get_elt_property ("beam-thickness"));;
+ Real thick = gh_scm2double (get_elt_property ("beam-thickness"));
Real bdy = interbeam_f;
Real stemdx = staffline_f;
- Real dx = last_visible_stem ()->hpos_f () - first_visible_stem ()->hpos_f ();
+ Real dx = visible_stem_count () ?
+ last_visible_stem ()->hpos_f () - first_visible_stem ()->hpos_f ()
+ : 0.0;
Real dy = get_real ("height");
Real dydx = dy && dx ? dy/dx : 0;
}
-Molecule*
-Beam::do_brew_molecule_p () const
+Molecule
+Beam::do_brew_molecule () const
{
- Molecule *mol_p = new Molecule;
+ Molecule mol;
if (!stem_count ())
- return mol_p;
+ return mol;
+ Real x0,dx;
+ if (visible_stem_count ())
+ {
+ x0 = first_visible_stem ()->hpos_f ();
+ dx = last_visible_stem ()->hpos_f () - x0;
+ }
+ else
+ {
+ x0 = stem (0)->hpos_f ();
+ dx = stem_top ()->hpos_f () - x0;
+ }
+
- Real x0 = first_visible_stem ()->hpos_f ();
- Real dx = last_visible_stem ()->hpos_f () - x0;
Real dy = get_real ("height");
Real dydx = dy && dx ? dy/dx : 0;
Real y = get_real ("y-position");
Molecule sb = stem_beams (i, next, prev);
Real x = i->hpos_f ()-x0;
sb.translate (Offset (x, x * dydx + y));
- mol_p->add_molecule (sb);
+ mol.add_molecule (sb);
}
- mol_p->translate_axis (x0
- - spanned_drul_[LEFT]->relative_coordinate (0, X_AXIS), X_AXIS);
+ mol.translate_axis (x0
+ - get_bound (LEFT)->relative_coordinate (0, X_AXIS), X_AXIS);
- return mol_p;
+ return mol;
}
int
if (!s->invisible_b ())
return s;
}
-
- assert (0);
-
return 0;
}
if (!s->invisible_b ())
return s;
}
-
- assert (0);
- // sigh
return 0;
}