lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fix conversion warnings in beaming code (issue 553010043 by address@hidd


From: nine . fierce . ballads
Subject: Fix conversion warnings in beaming code (issue 553010043 by address@hidden)
Date: Tue, 01 Oct 2019 20:07:39 -0700

Reviewers: ,

Description:
Fix conversion warnings in beaming code

Changes include preserving sizes and indices as vsize types and adding
explicit static casts.  Warnings were reported by g++ 9.2.1 on x86_64.

Please review this at https://codereview.appspot.com/553010043/

Affected files (+35, -33 lines):
  M lily/beam.cc
  M lily/beam-quanting.cc
  M lily/beaming-pattern.cc
  M lily/include/beam.hh
  M lily/include/beam-scoring-problem.hh
  M lily/include/beaming-pattern.hh


Index: lily/beam-quanting.cc
diff --git a/lily/beam-quanting.cc b/lily/beam-quanting.cc
index 4f088b4146bc73f395c53110413c1271847cea6d..c33c52bfc5d3b9e8f844ce99e515d8fc4adb368a 100644
--- a/lily/beam-quanting.cc
+++ b/lily/beam-quanting.cc
@@ -635,16 +635,15 @@ Real
calc_positions_concaveness (vector<int> const &positions, Direction beam_dir)
 {
   Real dy = positions.back () - positions[0];
-  Real slope = dy / Real (positions.size () - 1);
+  Real slope = dy / static_cast<Real> (positions.size () - 1);
   Real concaveness = 0.0;
   for (vsize i = 1; i + 1 < positions.size (); i++)
     {
-      Real line_y = slope * i + positions[0];
-
+      Real line_y = slope * static_cast<Real> (i) + positions[0];
       concaveness += max (beam_dir * (positions[i] - line_y), 0.0);
     }

-  concaveness /= positions.size ();
+  concaveness /= static_cast<Real> (positions.size ());

   /*
     Normalize. For dy = 0, the slope ends up as 0 anyway, so the
Index: lily/beam.cc
diff --git a/lily/beam.cc b/lily/beam.cc
index 500bb5a1913aab608a976ccb88eade8769f2ebfb..4979bb48d16eea8e8a087d0f0618efae6d2c844c 100644
--- a/lily/beam.cc
+++ b/lily/beam.cc
@@ -174,7 +174,7 @@ Beam::calc_direction (SCM smob)

   Direction dir = CENTER;

-  int count = normal_stem_count (me);
+  vsize count = normal_stem_count (me);
   if (count < 2)
     {
       extract_grob_set (me, "stems", stems);
@@ -715,7 +715,10 @@ Beam::print (SCM grob)
Real factor = Interval (multiplier, 1 - multiplier).linear_combination (feather_dir);

       if (segments[0].vertical_count_ < 0 && feather_dir)
-        weighted_average += beam_dy * (segments.size () - 1) * factor;
+        {
+          Real n = static_cast<Real> (segments.size () - 1);
+          weighted_average += beam_dy * n * factor;
+        }

       b.translate_axis (weighted_average, Y_AXIS);

@@ -958,8 +961,8 @@ Beam::calc_stem_shorten (SCM smob)
   if (is_knee (me))
     return scm_from_int (0);

-  Real forced_fraction = 1.0 * forced_stem_count (me)
-                         / normal_stem_count (me);
+  Real forced_fraction = static_cast<Real> (forced_stem_count (me))
+                         / static_cast<Real> (normal_stem_count (me));

   int beam_count = get_beam_count (me);

@@ -1163,12 +1166,12 @@ Beam::set_beaming (Grob *me, Beaming_pattern const *beaming)
     }
 }

-int
+vsize
 Beam::forced_stem_count (Grob *me)
 {
   extract_grob_set (me, "normal-stems", stems);

-  int f = 0;
+  vsize f = 0;
   for (vsize i = 0; i < stems.size (); i++)
     {
       Grob *s = stems[i];
@@ -1185,7 +1188,7 @@ Beam::forced_stem_count (Grob *me)
   return f;
 }

-int
+vsize
 Beam::normal_stem_count (Grob *me)
 {
   extract_grob_set (me, "normal-stems", stems);
Index: lily/beaming-pattern.cc
diff --git a/lily/beaming-pattern.cc b/lily/beaming-pattern.cc
index 66e573d84561c2af8ba576599720264256db521d..269c209ecf6e8ac93874997fa12e0393079bcf09 100644
--- a/lily/beaming-pattern.cc
+++ b/lily/beaming-pattern.cc
@@ -351,19 +351,19 @@ Beaming_pattern::Beaming_pattern ()
 }

 int
-Beaming_pattern::beamlet_count (int i, Direction d) const
+Beaming_pattern::beamlet_count (vsize i, Direction d) const
 {
   return infos_.at (i).beam_count_drul_[d];
 }

 Moment
-Beaming_pattern::start_moment (int i) const
+Beaming_pattern::start_moment (vsize i) const
 {
   return infos_.at (i).start_moment_;
 }

 Moment
-Beaming_pattern::end_moment (int i) const
+Beaming_pattern::end_moment (vsize i) const
 {
   Duration dur (2 + max (beamlet_count (i, LEFT),
                          beamlet_count (i, RIGHT)),
@@ -374,13 +374,13 @@ Beaming_pattern::end_moment (int i) const
 }

 Moment
-Beaming_pattern::remaining_length (int i) const
+Beaming_pattern::remaining_length (vsize i) const
 {
     return end_moment (infos_.size () - 1) - infos_[i].start_moment_;
 }

 int
-Beaming_pattern::beam_count_for_rhythmic_position (int idx) const
+Beaming_pattern::beam_count_for_rhythmic_position (vsize idx) const
 {
// Calculate number of beams representing the rhythmic position of given stem
     return intlog2(infos_[idx].start_moment_.main_part_.den()) - 2;
@@ -393,19 +393,19 @@ Beaming_pattern::beam_count_for_length (Moment len) const
 }

 bool
-Beaming_pattern::invisibility (int i) const
+Beaming_pattern::invisibility (vsize i) const
 {
   return infos_.at (i).invisible_;
 }

 Rational
-Beaming_pattern::factor (int i) const
+Beaming_pattern::factor (vsize i) const
 {
   return infos_.at (i).factor_;
 }

 bool
-Beaming_pattern::tuplet_start (int i) const
+Beaming_pattern::tuplet_start (vsize i) const
 {
   return infos_.at (i).tuplet_start_;
 }
@@ -415,7 +415,7 @@ Beaming_pattern::tuplet_start (int i) const
     Beaming_pattern containing the removed elements
 */
 Beaming_pattern *
-Beaming_pattern::split_pattern (int i)
+Beaming_pattern::split_pattern (vsize i)
 {
   Beaming_pattern *new_pattern = 0;
   int count;
Index: lily/include/beam-scoring-problem.hh
diff --git a/lily/include/beam-scoring-problem.hh b/lily/include/beam-scoring-problem.hh index 983bb0137d365d603be7ffe4ef4f8bbbd7a85e55..8b30acbee52aa93cec0efc1e39e03262a8bbcf71 100644
--- a/lily/include/beam-scoring-problem.hh
+++ b/lily/include/beam-scoring-problem.hh
@@ -131,7 +131,7 @@ private:
   Real beam_thickness_;
   Real line_thickness_;
   Real musical_dy_;
-  int normal_stem_count_;
+  vsize normal_stem_count_;
   Real x_span_;

   /*
Index: lily/include/beam.hh
diff --git a/lily/include/beam.hh b/lily/include/beam.hh
index 77290c73fe2a8056f6f9c9d506a5de34fdaf74b7..76ae590e7675b5eb185b7401f9168890aa63195c 100644
--- a/lily/include/beam.hh
+++ b/lily/include/beam.hh
@@ -42,7 +42,7 @@ struct Beam_stem_segment
   Grob *stem_;
   Real width_;
   Real stem_x_;
-  int rank_;
+  vsize rank_;
   vsize stem_index_;
   bool gapped_;
   Direction dir_;
@@ -54,7 +54,7 @@ bool operator <(Beam_stem_segment const &a, Beam_stem_segment const &b);
 class Beam
 {
 public:
-  static int normal_stem_count (Grob *);
+  static vsize normal_stem_count (Grob *);
   static Grob *first_normal_stem (Grob *);
   static Grob *last_normal_stem (Grob *);
   static void add_stem (Grob *, Grob *);
@@ -92,7 +92,7 @@ private:
   static void set_stem_directions (Grob *, Direction);
   static void consider_auto_knees (Grob *);
   static void set_stem_shorten (Grob *);
-  static int forced_stem_count (Grob *);
+  static vsize forced_stem_count (Grob *);
   static Real calc_stem_y (Grob *, Grob *s, Grob **c,
                            Real, Real, Direction,
                            Drul_array<Real> pos, bool french);
Index: lily/include/beaming-pattern.hh
diff --git a/lily/include/beaming-pattern.hh b/lily/include/beaming-pattern.hh index 8a88db3e9b8f8dec4e50dcfbe4fc5d41bb624f73..08550270bab331501dfff3e92fa1b51ff3353fe8 100644
--- a/lily/include/beaming-pattern.hh
+++ b/lily/include/beaming-pattern.hh
@@ -67,21 +67,21 @@ public:
   void beamify (Beaming_options const &);
   void de_grace ();
void add_stem (Moment d, int beams, bool invisible, Rational factor, bool tuplet_starrt);
-  int beamlet_count (int idx, Direction d) const;
-  bool invisibility (int idx) const;
-  Rational factor (int idx) const;
-  bool tuplet_start (int idx) const;
-  Moment start_moment (int idx) const;
-  Moment end_moment (int idx) const;
-  Beaming_pattern *split_pattern (int idx);
+  int beamlet_count (vsize idx, Direction d) const;
+  bool invisibility (vsize idx) const;
+  Rational factor (vsize idx) const;
+  bool tuplet_start (vsize idx) const;
+  Moment start_moment (vsize idx) const;
+  Moment end_moment (vsize idx) const;
+  Beaming_pattern *split_pattern (vsize idx);

 private:
   vector<Beam_rhythmic_element> infos_;
   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;
+  Moment remaining_length (vsize idx) const;
+  int beam_count_for_rhythmic_position (vsize idx) const;
   int beam_count_for_length (Moment len) const;
 };






reply via email to

[Prev in Thread] Current Thread [Next in Thread]