X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbeam.cc;h=25f90cb6eb3e09ddbf428b817cfc2f5f2442d325;hb=07a5ed85c189a97d04c550679826dfc5eca2eb18;hp=124dc7f9c06f70fa03f4f8d58492e2e480def09b;hpb=45bae7c4e36d595cf545c85a53ff14c95bf4cf9c;p=lilypond.git diff --git a/lily/beam.cc b/lily/beam.cc index 124dc7f9c0..25f90cb6eb 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -20,7 +20,7 @@ #include // tanh. - +#include "molecule.hh" #include "directional-element-interface.hh" #include "beaming.hh" #include "beam.hh" @@ -37,26 +37,25 @@ #include "warn.hh" void -Beam::add_stem (Score_element*me, Score_element*s) +Beam::add_stem (Grob*me, Grob*s) { - Pointer_group_interface gi (me, "stems"); - gi.add_element (s); + Pointer_group_interface:: add_element(me, "stems", s); s->add_dependency (me); assert (!Stem::beam_l (s)); - s->set_elt_property ("beam", me->self_scm ()); + s->set_grob_property ("beam", me->self_scm ()); add_bound_item (dynamic_cast (me), dynamic_cast (s)); } int -Beam::get_multiplicity (Score_element*me) +Beam::get_multiplicity (Grob*me) { int m = 0; - for (SCM s = me->get_elt_property ("stems"); gh_pair_p (s); s = gh_cdr (s)) + for (SCM s = me->get_grob_property ("stems"); gh_pair_p (s); s = gh_cdr (s)) { - Score_element * sc = unsmob_element (gh_car (s)); + Grob * sc = unsmob_grob (gh_car (s)); if (Stem::has_interface (sc)) m = m >? Stem::beam_count (sc,LEFT) >? Stem::beam_count (sc,RIGHT); @@ -72,11 +71,11 @@ Beam::get_multiplicity (Score_element*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) { - Score_element * me = unsmob_element (smob); + Grob * me = unsmob_grob (smob); // Why? if (visible_stem_count (me) < 2) @@ -94,11 +93,8 @@ Beam::before_line_breaking (SCM smob) return SCM_EOL; } -/* - FIXME - */ Direction -Beam::get_default_dir (Score_element*me) +Beam::get_default_dir (Grob*me) { Drul_array total; total[UP] = total[DOWN] = 0; @@ -111,7 +107,7 @@ Beam::get_default_dir (Score_element*me) for (int i=0; i get_grob_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); /* If dir is not determined: get default */ - return to_dir (me->get_elt_property ("default-neutral-direction")); + return to_dir (me->get_grob_property ("default-neutral-direction")); } @@ -148,7 +143,7 @@ Beam::get_default_dir (Score_element*me) once stem gets cleaned-up. */ void -Beam::set_stem_directions (Score_element*me) +Beam::set_stem_directions (Grob*me) { Link_array stems =Pointer_group_interface__extract_elements (me, (Item*) 0, "stems"); @@ -156,15 +151,15 @@ Beam::set_stem_directions (Score_element*me) for (int i=0; i remove_elt_property ("dir-forced"); + Grob *s = stems[i]; + SCM force = s->remove_grob_property ("dir-forced"); if (!gh_boolean_p (force) || !gh_scm2bool (force)) Directional_element_interface ::set (s,d); } } void -Beam::auto_knees (Score_element*me) +Beam::auto_knees (Grob*me) { if (!auto_knee (me,"auto-interstaff-knee-gap", true)) auto_knee (me, "auto-knee-gap", false); @@ -178,11 +173,11 @@ Beam::auto_knees (Score_element*me) don't set, or unset autoKneeGap/autoInterstaffKneeGap. */ bool -Beam::auto_knee (Score_element*me, String gap_str, bool interstaff_b) +Beam::auto_knee (Grob*me, String gap_str, bool interstaff_b) { bool knee_b = false; int knee_y = 0; - SCM gap = me->get_elt_property (gap_str.ch_C()); + SCM gap = me->get_grob_property (gap_str.ch_C()); Direction d = Directional_element_interface::get (me); Link_array stems= @@ -219,7 +214,7 @@ Beam::auto_knee (Score_element*me, String gap_str, bool interstaff_b) + (int)calc_interstaff_dist (s, dynamic_cast (me)); Directional_element_interface::set (s,y < knee_y ? UP : DOWN); - s->set_elt_property ("dir-forced", SCM_BOOL_T); + s->set_grob_property ("dir-forced", SCM_BOOL_T); } } return knee_b; @@ -232,7 +227,7 @@ Beam::auto_knee (Score_element*me, String gap_str, bool interstaff_b) scmify forced-fraction */ void -Beam::set_stem_shorten (Score_element*m) +Beam::set_stem_shorten (Grob*m) { Spanner*me = dynamic_cast (m); if (!visible_stem_count (me)) @@ -244,9 +239,7 @@ Beam::set_stem_shorten (Score_element*m) int multiplicity = get_multiplicity (me); - // grace stems? - SCM shorten = scm_eval2 (ly_symbol2scm ("beamed-stem-shorten"), SCM_EOL); - + SCM shorten = me->get_grob_property ("beamed-stem-shorten"); if (shorten == SCM_EOL) return; @@ -268,8 +261,8 @@ Beam::set_stem_shorten (Score_element*m) Item* s = stems[i]; if (Stem::invisible_b (s)) continue; - if (gh_number_p (s->get_elt_property ("shorten"))) - s->set_elt_property ("shorten", gh_double2scm (shorten_f)); + if (gh_number_p (s->get_grob_property ("shorten"))) + s->set_grob_property ("shorten", gh_double2scm (shorten_f)); } } @@ -277,11 +270,11 @@ Beam::set_stem_shorten (Score_element*m) 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) { - Score_element * me = unsmob_element (smob); + Grob * me = unsmob_grob (smob); /* first, calculate y, dy */ Real y, dy; @@ -311,15 +304,15 @@ Beam::after_line_breaking (SCM smob) */ /* check for user-override of dy */ - SCM s = me->remove_elt_property ("height-hs"); + SCM s = me->remove_grob_property ("height-hs"); if (gh_number_p (s)) { dy = gh_scm2double (s) * half_space; } - me->set_elt_property ("height", gh_double2scm (dy)); + me->set_grob_property ("height", gh_double2scm (dy)); /* check for user-override of y */ - s = me->remove_elt_property ("y-position-hs"); + s = me->remove_grob_property ("y-position-hs"); if (gh_number_p (s)) { y = gh_scm2double (s) * half_space; @@ -350,7 +343,7 @@ Beam::after_line_breaking (SCM smob) // UGH. Y is not in staff position unit? // Ik dacht datwe daar juist van weg wilden? set_stem_length (me, y, dy); - me->set_elt_property ("y-position", gh_double2scm (y)); + me->set_grob_property ("y-position", gh_double2scm (y)); return SCM_UNSPECIFIED; } @@ -359,7 +352,7 @@ Beam::after_line_breaking (SCM smob) See Documentation/tex/fonts.doc */ void -Beam::calc_default_position_and_height (Score_element*me,Real* y, Real* dy) +Beam::calc_default_position_and_height (Grob*me,Real* y, Real* dy) { *y = 0; *dy = 0; @@ -397,17 +390,16 @@ Beam::calc_default_position_and_height (Score_element*me,Real* y, Real* dy) } bool -Beam::suspect_slope_b (Score_element*me, Real y, Real dy) +Beam::suspect_slope_b (Grob*me, Real y, Real dy) { /* first, calculate y, dy */ /* steep slope running against lengthened stem is suspect */ - Real ss = me->paper_l ()->get_var ("staffspace"); 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 = gh_scm2double (me->get_elt_property ("outer-stem-length-limit")) * ss; - Real steep = gh_scm2double (me->get_elt_property ("slope-limit")); + Real lengthened = gh_scm2double (me->get_grob_property ("outer-stem-length-limit")); + Real steep = gh_scm2double (me->get_grob_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); @@ -427,9 +419,9 @@ Beam::suspect_slope_b (Score_element*me, Real y, Real dy) corresponds with some tables in [Wanske] */ Real -Beam::calc_slope_damping_f (Score_element*me,Real dy) +Beam::calc_slope_damping_f (Grob*me,Real dy) { - SCM damp = me->get_elt_property ("damping"); + SCM damp = me->get_grob_property ("damping"); int damping = gh_scm2int (damp); if (damping) @@ -445,18 +437,16 @@ Beam::calc_slope_damping_f (Score_element*me,Real dy) } Real -Beam::calc_stem_y_f (Score_element*me,Item* s, Real y, Real dy) +Beam::calc_stem_y_f (Grob*me,Item* s, Real y, Real dy) { int beam_multiplicity = get_multiplicity (me); int stem_multiplicity = (Stem::flag_i (s) - 2) >? 0; - Real staffspace = me->paper_l ()->get_var ("staffspace"); - - SCM space_proc = me->get_elt_property ("beam-space-function"); + SCM space_proc = me->get_grob_property ("space-function"); SCM space = gh_call1 (space_proc, gh_int2scm (beam_multiplicity)); - Real thick = gh_scm2double (me->get_elt_property ("beam-thickness")) *staffspace; - Real interbeam_f = gh_scm2double (space) * staffspace; + Real thick = gh_scm2double (me->get_grob_property ("thickness")) ; + Real interbeam_f = gh_scm2double (space) ; // ugh -> use commonx Real x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS); @@ -486,7 +476,7 @@ Beam::calc_stem_y_f (Score_element*me,Item* s, Real y, Real dy) } Real -Beam::check_stem_length_f (Score_element*me,Real y, Real dy) +Beam::check_stem_length_f (Grob*me,Real y, Real dy) { Real shorten = 0; Real lengthen = 0; @@ -524,7 +514,7 @@ Beam::check_stem_length_f (Score_element*me,Real y, Real dy) stem directions and length should set to relative to the chord's position of the beam. */ void -Beam::set_stem_length (Score_element*me,Real y, Real dy) +Beam::set_stem_length (Grob*me,Real y, Real dy) { Real half_space = Staff_symbol_referencer::staff_space (me)/2; Link_array stems= @@ -553,11 +543,17 @@ Beam::set_stem_length (Score_element*me,Real y, Real dy) + n * staff_space */ Real -Beam::quantise_dy_f (Score_element*me,Real dy) +Beam::quantise_dy_f (Grob*me,Real dy) { Array a; - for (SCM s = scm_eval2 (ly_symbol2scm ("beam-height-quants"), SCM_EOL); - s !=SCM_EOL; s = gh_cdr (s)) + + SCM proc = me->get_grob_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) @@ -582,20 +578,25 @@ Beam::quantise_dy_f (Score_element*me,Real dy) if extend_b then stems must *not* get shorter */ Real -Beam::quantise_y_f (Score_element*me,Real y, Real dy, int quant_dir) +Beam::quantise_y_f (Grob*me,Real y, Real dy, int quant_dir) { 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_grob_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 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) @@ -613,10 +614,10 @@ Beam::quantise_y_f (Score_element*me,Real y, Real dy, int quant_dir) } void -Beam::set_beaming (Score_element*me,Beaming_info_list *beaming) +Beam::set_beaming (Grob*me,Beaming_info_list *beaming) { - Link_array stems= - Pointer_group_interface__extract_elements (me, (Score_element*)0, "stems"); + Link_array stems= + Pointer_group_interface__extract_elements (me, (Grob*)0, "stems"); Direction d = LEFT; for (int i=0; i < stems.size(); i++) @@ -635,11 +636,10 @@ Beam::set_beaming (Score_element*me,Beaming_info_list *beaming) /* 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) +Beam::stem_beams (Grob*me,Item *here, Item *next, Item *prev) { // ugh -> use commonx if ((next && !(next->relative_coordinate (0, X_AXIS) > here->relative_coordinate (0, X_AXIS))) || @@ -648,13 +648,12 @@ 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); - Real staffspace =me->paper_l ()->get_var ("staffspace"); - SCM space_proc = me->get_elt_property ("beam-space-function"); + SCM space_proc = me->get_grob_property ("space-function"); SCM space = gh_call1 (space_proc, gh_int2scm (multiplicity)); - Real thick = gh_scm2double (me->get_elt_property ("beam-thickness")) *staffspace; - Real interbeam_f = gh_scm2double (space) * staffspace; + Real thick = gh_scm2double (me->get_grob_property ("thickness")) ; + Real interbeam_f = gh_scm2double (space) ; Real bdy = interbeam_f; Real stemdx = staffline_f; @@ -663,24 +662,21 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev) Real dx = visible_stem_count (me) ? last_visible_stem (me)->relative_coordinate (0, X_AXIS) - first_visible_stem (me)->relative_coordinate (0, X_AXIS) : 0.0; - Real dy = gh_scm2double (me->get_elt_property ("height")); + Real dy = gh_scm2double (me->get_grob_property ("height")); Real dydx = dy && dx ? dy/dx : 0; Molecule leftbeams; Molecule rightbeams; - /* - UGH: make a property of this. - */ Real nw_f; if (!Stem::first_head (here)) nw_f = 0; else { int t = Stem::type_i (here); - SCM proc = me->get_elt_property ("beam-flag-width-function"); + SCM proc = me->get_grob_property ("flag-width-function"); SCM result = gh_call1 (proc, gh_int2scm (t)); - nw_f = gh_scm2double (result) * staffspace; + nw_f = gh_scm2double (result); } @@ -699,7 +695,7 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev) w = w/2 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++) { @@ -715,12 +711,12 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev) int rwholebeams= Stem::beam_count (here,RIGHT) 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_grob_property ("gap"); if (gh_number_p (gap)) { int gap_i = gh_scm2int ( (gap)); @@ -735,7 +731,7 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev) // 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++) @@ -747,7 +743,7 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev) w = w/2 lookup_l ()->beam (dydx, w, thick); + a = Lookup::beam (dydx, w, thick); for (; j < rwholebeams + rhalfs; j++) { @@ -766,14 +762,14 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev) return leftbeams; } -MAKE_SCHEME_CALLBACK(Beam,brew_molecule); +MAKE_SCHEME_CALLBACK(Beam,brew_molecule,1); SCM Beam::brew_molecule (SCM smob) { - Score_element * me =unsmob_element (smob); + Grob * me =unsmob_grob (smob); Molecule mol; - if (!gh_pair_p (me->get_elt_property ("stems"))) + if (!gh_pair_p (me->get_grob_property ("stems"))) return SCM_EOL; Real x0,dx; Link_arraystems = @@ -791,9 +787,9 @@ Beam::brew_molecule (SCM smob) } - Real dy = gh_scm2double (me->get_elt_property ("height")); + Real dy = gh_scm2double (me->get_grob_property ("height")); Real dydx = dy && dx ? dy/dx : 0; - Real y = gh_scm2double (me->get_elt_property ("y-position")); + Real y = gh_scm2double (me->get_grob_property ("y-position")); for (int j=0; j (me)->get_bound (LEFT)->relative_coordinate (0, X_AXIS), X_AXIS); - return mol.create_scheme (); + return mol.smobbed_copy (); } int -Beam::forced_stem_count (Score_element*me) +Beam::forced_stem_count (Grob*me) { Link_arraystems = Pointer_group_interface__extract_elements ( me, (Item*) 0, "stems"); @@ -840,7 +836,7 @@ Beam::forced_stem_count (Score_element*me) use filter and standard list functions. */ int -Beam::visible_stem_count (Score_element*me) +Beam::visible_stem_count (Grob*me) { Link_arraystems = Pointer_group_interface__extract_elements (me, (Item*) 0, "stems"); @@ -854,7 +850,7 @@ Beam::visible_stem_count (Score_element*me) } Item* -Beam::first_visible_stem(Score_element*me) +Beam::first_visible_stem(Grob*me) { Link_arraystems = Pointer_group_interface__extract_elements ( me, (Item*) 0, "stems"); @@ -868,7 +864,7 @@ Beam::first_visible_stem(Score_element*me) } Item* -Beam::last_visible_stem(Score_element*me) +Beam::last_visible_stem(Grob*me) { Link_arraystems = Pointer_group_interface__extract_elements ( me, (Item*) 0, "stems"); @@ -890,18 +886,22 @@ Beam::last_visible_stem(Score_element*me) 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) { + Grob *rest = unsmob_grob (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; + Grob * st = unsmob_grob (rest->get_grob_property ("stem")); + Grob * stem = st; if (!stem) - return 0.0; - Score_element * beam = unsmob_element (stem->get_elt_property ("beam")); + return gh_double2scm (0.0); + Grob * beam = unsmob_grob (stem->get_grob_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; @@ -909,11 +909,11 @@ Beam::rest_collision_callback (Score_element *rest, Axis a ) // todo: make sure this calced already. - SCM s = beam->get_elt_property ("height"); + SCM s = beam->get_grob_property ("height"); if (gh_number_p (s)) beam_dy = gh_scm2double (s); - s = beam->get_elt_property ("y-position"); + s = beam->get_grob_property ("y-position"); if (gh_number_p (s)) beam_y = gh_scm2double (s); @@ -926,10 +926,12 @@ Beam::rest_collision_callback (Score_element *rest, Axis a ) 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")); + = gh_scm2double (rest->get_grob_property ("minimum-beam-collision-distance")); Real dist = minimum_dist + -d * (beamy - rest_dim) >? 0; @@ -942,26 +944,23 @@ Beam::rest_collision_callback (Score_element *rest, Axis a ) 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); } bool -Beam::has_interface (Score_element*me) +Beam::has_interface (Grob*me) { return me->has_interface (ly_symbol2scm ("beam-interface")); } void -Beam::set_interface (Score_element*me) +Beam::set_interface (Grob*me) { - Pointer_group_interface g (me, "stems"); - g.set_interface (); - /* why the init? No way to tell difference between default and user override. */ - me->set_elt_property ("height", gh_int2scm (0)); // ugh. - me->set_elt_property ("y-position" ,gh_int2scm (0)); + me->set_grob_property ("height", gh_int2scm (0)); // ugh. + me->set_grob_property ("y-position" ,gh_int2scm (0)); me->set_interface (ly_symbol2scm("beam-interface")); }