source file of the GNU LilyPond music typesetter
- (c) 1999--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/
#include "beaming-pattern.hh"
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
{
*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;
}
}
}
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;
+
+ 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_ += options.measure_length_;
- bool subdivide_beams = to_boolean (context->get_property ("subdivideBeams"));
- Moment beat_length = robust_scm2moment (context->get_property ("beatLength"), Moment (1, 4));
-
- SCM grouping = context->get_property ("beatGrouping");
Moment measure_pos (0);
vector<Moment> group_starts;
vector<Moment> beat_starts;
-
+
+ SCM grouping = options.grouping_;
while (measure_pos <= infos_.back().start_moment_)
{
int count = 2;
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++)
{
- 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_);
}
{
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;
+}