X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbeaming-pattern.cc;h=37ef6ee614e76cf52629e7ebb073a0c88f536fc4;hb=2a00c69a012d4ccaf24a036bdb5ac9ea43fb9604;hp=ca9970dd8901324dbfc02d0ca21dfbb8f489ce91;hpb=74d1723b4867e72387e7888cd52e3eee87409123;p=lilypond.git diff --git a/lily/beaming-pattern.cc b/lily/beaming-pattern.cc index ca9970dd89..37ef6ee614 100644 --- a/lily/beaming-pattern.cc +++ b/lily/beaming-pattern.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1999--2006 Han-Wen Nienhuys + (c) 1999--2007 Han-Wen Nienhuys */ #include "beaming-pattern.hh" @@ -25,6 +25,16 @@ Beam_rhythmic_element::Beam_rhythmic_element (Moment m, int 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) { @@ -56,10 +66,9 @@ Beaming_pattern::best_splitpoint_index (bool *at_boundary) const *at_boundary = false; - int min_factor_twos = 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_; @@ -72,11 +81,11 @@ Beaming_pattern::best_splitpoint_index (bool *at_boundary) const */ - int factor_2s = count_factor_twos (dt.den ()); + dt /= infos_[i].beat_length_; - if (factor_2s < min_factor_twos) + if (dt.den () < min_den) { - min_factor_twos = factor_2s; + min_den = dt.den (); min_index = i; } } @@ -97,26 +106,34 @@ Beaming_pattern::beam_extend_count (Direction d) const } void -Beaming_pattern::beamify (Context *context) +Beaming_pattern::de_grace () +{ + for (vsize i = 0; i < infos_.size (); i ++) + { + infos_[i].de_grace (); + } +} + +void +Beaming_pattern::beamify (Beaming_options const &options) { if (infos_.size () <= 1) return; - - 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_.grace_part_) + de_grace (); if (infos_[0].start_moment_ < Moment (0)) - for (vsize i = 0; i < infos_.size(); i++) - infos_[i].start_moment_ += measure_length; + for (vsize i = 0; i < infos_.size (); i++) + infos_[i].start_moment_ += options.measure_length_; - SCM grouping = context->get_property ("beatGrouping"); Moment measure_pos (0); vector group_starts; vector beat_starts; - - while (measure_pos <= infos_.back().start_moment_) + + SCM grouping = options.grouping_; + while (measure_pos <= infos_.back ().start_moment_) { int count = 2; if (scm_is_pair (grouping)) @@ -128,29 +145,32 @@ Beaming_pattern::beamify (Context *context) group_starts.push_back (measure_pos); for (int i = 0; i < count; i++) { - beat_starts.push_back (measure_pos + beat_length * i); + beat_starts.push_back (measure_pos + options.beat_length_ * i); } - measure_pos += beat_length * count; + measure_pos += options.beat_length_ * count; } vsize j = 0; vsize k = 0; - for (vsize i = 0; i < infos_.size(); i++) + for (vsize i = 0; i < infos_.size (); i++) { - while (j < group_starts.size() - 1 + while (j + 1 < group_starts.size () && group_starts[j+1] <= infos_[i].start_moment_) j++; - infos_[i].group_start_ = group_starts[j]; - - while (k < beat_starts.size() - 1 + if (j < group_starts.size ()) + infos_[i].group_start_ = group_starts[j]; + + infos_[i].beat_length_ = options.beat_length_; + while (k + 1 < beat_starts.size () && beat_starts[k+1] <= infos_[i].start_moment_) k++; - infos_[i].beat_start_ = beat_starts[k]; + if (k < beat_starts.size ()) + infos_[i].beat_start_ = beat_starts[k]; } - beamify (subdivide_beams); + beamify (options.subdivide_beams_); } @@ -212,3 +232,18 @@ Beaming_pattern::beamlet_count (int i, Direction d) const { return infos_.at (i).beam_count_drul_[d]; } + +void +Beaming_options::from_context (Context *context) +{ + grouping_ = context->get_property ("beatGrouping"); + subdivide_beams_ = to_boolean (context->get_property ("subdivideBeams")); + beat_length_ = robust_scm2moment (context->get_property ("beatLength"), Moment (1, 4)); + measure_length_ = robust_scm2moment (context->get_property ("measureLength"), Moment (1, 4)); +} + +Beaming_options::Beaming_options () +{ + grouping_ = SCM_EOL; + subdivide_beams_ = false; +}