X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbeam.cc;h=9d5d5aa212560f6c133cd4b8e03d40f282312ed0;hb=767e42120b317f7ab2ca3e7a079bc4c2a0f7a776;hp=b25a48ada569b9b115fd618b43aa30fa2d1b666b;hpb=f1b323b28c4ed9e06193ed9a0447d48423fb05d5;p=lilypond.git diff --git a/lily/beam.cc b/lily/beam.cc index b25a48ada5..9d5d5aa212 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2005 Han-Wen Nienhuys + (c) 1997--2006 Han-Wen Nienhuys Jan Nieuwenhuizen */ @@ -25,18 +25,20 @@ */ #include "beam.hh" -#include "interval-set.hh" -#include "directional-element-interface.hh" + #include "beaming.hh" -#include "misc.hh" +#include "directional-element-interface.hh" +#include "international.hh" +#include "interval-set.hh" +#include "item.hh" #include "least-squares.hh" -#include "stem.hh" -#include "output-def.hh" #include "lookup.hh" +#include "misc.hh" +#include "output-def.hh" #include "pointer-group-interface.hh" -#include "staff-symbol-referencer.hh" -#include "item.hh" #include "spanner.hh" +#include "staff-symbol-referencer.hh" +#include "stem.hh" #include "warn.hh" #if DEBUG_QUANTING @@ -89,7 +91,7 @@ Beam::get_beam_count (Grob *me) int m = 0; extract_grob_set (me, "stems", stems); - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *stem = stems[i]; m = max (m, (Stem::beam_multiplicity (stem).length () + 1)); @@ -138,16 +140,22 @@ Beam::calc_direction (SCM smob) me->suicide (); return SCM_UNSPECIFIED; } - else + else { - d = to_dir (stems[0]->get_property ("default-direction")); + Grob *stem = first_visible_stem (me); + + /* + ugh: stems[0] case happens for chord tremolo. + */ + d = to_dir ((stem ? stem : stems[0])->get_property ("default-direction")); } } - if (count >= 1) { - d = get_default_dir (me); + if (!d) + d = get_default_dir (me); + consider_auto_knees (me); } @@ -216,7 +224,7 @@ Beam::calc_beaming (SCM smob) SCM last_beaming = scm_cons (SCM_EOL, scm_list_1 (scm_from_int (0))); Direction last_dir = CENTER; - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *this_stem = stems[i]; SCM this_beaming = this_stem->get_property ("beaming"); @@ -298,7 +306,7 @@ Beam::print (SCM grob) else { x0 = stems[0]->relative_coordinate (xcommon, X_AXIS); - dx = stems.top ()->relative_coordinate (xcommon, X_AXIS) - x0; + dx = stems.back ()->relative_coordinate (xcommon, X_AXIS) - x0; } SCM posns = me->get_property ("quantized-positions"); @@ -328,7 +336,7 @@ Beam::print (SCM grob) Stencil the_beam; Real lt = me->layout ()->get_dimension (ly_symbol2scm ("linethickness")); - for (int i = 0; i <= stems.size (); i++) + for (vsize i = 0; i <= stems.size (); i++) { Grob *stem = (i < stems.size ()) ? stems[i] : 0; @@ -344,25 +352,25 @@ Beam::print (SCM grob) SCM left = (i > 0) ? scm_cdr (last_beaming) : SCM_EOL; SCM right = stem ? scm_car (this_beaming) : SCM_EOL; - Array full_beams; - Array lfliebertjes; - Array rfliebertjes; + std::vector full_beams; + std::vector lfliebertjes; + std::vector rfliebertjes; for (SCM s = left; scm_is_pair (s); s = scm_cdr (s)) { int b = scm_to_int (scm_car (s)); if (scm_c_memq (scm_car (s), right) != SCM_BOOL_F) - full_beams.push (b); + full_beams.push_back (b); else - lfliebertjes.push (b); + lfliebertjes.push_back (b); } for (SCM s = right; scm_is_pair (s); s = scm_cdr (s)) { int b = scm_to_int (scm_car (s)); if (scm_c_memq (scm_car (s), left) == SCM_BOOL_F) - rfliebertjes.push (b); + rfliebertjes.push_back (b); } Drul_array break_overshoot @@ -393,13 +401,13 @@ Beam::print (SCM grob) gap_count = scm_to_int (me->get_property ("gap-count")); gapped = Lookup::beam (slope, w - 2 * gap_length, thick, blot); - full_beams.sort (default_compare); + vector_sort (full_beams, default_compare); if (stem_dir == UP) full_beams.reverse (); } int k = 0; - for (int j = full_beams.size (); j--;) + for (vsize j = full_beams.size (); j--;) { Stencil b (whole); @@ -458,7 +466,7 @@ Beam::print (SCM grob) Stencil rhalf = Lookup::beam (slope, rw, thick, blot); Stencil lhalf = Lookup::beam (slope, lw, thick, blot); - for (int j = lfliebertjes.size (); j--;) + for (vsize j = lfliebertjes.size (); j--;) { Stencil b (lhalf); b.translate_axis (last_xposn - x0 - last_stem_width /2, @@ -468,7 +476,7 @@ Beam::print (SCM grob) Y_AXIS); the_beam.add_stencil (b); } - for (int j = rfliebertjes.size (); j--;) + for (vsize j = rfliebertjes.size (); j--;) { Stencil b (rhalf); b.translate_axis (xposn - x0 - rw + stem_width / 2, X_AXIS); @@ -498,7 +506,7 @@ Beam::print (SCM grob) should be switchable for those who want to twiddle with the parameters. */ - String str; + std::string str; SCM properties = Font_interface::text_font_alist_chain (me); Direction stem_dir = stems.size () ? to_dir (stems[0]->get_property ("direction")) : UP; @@ -524,7 +532,7 @@ Beam::get_default_dir (Grob *me) extract_grob_set (me, "stems", stems); - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *s = stems[i]; Direction stem_dir = CENTER; @@ -545,12 +553,14 @@ Beam::get_default_dir (Grob *me) } Direction dir = CENTER; - - if (Direction d = (Direction) sign (count[UP] - count[DOWN])) + Direction d = CENTER; + if ((d = (Direction) sign (count[UP] - count[DOWN]))) dir = d; - else if (Direction d = (Direction) sign (total[UP] / count[UP] - total[DOWN]/count[DOWN])) + else if (count[UP] + && count[DOWN] + && (d = (Direction) sign (total[UP] / count[UP] - total[DOWN]/count[DOWN]))) dir = d; - else if (Direction d = (Direction) sign (total[UP] - total[DOWN])) + else if ((d = (Direction) sign (total[UP] - total[DOWN]))) dir = d; else dir = to_dir (me->get_property ("neutral-direction")); @@ -566,7 +576,7 @@ Beam::set_stem_directions (Grob *me, Direction d) { extract_grob_set (me, "stems", stems); - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *s = stems[i]; @@ -604,8 +614,8 @@ Beam::consider_auto_knees (Grob *me) Grob *common = common_refpoint_of_array (stems, me, Y_AXIS); Real staff_space = Staff_symbol_referencer::staff_space (me); - Array head_extents_array; - for (int i = 0; i < stems.size (); i++) + std::vector head_extents_array; + for (vsize i = 0; i < stems.size (); i++) { Grob *stem = stems[i]; if (Stem::is_invisible (stem)) @@ -631,7 +641,7 @@ Beam::consider_auto_knees (Grob *me) head_extents[-stemdir] = -stemdir * infinity_f; } } - head_extents_array.push (head_extents); + head_extents_array.push_back (head_extents); gaps.remove_interval (head_extents); } @@ -639,7 +649,7 @@ Beam::consider_auto_knees (Grob *me) Interval max_gap; Real max_gap_len = 0.0; - for (int i = gaps.allowed_regions_.size () -1; i >= 0; i--) + for (vsize i = gaps.allowed_regions_.size () -1; i != VPOS ;i--) { Interval gap = gaps.allowed_regions_[i]; @@ -666,7 +676,7 @@ Beam::consider_auto_knees (Grob *me) if (max_gap_len > threshold) { int j = 0; - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *stem = stems[i]; if (Stem::is_invisible (stem)) @@ -775,7 +785,7 @@ Beam::calc_least_squares_positions (SCM smob, SCM posns) if (count < 1) return ly_interval2scm (pos); - Array x_posns; + std::vector x_posns; extract_grob_set (me, "stems", stems); Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS); Grob *commony = common_refpoint_of_array (stems, me, Y_AXIS); @@ -791,12 +801,12 @@ Beam::calc_least_squares_positions (SCM smob, SCM posns) + lvs->relative_coordinate (commony, Y_AXIS) - my_y); Real x0 = first_visible_stem (me)->relative_coordinate (commonx, X_AXIS); - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *s = stems[i]; Real x = s->relative_coordinate (commonx, X_AXIS) - x0; - x_posns.push (x); + x_posns.push_back (x); } Real dx = last_visible_stem (me)->relative_coordinate (commonx, X_AXIS) - x0; @@ -835,13 +845,13 @@ Beam::calc_least_squares_positions (SCM smob, SCM posns) } else { - Array ideals; - for (int i = 0; i < stems.size (); i++) + std::vector ideals; + for (vsize i = 0; i < stems.size (); i++) { Grob *s = stems[i]; if (Stem::is_invisible (s)) continue; - ideals.push (Offset (x_posns[i], + ideals.push_back (Offset (x_posns[i], Stem::get_stem_info (s).ideal_y_ + s->relative_coordinate (commony, Y_AXIS) - my_y)); @@ -881,7 +891,7 @@ Beam::shift_region_to_valid (SCM grob, SCM posns) /* Code dup. */ - Array x_posns; + std::vector x_posns; extract_grob_set (me, "stems", stems); Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS); Grob *commony = common_refpoint_of_array (stems, me, Y_AXIS); @@ -892,12 +902,12 @@ Beam::shift_region_to_valid (SCM grob, SCM posns) return posns; Real x0 = fvs->relative_coordinate (commonx, X_AXIS); - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *s = stems[i]; Real x = s->relative_coordinate (commonx, X_AXIS) - x0; - x_posns.push (x); + x_posns.push_back (x); } Grob *lvs = last_visible_stem (me); @@ -921,7 +931,7 @@ Beam::shift_region_to_valid (SCM grob, SCM posns) */ Interval feasible_left_point; feasible_left_point.set_full (); - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *s = stems[i]; if (Stem::is_invisible (s)) @@ -1123,7 +1133,7 @@ Beam::set_stem_lengths (SCM smob) Real xl = fvs ? fvs->relative_coordinate (common[X_AXIS], X_AXIS) : 0.0; Real xr = lvs ? lvs->relative_coordinate (common[X_AXIS], X_AXIS) : 0.0; - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *s = stems[i]; if (Stem::is_invisible (s)) @@ -1153,7 +1163,7 @@ Beam::set_beaming (Grob *me, Beaming_info_list const *beaming) extract_grob_set (me, "stems", stems); Direction d = LEFT; - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { /* Don't overwrite user settings. @@ -1184,7 +1194,7 @@ Beam::forced_stem_count (Grob *me) extract_grob_set (me, "stems", stems); int f = 0; - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { Grob *s = stems[i]; @@ -1208,7 +1218,7 @@ Beam::visible_stem_count (Grob *me) { extract_grob_set (me, "stems", stems); int c = 0; - for (int i = stems.size (); i--;) + for (vsize i = stems.size (); i--;) { if (!Stem::is_invisible (stems[i])) c++; @@ -1221,7 +1231,7 @@ Beam::first_visible_stem (Grob *me) { extract_grob_set (me, "stems", stems); - for (int i = 0; i < stems.size (); i++) + for (vsize i = 0; i < stems.size (); i++) { if (!Stem::is_invisible (stems[i])) return stems[i]; @@ -1234,7 +1244,7 @@ Beam::last_visible_stem (Grob *me) { extract_grob_set (me, "stems", stems); - for (int i = stems.size (); i--;) + for (vsize i = stems.size (); i--;) { if (!Stem::is_invisible (stems[i])) return stems[i]; @@ -1349,7 +1359,7 @@ Beam::is_knee (Grob *me) bool knee = false; int d = 0; extract_grob_set (me, "stems", stems); - for (int i = stems.size (); i--;) + for (vsize i = stems.size (); i--;) { Direction dir = get_grob_direction (stems[i]); if (d && d != dir) @@ -1371,7 +1381,7 @@ Beam::get_direction_beam_count (Grob *me, Direction d) extract_grob_set (me, "stems", stems); int bc = 0; - for (int i = stems.size (); i--;) + for (vsize i = stems.size (); i--;) { /* Should we take invisible stems into account?