X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbeam.cc;h=4a2e752947bcf753815e151e207f1cae6f7b562d;hb=0840d13e6d695215b1c353c35eaf32bfd78b3709;hp=0cfc3e193cba6b3feea911abb09a6f9e5118d6c2;hpb=2da5c55cf0a968982223682227a0cf3b019d03a8;p=lilypond.git diff --git a/lily/beam.cc b/lily/beam.cc index 0cfc3e193c..4a2e752947 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -49,6 +49,7 @@ #include "lookup.hh" #include "main.hh" #include "misc.hh" +#include "note-column.hh" #include "note-head.hh" #include "output-def.hh" #include "pointer-group-interface.hh" @@ -141,6 +142,92 @@ Beam::get_beam_count (Grob *me) return m; } +//------ for whole note chord tremolos + +bool +Beam::whole_note_close_chord_tremolo (Grob *me) +{ + if (!scm_is_integer (me->get_property ("gap-count"))) + return false; + + extract_grob_set (me, "stems", stems); + for (vsize i = 0; i < stems.size (); i++) + if (Stem::duration_log (stems[i])) + return false; + + Grob *staff = Staff_symbol_referencer::get_staff_symbol (me); + if (staff) + { + Grob *outside_stems[2] = {Stem::extremal_heads (stems[0])[DOWN], + Stem::extremal_heads (stems.back ())[DOWN]}; + + Interval lines = Staff_symbol::line_span (staff); + for (int i = 0; i < 2; i++) + { + Real my_pos = Staff_symbol_referencer::get_position (outside_stems[i]); + if (my_pos > lines[UP] + 1) + return false; + else if (my_pos < lines[DOWN] - 1) + return false; + } + } + + return (Staff_symbol_referencer::get_position (Stem::extremal_heads (stems.back ())[DOWN]) + - Staff_symbol_referencer::get_position (Stem::extremal_heads (stems[0])[DOWN])) + < 2; +} + +MAKE_SCHEME_CALLBACK (Beam, calc_beam_gap, 1); +SCM +Beam::calc_beam_gap (SCM smob) +{ + Spanner *me = unsmob_spanner (smob); + SCM default_value = scm_cons (scm_from_double (0.8), scm_from_double (0.8)); + if (!whole_note_close_chord_tremolo (me)) + return default_value; + + Interval left = Note_column::accidental_width + (me->get_bound (RIGHT)->get_parent (X_AXIS)); + + if (left.length () > 0.4) + return scm_cons (scm_from_double (0.8), scm_from_double (1.3 + left.length ())); + else + return default_value; +} + +MAKE_SCHEME_CALLBACK (Beam, calc_springs_and_rods, 1); +SCM +Beam::calc_springs_and_rods (SCM smob) +{ + Grob *me = unsmob_grob (smob); + + if (!whole_note_close_chord_tremolo (me)) + return SCM_BOOL_F; + + return scm_call_1 (Spanner::set_spacing_rods_proc, smob); +} + +MAKE_SCHEME_CALLBACK (Beam, calc_minimum_length, 1); +SCM +Beam::calc_minimum_length (SCM smob) +{ + Spanner *me = unsmob_spanner (smob); + SCM default_value = scm_from_double (0.0); + + if (!whole_note_close_chord_tremolo (me)) + return SCM_BOOL_F; + + Interval left = Note_column::accidental_width + (me->get_bound (RIGHT)->get_parent (X_AXIS)); + + if (left.length () > 0.4) + return scm_from_double (left.length () + 4.0); + else + return default_value; +} + +//------ and everything else + MAKE_SCHEME_CALLBACK (Beam, calc_normal_stems, 1); SCM Beam::calc_normal_stems (SCM smob) @@ -197,6 +284,18 @@ Beam::calc_direction (SCM smob) dir = to_dir (stem->get_property_data ("direction")); else dir = to_dir (stem->get_property ("default-direction")); + + extract_grob_set (stem, "note-heads", heads); + /* default position of Kievan heads with beams is down + placing this here avoids warnings downstream */ + if (heads.size()) + { + if (heads[0]->get_property ("style") == ly_symbol2scm ("kievan")) + { + if (dir == CENTER) + dir = DOWN; + } + } } } @@ -284,9 +383,8 @@ Beam::calc_beaming (SCM smob) last_dir ? last_dir : this_dir, this_dir); - Direction d = LEFT; Slice new_slice; - do + for (LEFT_and_RIGHT (d)) { new_slice.set_empty (); SCM s = index_get_cell (this_beaming, d); @@ -299,7 +397,6 @@ Beam::calc_beaming (SCM smob) scm_set_car_x (s, scm_from_int (new_beam_pos)); } } - while (flip (&d) != LEFT); if (!new_slice.is_empty ()) last_int = new_slice; @@ -351,13 +448,11 @@ Beam::calc_beam_segments (SCM smob) extract_grob_set (me, "stems", stems); Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS); - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) commonx = me->get_bound (d)->common_refpoint (commonx, X_AXIS); - while (flip (&d) != LEFT); int gap_count = robust_scm2int (me->get_property ("gap-count"), 0); - Real gap_length = robust_scm2double (me->get_property ("gap"), 0.0); + Interval gap_lengths = robust_scm2interval (me->get_property ("beam-gap"), Interval (0.0, 0.0)); Position_stem_segments_map stem_segments; Real lt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness")); @@ -376,7 +471,7 @@ Beam::calc_beam_segments (SCM smob) Real stem_x = stem->relative_coordinate (commonx, X_AXIS); SCM beaming = stem->get_property ("beaming"); - do + for (LEFT_and_RIGHT (d)) { // Find the maximum and minimum beam ranks. // Given that RANKS is never reset to empty, the interval will always be @@ -415,7 +510,6 @@ Beam::calc_beam_segments (SCM smob) stem_segments[beam_rank].push_back (seg); } } - while (flip (&d) != LEFT); } Drul_array break_overshoot @@ -444,9 +538,8 @@ Beam::calc_beam_segments (SCM smob) // we are currently looking at (ie. if segs[j].dir_ == event_dir then we // are looking at that edge of the beam segment that is furthest from its // stem). - Direction event_dir = LEFT; Beam_stem_segment const &seg = segs[j]; - do + for (LEFT_and_RIGHT (event_dir)) { Beam_stem_segment const &neighbor_seg = segs[j + event_dir]; // TODO: make names clearer? --jneem @@ -515,7 +608,7 @@ Beam::calc_beam_segments (SCM smob) current.horizontal_[event_dir] += event_dir * seg.width_ / 2; if (seg.gapped_) { - current.horizontal_[event_dir] -= event_dir * gap_length; + current.horizontal_[event_dir] -= event_dir * gap_lengths[event_dir]; if (Stem::is_invisible (seg.stem_)) { @@ -528,7 +621,7 @@ Beam::calc_beam_segments (SCM smob) for (vsize k = 0; k < heads.size (); k++) current.horizontal_[event_dir] = event_dir * min (event_dir * current.horizontal_[event_dir], - - gap_length / 2 + - gap_lengths[event_dir] / 2 + event_dir * heads[k]->extent (commonx, X_AXIS)[-event_dir]); @@ -542,22 +635,19 @@ Beam::calc_beam_segments (SCM smob) current = Beam_segment (); } } - while (flip (&event_dir) != LEFT); } } SCM segments_scm = SCM_EOL; - SCM *tail = &segments_scm; - for (vsize i = 0; i < segments.size (); i++) + for (vsize i = segments.size (); i--;) { - *tail = scm_cons (scm_list_2 (scm_cons (ly_symbol2scm ("vertical-count"), - scm_from_int (segments[i].vertical_count_)), - scm_cons (ly_symbol2scm ("horizontal"), - ly_interval2scm (segments[i].horizontal_))), - SCM_EOL); - tail = SCM_CDRLOC (*tail); + segments_scm = scm_cons (scm_list_2 (scm_cons (ly_symbol2scm ("vertical-count"), + scm_from_int (segments[i].vertical_count_)), + scm_cons (ly_symbol2scm ("horizontal"), + ly_interval2scm (segments[i].horizontal_))), + segments_scm); } return segments_scm; @@ -583,10 +673,8 @@ Beam::calc_x_positions (SCM smob) { extract_grob_set (me, "stems", stems); Grob *common_x = common_refpoint_of_array (stems, me, X_AXIS); - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) x_positions[d] = me->relative_coordinate (common_x, X_AXIS); - while (flip (&d) != LEFT); } return ly_interval2scm (x_positions); } @@ -621,10 +709,8 @@ Beam::print (SCM grob) */ extract_grob_set (me, "stems", stems); Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS); - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) commonx = me->get_bound (d)->common_refpoint (commonx, X_AXIS); - while (flip (&d) != LEFT); vector segments = get_beam_segments (me); @@ -686,7 +772,7 @@ Beam::print (SCM grob) // we need two translations: the normal one and // the one of the lowest segment - int idx[] = {i, extreme}; + size_t idx[] = {i, extreme}; Real translations[2]; for (int j = 0; j < 2; j++) @@ -764,13 +850,11 @@ Beam::get_default_dir (Grob *me) for (iterof (s, stems); s != stems.end (); s++) { Interval positions = Stem::head_positions (*s); - Direction d = DOWN; - do + for (DOWN_and_UP (d)) { if (sign (positions[d]) == d) extremes[d] = d * max (d * positions[d], d * extremes[d]); } - while (flip (&d) != DOWN); } Drul_array total (0, 0); @@ -861,9 +945,7 @@ Beam::consider_auto_knees (Grob *me) if (!scm_is_number (scm)) return; - Interval_set gaps; - - gaps.set_full (); + vector forbidden_intervals; extract_grob_set (me, "normal-stems", stems); @@ -897,15 +979,17 @@ Beam::consider_auto_knees (Grob *me) } head_extents_array.push_back (head_extents); - gaps.remove_interval (head_extents); + forbidden_intervals.push_back (head_extents); } Interval max_gap; Real max_gap_len = 0.0; - for (vsize i = gaps.allowed_regions_.size () - 1; i != VPOS; i--) + vector allowed_regions + = Interval_set::interval_union (forbidden_intervals).complement ().intervals (); + for (vsize i = allowed_regions.size () - 1; i != VPOS; i--) { - Interval gap = gaps.allowed_regions_[i]; + Interval gap = allowed_regions[i]; /* the outer gaps are not knees. @@ -1133,13 +1217,12 @@ Beam::set_beaming (Grob *me, Beaming_pattern const *beaming) { extract_grob_set (me, "stems", stems); - Direction d = LEFT; for (vsize i = 0; i < stems.size (); i++) { /* Don't overwrite user settings. */ - do + for (LEFT_and_RIGHT (d)) { Grob *stem = stems[i]; SCM beaming_prop = stem->get_property ("beaming"); @@ -1161,7 +1244,6 @@ Beam::set_beaming (Grob *me, Beaming_pattern const *beaming) Stem::set_beaming (stem, count, d); } } - while (flip (&d) != LEFT); } } @@ -1243,10 +1325,8 @@ Beam::rest_collision_callback (SCM smob, SCM prev_offset) Drul_array pos (robust_scm2drul (beam->get_property ("positions"), Drul_array (0, 0))); - Direction dir = LEFT; - do + for (LEFT_and_RIGHT (dir)) pos[dir] += beam->relative_coordinate (common_y, Y_AXIS); - while (flip (&dir) != LEFT); Real staff_space = Staff_symbol_referencer::staff_space (rest); @@ -1291,51 +1371,54 @@ Beam::rest_collision_callback (SCM smob, SCM prev_offset) Real shift = d * min (d * (beam_y - d * minimum_distance - rest_dim), 0.0); shift /= staff_space; - Real rad = Staff_symbol_referencer::line_count (rest) * staff_space / 2; /* Always move discretely by half spaces */ shift = ceil (fabs (shift * 2.0)) / 2.0 * sign (shift); + Interval staff_span = Staff_symbol_referencer::staff_span (rest); + staff_span *= staff_space / 2; + /* Inside staff, move by whole spaces*/ - if ((rest_extent[d] + staff_space * shift) * d - < rad - || (rest_extent[-d] + staff_space * shift) * -d - < rad) + if (staff_span.contains (rest_extent[d] + staff_space * shift) + || staff_span.contains (rest_extent[-d] + staff_space * shift)) shift = ceil (fabs (shift)) * sign (shift); return scm_from_double (offset + staff_space * shift); } +/* + Estimate the position of a rest under a beam, + as the average position of its neighboring heads. +*/ MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Beam, pure_rest_collision_callback, 4, 1, ""); SCM Beam::pure_rest_collision_callback (SCM smob, - SCM, /* prev_offset */ SCM, /* start */ - SCM /* end */) + SCM, /* end */ + SCM prev_offset) { - Real amount = 0.0; + Real previous = robust_scm2double (prev_offset, 0.0); Grob *me = unsmob_grob (smob); Grob *stem = unsmob_grob (me->get_object ("stem")); if (!stem) - return scm_from_double (amount); + return scm_from_double (previous); Grob *beam = unsmob_grob (stem->get_object ("beam")); if (!beam || !Beam::normal_stem_count (beam) || !is_direction (beam->get_property_data ("direction"))) - return scm_from_double (amount); + return scm_from_double (previous); Real ss = Staff_symbol_referencer::staff_space (me); /* This gives the extrema of rest positions. - In general, beams are never typeset more than one staff space away - from the staff in either direction. + Even with noteheads on ledgers, beams typically remain within the staff, + and push rests at most one staff-space (2 positions) from the staff. */ Grob *staff = Staff_symbol_referencer::get_staff_symbol (me); Interval rest_max_pos = staff ? Staff_symbol::line_span (staff) : Interval (0.0, 0.0); - rest_max_pos.widen (1); - rest_max_pos *= ss / 2; + rest_max_pos.widen (2); extract_grob_set (beam, "stems", stems); vector my_stems; @@ -1356,7 +1439,7 @@ Beam::pure_rest_collision_callback (SCM smob, Grob *right; if (idx == (vsize) - 1 || my_stems.size () == 1) - return scm_from_double (amount); + return scm_from_double (previous); else if (idx == 0) left = right = my_stems[1]; else if (idx == my_stems.size () - 1) @@ -1366,15 +1449,25 @@ Beam::pure_rest_collision_callback (SCM smob, left = my_stems[idx - 1]; right = my_stems[idx + 1]; } - Direction beamdir = get_grob_direction (beam); - /* - Take the position between the two bounding head_positions, - then bound it by the minimum and maximum positions outside the staff. - 4.0 = 2.0 to get out of staff space * 2.0 for the average - */ - amount = min (max ((Stem::head_positions (left)[beamdir] + Stem::head_positions (right)[beamdir]) / 4.0, rest_max_pos[DOWN]), rest_max_pos[UP]); - return scm_from_double (amount); + /* In stems with several heads, use the one closest to the beam. */ + Direction beamdir = get_grob_direction (beam); + Real shift = min (max ( (Stem::head_positions (left)[beamdir] + + Stem::head_positions (right)[beamdir]) / 2.0, + rest_max_pos[DOWN]), + rest_max_pos[UP] + ) * ss / 2.0 + - previous; + + // So that ceil below kicks in for rests that would otherwise brush + // up against a beam quanted to a ledger line, add a bit of space + // between the beam and the rest. + shift += (0.01 * beamdir); + + /* Always move by a whole number of staff spaces */ + shift = ceil (fabs (shift / ss)) * ss * sign (shift); + + return scm_from_double (previous + shift); } bool @@ -1485,6 +1578,7 @@ ADD_INTERFACE (Beam, "auto-knee-gap " "beamed-stem-shorten " "beaming " + "beam-gap " "beam-segments " "beam-thickness " "break-overshoot " @@ -1496,7 +1590,6 @@ ADD_INTERFACE (Beam, "damping " "details " "direction " - "gap " "gap-count " "grow-direction " "inspect-quants "