+ if ((flag_directions[i] == CENTER) && (flag_directions[i - 1] == LEFT))
+ flag_directions[i] = RIGHT;
+ if ((flag_directions[i] == CENTER) && (flag_directions[i + 1] == RIGHT))
+ flag_directions[i] = LEFT;
+ }
+
+ // Set the count on each side of the stem
+ // We need to run this code twice to make both the
+ // left and the right counts work properly
+ for (int i = 0; i < 2; i++)
+ for (vsize i = 1; i < infos_.size () - 1; i++)
+ {
+ Direction non_flag_dir = -flag_directions[i];
+ if (non_flag_dir)
+ {
+ int count =
+ (infos_[i + 1].rhythmic_importance_ < 0 &&
+ options.subdivide_beams_)
+ // we're left of a subdivision
+ ? (i != infos_.size () - 2)
+ // respect the beam count for shortened beams ...
+ ? max (beam_count_for_rhythmic_position (i + 1),
+ beam_count_for_length (remaining_length (i + 1)))
+ // ... except if there's only one trailing stem
+ : beam_count_for_rhythmic_position (i + 1)
+
+ // we're at any other stem
+ : min (min (infos_[i].count (non_flag_dir),
+ infos_[i + non_flag_dir].count (-non_flag_dir)),
+ infos_[i - non_flag_dir].count (non_flag_dir));
+
+ // Ensure at least one beam is left, even for groups longer than 1/8
+ count = max (count, 1);
+
+ infos_[i].beam_count_drul_[non_flag_dir] = count;
+ }
+ }
+}
+
+/*
+ Set the tuplet start moment as necessary
+*/
+void
+update_tuplet (Moment start_moment, Rational factor, Moment *tuplet_start_moment)
+{
+ int tuplet_number = (int) factor.den ();
+ if ((tuplet_number > 1) && (tuplet_start_moment->num () < 0))
+ *tuplet_start_moment = start_moment;
+ else if (tuplet_number == 1)
+ *tuplet_start_moment = Moment (-1, 1);
+}
+
+/*
+ Get the group start position, the next group starting position, and the
+ next beat starting position, given start_moment, base_moment,
+ grouping, and factor
+*/
+void
+find_location (SCM grouping, Moment base_moment, Moment start_moment,
+ Rational factor, Moment *group_pos, Moment *next_group_pos,
+ Moment *next_beat_pos)
+{
+ *group_pos = Moment (0);
+ *next_group_pos = Moment (0);
+ *next_beat_pos = base_moment;
+
+ while (*next_beat_pos <= start_moment)
+ *next_beat_pos += base_moment;
+
+ while (*next_group_pos < *next_beat_pos)
+ {
+ I64 group_count = 1; //default -- 1 base moments in a beam
+ if (scm_is_pair (grouping))