X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbeaming-pattern.cc;h=092c6b673d39f9509b87d997961796553e82c6fd;hb=ce593a5d9614d463ac0255eac17ceb50ce3bcc29;hp=c6fba3a5a5b0589183bc3fdda33420ab7b0ab8bd;hpb=7693db10b018da89a3123cb4c9e21e3956638c56;p=lilypond.git diff --git a/lily/beaming-pattern.cc b/lily/beaming-pattern.cc index c6fba3a5a5..092c6b673d 100644 --- a/lily/beaming-pattern.cc +++ b/lily/beaming-pattern.cc @@ -24,6 +24,30 @@ Beam_rhythmic_element::Beam_rhythmic_element (Moment m, int i) beam_count_drul_[RIGHT] = i; } + +void +Beam_rhythmic_element::de_grace () +{ + if (start_moment_.grace_part_) + { + start_moment_.main_part_ = start_moment_.grace_part_; + start_moment_.grace_part_ = 0; + } +} + +int +count_factor_twos (int x) +{ + int c = 0; + while (x && x % 2 == 0) + { + x /= 2; + c ++; + } + + return c; +} + int Beaming_pattern::best_splitpoint_index (bool *at_boundary) const { @@ -42,16 +66,27 @@ Beaming_pattern::best_splitpoint_index (bool *at_boundary) const *at_boundary = false; - int min_denominator = INT_MAX; + int min_den = INT_MAX; int min_index = -1; Moment beat_pos; for (vsize i = 1; i < infos_.size (); i++) { - Moment dt = infos_[i].start_moment_ - infos_[i].beat_start_; - if (dt.den () < min_denominator) + Moment dt = infos_[i].start_moment_ - infos_[i].beat_start_; + + /* + This is a kludge, for the most common case of 16th, 32nds + etc. What should really happen is that \times x/y should + locally introduce a voice-specific beat duration. (or + perhaps: a list of beat durations for nested tuplets.) + + */ + + dt /= infos_[i].beat_length_; + + if (dt.den () < min_den) { - min_denominator = dt.den (); + min_den = dt.den (); min_index = i; } } @@ -71,14 +106,31 @@ Beaming_pattern::beam_extend_count (Direction d) const return min (thisbeam.beam_count_drul_[-d], next.beam_count_drul_[d]); } +void +Beaming_pattern::de_grace () +{ + for (vsize i = 0; i < infos_.size (); i ++) + { + infos_[i].de_grace (); + } +} + void Beaming_pattern::beamify (Context *context) { if (infos_.size () <= 1) return; + + if (infos_[0].start_moment_.grace_part_) + de_grace (); bool subdivide_beams = to_boolean (context->get_property ("subdivideBeams")); Moment beat_length = robust_scm2moment (context->get_property ("beatLength"), Moment (1, 4)); + Moment measure_length = robust_scm2moment (context->get_property ("measureLength"), Moment (1, 4)); + + if (infos_[0].start_moment_ < Moment (0)) + for (vsize i = 0; i < infos_.size(); i++) + infos_[i].start_moment_ += measure_length; SCM grouping = context->get_property ("beatGrouping"); Moment measure_pos (0); @@ -107,13 +159,13 @@ Beaming_pattern::beamify (Context *context) vsize k = 0; for (vsize i = 0; i < infos_.size(); i++) { - while (j < group_starts.size()-1 + while (j < group_starts.size() - 1 && group_starts[j+1] <= infos_[i].start_moment_) j++; infos_[i].group_start_ = group_starts[j]; - - while (k < beat_starts.size()-1 + infos_[i].beat_length_ = beat_length; + while (k < beat_starts.size() - 1 && beat_starts[k+1] <= infos_[i].start_moment_) k++;