summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrs Liska <ul@openlilylib.org>2015-12-23 22:07:22 +0100
committerUrs Liska <ul@openlilylib.org>2015-12-28 17:08:34 +0100
commit29022d7b0d1d1a52d221def82511d4d393c52e8d (patch)
tree83570794b4278c43e82f4a4831e30e254130a3ab
parent73d4697d0b91c1743e2d3dc31e1c4e87ce03da7b (diff)
4704: Improve beam subdivision beaming count
Calculates the remaining length of a beam. If this is shorter than the regular value at the subdivision point more beams are used. (Example: subdivision at 1/8 -> one beam left. Remaing notes on the beam: 3/32 -> two beams left.) However, if only one stem is left after the subdivision this isn't applied in order to have a visual separation. In this case the default subdivision beam count is used.
-rw-r--r--lily/beaming-pattern.cc48
-rw-r--r--lily/include/beaming-pattern.hh3
2 files changed, 42 insertions, 9 deletions
diff --git a/lily/beaming-pattern.cc b/lily/beaming-pattern.cc
index 135438e063..a889990525 100644
--- a/lily/beaming-pattern.cc
+++ b/lily/beaming-pattern.cc
@@ -166,15 +166,26 @@ Beaming_pattern::beamify (Beaming_options const &options)
Direction non_flag_dir = -flag_directions[i];
if (non_flag_dir)
{
- int importance = infos_[i + 1].rhythmic_importance_;
- int start_dur = intlog2(infos_[i+1].start_moment_.main_part_.den());
- int count = (importance < 0 && options.subdivide_beams_)
- ? max(start_dur,3)-2 // 1/8 note has one beam
- : 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));
-
- infos_[i].beam_count_drul_[non_flag_dir] = max(count, 1);
+ 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;
}
}
}
@@ -362,6 +373,25 @@ Beaming_pattern::end_moment (int i) const
+ infos_.at (i).factor_ * dur.get_length ();
}
+Moment
+Beaming_pattern::remaining_length (int i) const
+{
+ return end_moment (infos_.size () - 1) - infos_[i].start_moment_;
+}
+
+int
+Beaming_pattern::beam_count_for_rhythmic_position (int idx) const
+{
+ // Calculate number of beams representing the rhythmic position of given stem
+ return intlog2(infos_[idx].start_moment_.main_part_.den()) - 2;
+}
+
+int
+Beaming_pattern::beam_count_for_length (Moment len) const
+{
+ return intlog2(len.main_part_.den()) - 2 - intlog2(len.main_part_.num());
+}
+
bool
Beaming_pattern::invisibility (int i) const
{
diff --git a/lily/include/beaming-pattern.hh b/lily/include/beaming-pattern.hh
index 217af19088..089bb31abd 100644
--- a/lily/include/beaming-pattern.hh
+++ b/lily/include/beaming-pattern.hh
@@ -80,6 +80,9 @@ private:
Direction flag_direction (Beaming_options const &, vsize) const;
void find_rhythmic_importance (Beaming_options const &);
void unbeam_invisible_stems ();
+ Moment remaining_length (int idx) const;
+ int beam_count_for_rhythmic_position (int idx) const;
+ int beam_count_for_length (Moment len) const;
};
#endif /* BEAMING_PATTERN_HH */