#include <math.h> // tanh.
-
+#include "molecule.hh"
#include "directional-element-interface.hh"
#include "beaming.hh"
#include "beam.hh"
void
Beam::add_stem (Score_element*me, Score_element*s)
{
- Pointer_group_interface gi (me, "stems");
- gi.add_element (s);
+ Pointer_group_interface:: add_element(me, "stems", s);
s->add_dependency (me);
[Alternatively, stems could set its own directions, according to
their beam, during 'final-pre-processing'.]
*/
-MAKE_SCHEME_CALLBACK(Beam,before_line_breaking);
+MAKE_SCHEME_CALLBACK(Beam,before_line_breaking,1);
SCM
Beam::before_line_breaking (SCM smob)
{
return SCM_EOL;
}
-/*
- FIXME
- */
Direction
Beam::get_default_dir (Score_element*me)
{
} while (flip(&d) != DOWN);
+ SCM func = me->get_elt_property ("dir-function");
+ SCM s = gh_call2 (func,
+ gh_cons (gh_int2scm (count[UP]),
+ gh_int2scm (count[DOWN])),
+ gh_cons (gh_int2scm (total[UP]),
+ gh_int2scm (total[DOWN])));
- SCM s = scm_eval2 (gh_list (ly_symbol2scm ("beam-dir-algorithm"),
- ly_quote_scm (gh_cons (gh_int2scm (count[UP]),
- gh_int2scm (count[DOWN]))),
- ly_quote_scm (gh_cons (gh_int2scm (total[UP]),
- gh_int2scm (total[DOWN]))),
- SCM_UNDEFINED),
- SCM_EOL);
if (gh_number_p (s) && gh_scm2int (s))
return to_dir (s);
int multiplicity = get_multiplicity (me);
- // grace stems?
- SCM shorten = scm_eval2 (ly_symbol2scm ("beamed-stem-shorten"), SCM_EOL);
-
+ SCM shorten = me->get_elt_property ("beamed-stem-shorten");
if (shorten == SCM_EOL)
return;
Set elt properties height and y-position if not set.
Adjust stem lengths to reach beam.
*/
-MAKE_SCHEME_CALLBACK(Beam,after_line_breaking);
+MAKE_SCHEME_CALLBACK(Beam,after_line_breaking,1);
SCM
Beam::after_line_breaking (SCM smob)
{
*/
Real first_ideal = Stem::calc_stem_info (first_visible_stem (me)).idealy_f_;
Real last_ideal = Stem::calc_stem_info (last_visible_stem (me)).idealy_f_;
- Real lengthened = me->paper_l ()->get_var ("beam_lengthened");
- Real steep = me->paper_l ()->get_var ("beam_steep_slope");
+ Real lengthened = gh_scm2double (me->get_elt_property ("outer-stem-length-limit"));
+ Real steep = gh_scm2double (me->get_elt_property ("slope-limit"));
// ugh -> use commonx
Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - first_visible_stem (me)->relative_coordinate (0, X_AXIS);
Real
Beam::calc_stem_y_f (Score_element*me,Item* s, Real y, Real dy)
{
- Real thick = gh_scm2double (me->get_elt_property ("beam-thickness"));
- thick *= me->paper_l ()->get_var ("staffspace");
-
int beam_multiplicity = get_multiplicity (me);
int stem_multiplicity = (Stem::flag_i (s) - 2) >? 0;
- Real interbeam_f = me->paper_l ()->interbeam_f (beam_multiplicity);
+ SCM space_proc = me->get_elt_property ("space-function");
+ SCM space = gh_call1 (space_proc, gh_int2scm (beam_multiplicity));
+
+ Real thick = gh_scm2double (me->get_elt_property ("thickness")) ;
+ Real interbeam_f = gh_scm2double (space) ;
+
// ugh -> use commonx
Real x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS);
Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - x0;
Beam::quantise_dy_f (Score_element*me,Real dy)
{
Array<Real> a;
- for (SCM s = scm_eval2 (ly_symbol2scm ("beam-height-quants"), SCM_EOL);
- s !=SCM_EOL; s = gh_cdr (s))
+
+ SCM proc = me->get_elt_property ("height-quants");
+ SCM quants = gh_call2 (proc, me->self_scm (),
+ gh_double2scm (me->paper_l ()->get_var ("stafflinethickness")
+ / 1.0));
+
+
+ for (SCM s = quants; gh_pair_p (s); s = gh_cdr (s))
a.push (gh_scm2double (gh_car (s)));
if (a.size () <= 1)
int multiplicity = get_multiplicity (me);
Real staff_space = Staff_symbol_referencer::staff_space (me);
- SCM quants = scm_eval2 (gh_list (ly_symbol2scm ("beam-vertical-position-quants"),
- gh_int2scm (multiplicity),
- gh_double2scm (dy/staff_space),
- SCM_UNDEFINED),
- SCM_EOL);
+ Real thick = me->paper_l ()->get_var ("stafflinethickness");
+
+ SCM proc = me->get_elt_property ("vertical-position-quant-function");
+ SCM quants = scm_apply (proc,
+ me->self_scm (),
+ gh_list (gh_int2scm (multiplicity),
+ gh_double2scm (dy/staff_space),
+ gh_double2scm (thick/staff_space),
+ SCM_EOL, SCM_UNDEFINED));
+
Array<Real> a;
- for (; quants != SCM_EOL; quants = gh_cdr (quants))
+ for (; gh_pair_p (quants); quants = gh_cdr (quants))
a.push (gh_scm2double (gh_car (quants)));
if (a.size () <= 1)
/*
beams to go with one stem.
- BURP
- clean me up.
+ FIXME: clean me up.
*/
Molecule
Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
Real staffline_f = me->paper_l ()->get_var ("stafflinethickness");
int multiplicity = get_multiplicity (me);
+ SCM space_proc = me->get_elt_property ("space-function");
+ SCM space = gh_call1 (space_proc, gh_int2scm (multiplicity));
- Real interbeam_f = me->paper_l ()->interbeam_f (multiplicity);
- Real thick = gh_scm2double (me->get_elt_property ("beam-thickness"));
- thick *= me->paper_l ()->get_var ("staffspace");
+ Real thick = gh_scm2double (me->get_elt_property ("thickness")) ;
+ Real interbeam_f = gh_scm2double (space) ;
Real bdy = interbeam_f;
Real stemdx = staffline_f;
Molecule leftbeams;
Molecule rightbeams;
- // UGH
Real nw_f;
if (!Stem::first_head (here))
nw_f = 0;
- else if (Stem::type_i (here)== 1)
- nw_f = me->paper_l ()->get_var ("wholewidth");
- else if (Stem::type_i (here) == 2)
- nw_f = me->paper_l ()->get_var ("notewidth") * 0.8;
- else
- nw_f = me->paper_l ()->get_var ("quartwidth");
+ else {
+ int t = Stem::type_i (here);
+
+ SCM proc = me->get_elt_property ("flag-width-function");
+ SCM result = gh_call1 (proc, gh_int2scm (t));
+ nw_f = gh_scm2double (result);
+ }
Direction dir = Directional_element_interface::get (me);
w = w/2 <? nw_f;
Molecule a;
if (lhalfs) // generates warnings if not
- a = me->lookup_l ()->beam (dydx, w, thick);
+ a = Lookup::beam (dydx, w, thick);
a.translate (Offset (-w, -w * dydx));
for (int j = 0; j < lhalfs; j++)
{
int rwholebeams= Stem::beam_count (here,RIGHT) <? Stem::beam_count (next,LEFT) ;
Real w = next->relative_coordinate (0, X_AXIS) - here->relative_coordinate (0, X_AXIS);
- Molecule a = me->lookup_l ()->beam (dydx, w + stemdx, thick);
+ Molecule a = Lookup::beam (dydx, w + stemdx, thick);
a.translate_axis( - stemdx/2, X_AXIS);
int j = 0;
Real gap_f = 0;
- SCM gap = me->get_elt_property ("beam-gap");
+ SCM gap = me->get_elt_property ("gap");
if (gh_number_p (gap))
{
int gap_i = gh_scm2int ( (gap));
// TODO: notehead widths differ for different types
gap_f = nw_f / 2;
w -= 2 * gap_f;
- a = me->lookup_l ()->beam (dydx, w + stemdx, thick);
+ a = Lookup::beam (dydx, w + stemdx, thick);
}
for (; j < rwholebeams; j++)
w = w/2 <? nw_f;
if (rhalfs)
- a = me->lookup_l ()->beam (dydx, w, thick);
+ a = Lookup::beam (dydx, w, thick);
for (; j < rwholebeams + rhalfs; j++)
{
return leftbeams;
}
-MAKE_SCHEME_CALLBACK(Beam,brew_molecule);
+MAKE_SCHEME_CALLBACK(Beam,brew_molecule,1);
SCM
Beam::brew_molecule (SCM smob)
{
mol.translate_axis (x0
- dynamic_cast<Spanner*> (me)->get_bound (LEFT)->relative_coordinate (0, X_AXIS), X_AXIS);
- return mol.create_scheme ();
+ return mol.smobbed_copy ();
}
int
rest -> stem -> beam -> interpolate_y_position ()
*/
-Real
-Beam::rest_collision_callback (Score_element *rest, Axis a )
+MAKE_SCHEME_CALLBACK(Beam,rest_collision_callback,2);
+SCM
+Beam::rest_collision_callback (SCM element_smob, SCM axis)
{
+ Score_element *rest = unsmob_element (element_smob);
+ Axis a = (Axis) gh_scm2int (axis);
+
assert (a == Y_AXIS);
Score_element * st = unsmob_element (rest->get_elt_property ("stem"));
Score_element * stem = st;
if (!stem)
- return 0.0;
+ return gh_double2scm (0.0);
Score_element * beam = unsmob_element (stem->get_elt_property ("beam"));
if (!beam || !Beam::has_interface (beam) || !Beam::visible_stem_count (beam))
- return 0.0;
+ return gh_double2scm (0.0);
// make callback for rest from this.
Real beam_dy = 0;
Real beamy = (stem->relative_coordinate (0, X_AXIS) - x0) * dydx + beam_y;
Real staff_space = Staff_symbol_referencer::staff_space (rest);
- Real rest_dim = rest->extent (Y_AXIS)[d]*2.0 / staff_space ;
+
+
+ Real rest_dim = rest->extent (rest, Y_AXIS)[d]*2.0 / staff_space ; // refp??
Real minimum_dist
= gh_scm2double (rest->get_elt_property ("minimum-beam-collision-distance"));
if (discrete_dist < stafflines+1)
discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
- return (-d * discrete_dist);
+ return gh_double2scm (-d * discrete_dist);
}
void
Beam::set_interface (Score_element*me)
{
- Pointer_group_interface g (me, "stems");
- g.set_interface ();
-
/*
why the init? No way to tell difference between default and user
override. */