]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 2491: Macro for(UP_and_DOWN) and 3 similar.
authorŁukasz Czerwiński <milimetr88@gmail.com>
Mon, 30 Apr 2012 11:11:48 +0000 (13:11 +0200)
committerDavid Kastrup <dak@gnu.org>
Mon, 30 Apr 2012 11:15:19 +0000 (13:15 +0200)
Replaces do{ ... } while(flip (&d) != DOWN/UP/... with a macro for(DOWN_and_UP/UP_and_DOWN/....) { }

Signed-off-by: David Kastrup <dak@gnu.org>
46 files changed:
flower/include/direction.hh
lily/ambitus-engraver.cc
lily/axis-group-interface.cc
lily/beam-quanting.cc
lily/beam.cc
lily/bezier.cc
lily/break-substitution.cc
lily/dynamic-align-engraver.cc
lily/figured-bass-continuation.cc
lily/hairpin.cc
lily/horizontal-bracket.cc
lily/interval-minefield.cc
lily/item.cc
lily/ledger-line-spanner.cc
lily/line-spanner.cc
lily/lookup.cc
lily/lyric-hyphen.cc
lily/multi-measure-rest-engraver.cc
lily/multi-measure-rest.cc
lily/new-fingering-engraver.cc
lily/note-collision.cc
lily/note-spacing.cc
lily/optimal-page-breaking.cc
lily/ottava-bracket.cc
lily/ottava-engraver.cc
lily/paper-column.cc
lily/piano-pedal-bracket.cc
lily/rest-collision.cc
lily/rod.cc
lily/script-column.cc
lily/slur-configuration.cc
lily/slur-scoring.cc
lily/slur.cc
lily/spacing-determine-loose-columns.cc
lily/spacing-interface.cc
lily/spacing-spanner.cc
lily/spanner.cc
lily/staff-symbol.cc
lily/stem.cc
lily/system-start-delimiter.cc
lily/system.cc
lily/tie-column.cc
lily/tie-engraver.cc
lily/tie-formatting-problem.cc
lily/tie.cc
lily/tuplet-bracket.cc

index 50c41a4ab46f5b28b50135ffde9fced8639149e3..97c0f6d79bb59ee9f790c250a71f66c120df3a99 100644 (file)
@@ -60,7 +60,7 @@ operator - (Direction const d)
   return other_dir (d);
 }
 
-// huh?
+// to be deleted soon (after coping with issues 2491 and 2493
 inline Direction
 flip (Direction *i)
 {
@@ -71,6 +71,16 @@ flip (Direction *i)
   return *i;
 }
 
+#define UP_and_DOWN(d) \
+  Direction d = UP; d != CENTER; d = (d == UP ? DOWN : CENTER)
+
+#define DOWN_and_UP(d) \
+  Direction d = DOWN; d != CENTER; d = (d == DOWN ? UP : CENTER)
+
+#define LEFT_and_RIGHT(d) \
+  Direction d = LEFT; d != CENTER; d = (d == LEFT ? RIGHT : CENTER)
+
+
 /**
    if d > 0: the max operator
    if d < 0: the min operator
index 2d2f027c4ee4277318da5c144051d8f8a1117fec..92fee10a50a3fddf160078537e9f5dfee526559e 100644 (file)
@@ -71,8 +71,7 @@ Ambitus_engraver::create_ambitus ()
 {
   ambitus_ = make_item ("AmbitusLine", SCM_EOL);
   group_ = make_item ("Ambitus", SCM_EOL);
-  Direction d = DOWN;
-  do
+  for (DOWN_and_UP (d))
     {
       heads_[d] = make_item ("AmbitusNoteHead", SCM_EOL);
       accidentals_[d] = make_item ("AmbitusAccidental", SCM_EOL);
@@ -82,7 +81,6 @@ Ambitus_engraver::create_ambitus ()
       Axis_group_interface::add_element (group_, heads_[d]);
       Axis_group_interface::add_element (group_, accidentals_[d]);
     }
-  while (flip (&d) != DOWN);
 
   ambitus_->set_parent (heads_[DOWN], X_AXIS);
   Axis_group_interface::add_element (group_, ambitus_);
@@ -164,8 +162,7 @@ Ambitus_engraver::finalize ()
       Grob *accidental_placement
         = make_item ("AccidentalPlacement", accidentals_[DOWN]->self_scm ());
 
-      Direction d = DOWN;
-      do
+      for (DOWN_and_UP (d))
         {
           Pitch p = pitch_interval_[d];
           heads_[d]->set_property ("cause", causes_[d]->self_scm ());
@@ -205,19 +202,16 @@ Ambitus_engraver::finalize ()
                                              ly_symbol2scm ("note-heads"),
                                              heads_[d]);
         }
-      while (flip (&d) != DOWN);
 
       Axis_group_interface::add_element (group_, accidental_placement);
     }
   else
     {
-      Direction d = DOWN;
-      do
+      for (DOWN_and_UP (d))
         {
           accidentals_[d]->suicide ();
           heads_[d]->suicide ();
         }
-      while (flip (&d) != DOWN);
 
       ambitus_->suicide ();
     }
index 8857de109d6b3cb6ec438fae3578fe22386e2da0..1b937985eeee2aab63444c47401f2a49e9a59af7 100644 (file)
@@ -476,14 +476,12 @@ Axis_group_interface::internal_calc_pure_relevant_grobs (Grob *me, string grob_s
 
       if (Item *it = dynamic_cast<Item *> (elts[i]))
         {
-          Direction d = LEFT;
-          do
+          for (LEFT_and_RIGHT (d))
             {
               Item *piece = it->find_prebroken_piece (d);
               if (piece && to_boolean (scm_apply_1 (pure_relevant_p, piece->self_scm (), SCM_EOL)))
                 relevant_grobs.push_back (piece);
             }
-          while (flip (&d) != LEFT);
         }
     }
 
index f2c35973e4b8600fa71593095fd65bb0353dc824..ac845103ea8f56c75d608da171224756b557314e 100644 (file)
@@ -193,10 +193,8 @@ void Beam_scoring_problem::init_instance_variables (Grob *me, Drul_array<Real> y
     the stems.  Otherwise, we want to do initial slope calculations.
   */
   do_initial_slope_calculations_ = false;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     do_initial_slope_calculations_ |= isinf (unquanted_y_[d]) || isnan (unquanted_y_[d]);
-  while (flip (&d) != LEFT);
 
   /*
     Calculations are relative to a unit-scaled staff, i.e. the quants are
@@ -245,10 +243,8 @@ void Beam_scoring_problem::init_instance_variables (Grob *me, Drul_array<Real> y
       for (int a = 2; a--;)
         common[a] = common_refpoint_of_array (stems, beams[i], Axis (a));
 
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         common[X_AXIS] = beams[i]->get_bound (d)->common_refpoint (common[X_AXIS], X_AXIS);
-      while (flip (&d) != LEFT);
 
       // positions of the endpoints of this beam segment, including any overhangs
       const Interval x_pos = robust_scm2interval (beams[i]->get_property ("X-positions"),
@@ -309,8 +305,7 @@ void Beam_scoring_problem::init_instance_variables (Grob *me, Drul_array<Real> y
       // TODO - why are we dividing by staff_space_?
       beam_translation_ = Beam::get_beam_translation (beams[i]) / staff_space_;
 
-      d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           quant_range_[d].set_full ();
           if (!edge_stems[d])
@@ -325,7 +320,6 @@ void Beam_scoring_problem::init_instance_variables (Grob *me, Drul_array<Real> y
                        + (edge_beam_counts_[d] - 1) * beam_translation_ + beam_thickness_ * .5);
           quant_range_[d][-ed] = heads[ed] + stem_offset;
         }
-      while (flip (&d) != LEFT);
 
       segments_ = Beam::get_beam_segments (beams[i]);
       vector_sort (segments_, beam_segment_less);
@@ -355,10 +349,8 @@ void Beam_scoring_problem::init_instance_variables (Grob *me, Drul_array<Real> y
           Real width = b[X_AXIS].length ();
           Real width_factor = sqrt (width / staff_space_);
 
-          Direction d = LEFT;
-          do
+          for (LEFT_and_RIGHT (d))
             add_collision (b[X_AXIS][d], b[Y_AXIS], width_factor);
-          while (flip (&d) != LEFT);
 
           Grob *stem = unsmob_grob (collisions[j]->get_object ("stem"));
           if (stem && Stem::has_interface (stem) && Stem::is_normal_stem (stem))
@@ -794,23 +786,19 @@ Beam_scoring_problem::shift_region_to_valid ()
       if (collisions_[i].y_.length () < min_y_size)
         continue;
 
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           Real dy = slope * collisions_[i].x_;
 
-          Direction yd = DOWN;
           Interval disallowed;
-          do
+          for (DOWN_and_UP (yd))
             {
               Real left_y = collisions_[i].y_[yd] - dy;
               disallowed[yd] = left_y;
             }
-          while (flip (&yd) != DOWN);
 
           forbidden_intervals.push_back (disallowed);
         }
-      while (flip (&d) != LEFT);
     }
 
   vector_sort (forbidden_intervals, Interval::left_less);
@@ -825,13 +813,11 @@ Beam_scoring_problem::shift_region_to_valid ()
 
   // if the beam placement falls out of the feasible region, we push it
   // to infinity so that it can never be a feasible candidate below
-  Direction d = DOWN;
-  do
+  for (DOWN_and_UP (d))
     {
       if (!feasible_left_point.contains (feasible_beam_placements[d]))
         feasible_beam_placements[d] = d * infinity_f;
     }
-  while (flip (&d) != DOWN);
 
   if ((feasible_beam_placements[UP] == infinity_f && feasible_beam_placements[DOWN] == -infinity_f) && !feasible_left_point.is_empty ())
     {
@@ -892,8 +878,7 @@ Beam_scoring_problem::generate_quants (vector<Beam_configuration *> *scores) con
                                             Interval (unshifted_quants[i],
                                                       unshifted_quants[j]));
 
-        Direction d = LEFT;
-        do
+        for (LEFT_and_RIGHT (d))
           {
             if (!quant_range_[d].contains (c->y[d]))
               {
@@ -902,7 +887,6 @@ Beam_scoring_problem::generate_quants (vector<Beam_configuration *> *scores) con
                 break;
               }
           }
-        while (flip (&d) != LEFT);
         if (c)
           scores->push_back (c);
       }
@@ -1098,10 +1082,8 @@ Beam_scoring_problem::score_stem_lengths (Beam_configuration *config) const
     }
 
   /* Divide by number of stems, to make the measure scale-free. */
-  Direction d = DOWN;
-  do
+  for (DOWN_and_UP (d))
     score[d] /= max (count[d], 1);
-  while (flip (&d) != DOWN);
 
   /*
     sometimes, two perfectly symmetric kneed beams will have the same score
@@ -1211,11 +1193,10 @@ Beam_scoring_problem::score_forbidden_quants (Beam_configuration *config) const
   Real extra_demerit = parameters_.SECONDARY_BEAM_DEMERIT
                        / max (edge_beam_counts_[LEFT], edge_beam_counts_[RIGHT]);
 
-  Direction d = LEFT;
   Real dem = 0.0;
   Real eps = parameters_.BEAM_EPS;
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       for (int j = 1; j <= edge_beam_counts_[d]; j++)
         {
@@ -1258,7 +1239,6 @@ Beam_scoring_problem::score_forbidden_quants (Beam_configuration *config) const
               }
         }
     }
-  while ((flip (&d)) != LEFT);
 
   if (max (edge_beam_counts_[LEFT], edge_beam_counts_[RIGHT]) >= 2)
     {
@@ -1267,8 +1247,7 @@ Beam_scoring_problem::score_forbidden_quants (Beam_configuration *config) const
       Real inter = 0.5;
       Real hang = 1.0 - (beam_thickness_ - line_thickness_) / 2;
 
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           if (edge_beam_counts_[d] >= 2
               && fabs (config->y[d] - edge_dirs_[d] * beam_translation_) < staff_radius_ + inter)
@@ -1296,7 +1275,6 @@ Beam_scoring_problem::score_forbidden_quants (Beam_configuration *config) const
                 dem += extra_demerit;
             }
         }
-      while (flip (&d) != LEFT);
     }
 
   config->add (dem, "F");
index 0cfc3e193cba6b3feea911abb09a6f9e5118d6c2..e2d12931875f1118989dd0fd9024b85965f82c84 100644 (file)
@@ -284,9 +284,8 @@ Beam::calc_beaming (SCM smob)
                              last_dir ? last_dir : this_dir,
                              this_dir);
 
-          Direction d = LEFT;
           Slice new_slice;
-          do
+          for (LEFT_and_RIGHT (d))
             {
               new_slice.set_empty ();
               SCM s = index_get_cell (this_beaming, d);
@@ -299,7 +298,6 @@ Beam::calc_beaming (SCM smob)
                   scm_set_car_x (s, scm_from_int (new_beam_pos));
                 }
             }
-          while (flip (&d) != LEFT);
 
           if (!new_slice.is_empty ())
             last_int = new_slice;
@@ -351,10 +349,8 @@ Beam::calc_beam_segments (SCM smob)
   extract_grob_set (me, "stems", stems);
 
   Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS);
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     commonx = me->get_bound (d)->common_refpoint (commonx, X_AXIS);
-  while (flip (&d) != LEFT);
 
   int gap_count = robust_scm2int (me->get_property ("gap-count"), 0);
   Real gap_length = robust_scm2double (me->get_property ("gap"), 0.0);
@@ -376,7 +372,7 @@ Beam::calc_beam_segments (SCM smob)
       Real stem_x = stem->relative_coordinate (commonx, X_AXIS);
       SCM beaming = stem->get_property ("beaming");
 
-      do
+      for (LEFT_and_RIGHT (d))
         {
           // Find the maximum and minimum beam ranks.
           // Given that RANKS is never reset to empty, the interval will always be
@@ -415,7 +411,6 @@ Beam::calc_beam_segments (SCM smob)
               stem_segments[beam_rank].push_back (seg);
             }
         }
-      while (flip (&d) != LEFT);
     }
 
   Drul_array<Real> break_overshoot
@@ -444,9 +439,8 @@ Beam::calc_beam_segments (SCM smob)
           // we are currently looking at (ie. if segs[j].dir_ == event_dir then we
           // are looking at that edge of the beam segment that is furthest from its
           // stem).
-          Direction event_dir = LEFT;
           Beam_stem_segment const &seg = segs[j];
-          do
+          for (LEFT_and_RIGHT (event_dir))
             {
               Beam_stem_segment const &neighbor_seg = segs[j + event_dir];
               // TODO: make names clearer? --jneem
@@ -542,7 +536,6 @@ Beam::calc_beam_segments (SCM smob)
                   current = Beam_segment ();
                 }
             }
-          while (flip (&event_dir) != LEFT);
         }
 
     }
@@ -583,10 +576,8 @@ Beam::calc_x_positions (SCM smob)
     {
       extract_grob_set (me, "stems", stems);
       Grob *common_x = common_refpoint_of_array (stems, me, X_AXIS);
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         x_positions[d] = me->relative_coordinate (common_x, X_AXIS);
-      while (flip (&d) != LEFT);
     }
   return ly_interval2scm (x_positions);
 }
@@ -621,10 +612,8 @@ Beam::print (SCM grob)
   */
   extract_grob_set (me, "stems", stems);
   Grob *commonx = common_refpoint_of_array (stems, me, X_AXIS);
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     commonx = me->get_bound (d)->common_refpoint (commonx, X_AXIS);
-  while (flip (&d) != LEFT);
 
   vector<Beam_segment> segments = get_beam_segments (me);
 
@@ -764,13 +753,11 @@ Beam::get_default_dir (Grob *me)
   for (iterof (s, stems); s != stems.end (); s++)
     {
       Interval positions = Stem::head_positions (*s);
-      Direction d = DOWN;
-      do
+      for (DOWN_and_UP (d))
         {
           if (sign (positions[d]) == d)
             extremes[d] = d * max (d * positions[d], d * extremes[d]);
         }
-      while (flip (&d) != DOWN);
     }
 
   Drul_array<int> total (0, 0);
@@ -1133,13 +1120,12 @@ Beam::set_beaming (Grob *me, Beaming_pattern const *beaming)
 {
   extract_grob_set (me, "stems", stems);
 
-  Direction d = LEFT;
   for (vsize i = 0; i < stems.size (); i++)
     {
       /*
         Don't overwrite user settings.
       */
-      do
+      for (LEFT_and_RIGHT (d))
         {
           Grob *stem = stems[i];
           SCM beaming_prop = stem->get_property ("beaming");
@@ -1161,7 +1147,6 @@ Beam::set_beaming (Grob *me, Beaming_pattern const *beaming)
               Stem::set_beaming (stem, count, d);
             }
         }
-      while (flip (&d) != LEFT);
     }
 }
 
@@ -1243,10 +1228,8 @@ Beam::rest_collision_callback (SCM smob, SCM prev_offset)
   Drul_array<Real> pos (robust_scm2drul (beam->get_property ("positions"),
                                          Drul_array<Real> (0, 0)));
 
-  Direction dir = LEFT;
-  do
+  for (LEFT_and_RIGHT (dir))
     pos[dir] += beam->relative_coordinate (common_y, Y_AXIS);
-  while (flip (&dir) != LEFT);
 
   Real staff_space = Staff_symbol_referencer::staff_space (rest);
 
index 56e14943f8d75c235c4af6abc589c5c129b19bb9..c4cdbb1c7b6c07d41bb338767994eef1bccc2ae4 100644 (file)
@@ -245,14 +245,12 @@ Bezier::minmax (Axis ax, Real l, Real r, Direction d) const
 
   //  or intersections of the curve with the bounding lines at L and R.
   Interval lr (l, r);
-  Direction dir = LEFT;
-  do
+  for (LEFT_and_RIGHT (dir))
     {
       vector<Real> v = get_other_coordinates (ax, lr[dir]);
       for (vsize i = v.size (); i--;)
         iv.add_point (v[i]);
     }
-  while (flip (&dir) != LEFT);
 
   if (iv.is_empty ())
     {
index ddaf9b4328e5d3df660bb21bcfe8357bd07af858..a0f03f753cc5b9d873223b9bb61537b3383dd513 100644 (file)
@@ -248,14 +248,12 @@ item_system_range (Item *it)
     return Slice (st->get_rank (), st->get_rank ());
 
   Slice sr;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Item *bi = it->find_prebroken_piece (d);
       if (bi && bi->get_system ())
         sr.add_point (bi->get_system ()->get_rank ());
     }
-  while (flip (&d) != LEFT);
 
   return sr;
 }
index b584e603c9345dfc3f935185c6bbf23b237af9ac..265498658abb01358aa6cd86b18ee21986fa666b 100644 (file)
@@ -158,8 +158,8 @@ Dynamic_align_engraver::set_spanner_bounds (Spanner *line, bool end)
 {
   if (!line)
     return;
-  Direction d = LEFT;
-  do
+
+  for (LEFT_and_RIGHT (d))
     {
       if ((d == LEFT && !line->get_bound (LEFT))
           || (end && d == RIGHT && !line->get_bound (RIGHT)))
@@ -181,7 +181,6 @@ Dynamic_align_engraver::set_spanner_bounds (Spanner *line, bool end)
           line->set_bound (d, bound);
         }
     }
-  while (flip (&d) != LEFT);
 }
 
 void
index 6034a34641a0e0b6bfc86c23cc58550155408816..bc216a2c4ab7609b222217652e2c20580a3390d5 100644 (file)
@@ -64,10 +64,10 @@ Figured_bass_continuation::print (SCM grob)
       * robust_scm2double (me->get_property ("thickness"), 1);
 
   Interval spanned;
-  Direction d = LEFT;
+
   Grob *common = me->get_bound (LEFT)->common_refpoint (me->get_bound (RIGHT),
                                                         X_AXIS);
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Item *bound = me->get_bound (d);
       Direction extdir
@@ -78,7 +78,6 @@ Figured_bass_continuation::print (SCM grob)
         = robust_relative_extent (bound, common, X_AXIS)[extdir]
           - me->relative_coordinate (common, X_AXIS);
     }
-  while (flip (&d) != LEFT);
   spanned.widen (- robust_scm2double (me->get_property ("padding"), 0.2));
 
   Stencil extender;
index 7ef0f847a1e8fdf30e3231434cbb84209d119f57..7639ddd78e774210ebcea9de2da6b772a493564a 100644 (file)
@@ -69,19 +69,16 @@ Hairpin::broken_bound_padding (SCM smob)
 
   Grob *my_vertical_axis_group = Grob::get_vertical_axis_group (me);
   Drul_array<Grob *> vertical_axis_groups;
-  Direction d = DOWN;
-  do
+  for (DOWN_and_UP (d))
     vertical_axis_groups[d] = d == dir
                               ? sys->get_neighboring_staff (d, my_vertical_axis_group, Interval_t<int> (me->spanned_rank_interval ()))
                               : my_vertical_axis_group;
-  while (flip (&d) != DOWN);
 
   if (!vertical_axis_groups[dir])
     return scm_from_double (0.0);
 
   Drul_array<Grob *> span_bars (0, 0);
-  d = DOWN;
-  do
+  for (DOWN_and_UP (d))
     {
       extract_grob_set (vertical_axis_groups[d], "elements", elts);
       for (vsize i = elts.size (); i--;)
@@ -98,7 +95,6 @@ Hairpin::broken_bound_padding (SCM smob)
       if (!span_bars[d])
         return scm_from_double (0.0);
     }
-  while (flip (&d) != DOWN);
 
   if (span_bars[DOWN] != span_bars[UP])
     return scm_from_double (0.0);
@@ -125,13 +121,11 @@ Hairpin::print (SCM smob)
 
   Drul_array<bool> broken;
   Drul_array<Item *> bounds;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       bounds[d] = me->get_bound (d);
       broken[d] = bounds[d]->break_status_dir () != CENTER;
     }
-  while (flip (&d) != LEFT);
 
   broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT);
   broken[RIGHT] = broken[RIGHT] && me->broken_neighbor (RIGHT)->is_live ();
@@ -162,7 +156,7 @@ Hairpin::print (SCM smob)
     thick = robust_scm2double (me->get_property ("thickness"), 1.0)
             * Staff_symbol_referencer::line_thickness (me);
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Item *b = bounds[d];
       Interval e = (Paper_column::has_interface (b) && b->break_status_dir ())
@@ -254,7 +248,6 @@ Hairpin::print (SCM smob)
             }
         }
     }
-  while (flip (&d) != LEFT);
 
   Real width = x_points[RIGHT] - x_points[LEFT];
 
index 7f3c839e9121bb261c2487e57ab7c007e0c5d58e..279ee0baf291bf2083f3979cd02704c09179da00 100644 (file)
@@ -53,8 +53,7 @@ Horizontal_bracket::make_bracket (Grob *me,
     = robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
                            Drul_array<bool> (false, false));
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (connect_to_other[d])
         {
@@ -63,7 +62,6 @@ Horizontal_bracket::make_bracket (Grob *me,
           shorten[d] = 0.0;
         }
     }
-  while (flip (&d) != LEFT);
 
   /*
     ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around.
@@ -113,14 +111,12 @@ Horizontal_bracket::print (SCM smob)
       return SCM_EOL;
     }
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Item *b = me->get_bound (d);
       if (b->break_status_dir ())
         enclosed.push_back (b);
     }
-  while (flip (&d) != LEFT);
 
   Stencil b = make_enclosing_bracket (me, me, enclosed, X_AXIS, get_grob_direction (me));
   return b.smobbed_copy ();
index 7571e219ece4d062563c826d4be455c5e931cd4c..ffe784fae81ca4eb8fca4b81f88e62b8e8b15eea 100644 (file)
@@ -58,8 +58,7 @@ Interval_minefield::solve ()
       dirty = false;
       for (vsize i = 0; i < forbidden_intervals_.size (); i++)
         {
-          Direction d = DOWN;
-          do
+          for (DOWN_and_UP (d))
             {
               Interval feasible_widened = Interval (feasible_placements_[d], feasible_placements_[d]);
               feasible_widened.widen (bulk_ / 2.);
@@ -75,8 +74,7 @@ Interval_minefield::solve ()
                   dirty = true;
                 }
             }
-          while (flip (&d) != DOWN);
         }
     }
   while (dirty);
-}
\ No newline at end of file
+}
index 0c3169a7766f31860ef77b978ad7829c017f58b1..9941bc13c2abf79bc36fd25f952a084633d6e635 100644 (file)
@@ -77,15 +77,13 @@ void
 Item::copy_breakable_items ()
 {
   Drul_array<Item *> new_copies;
-  Direction i = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Grob *dolly = clone ();
       Item *item = dynamic_cast<Item *> (dolly);
       get_root_system (this)->typeset_grob (item);
-      new_copies[i] = item;
+      new_copies[d] = item;
     }
-  while (flip (&i) != LEFT);
 
   broken_to_drul_ = new_copies;
 }
@@ -115,14 +113,12 @@ Item::find_broken_piece (System *l) const
   if (get_system () == l)
     return (Item *) (this);
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Grob *s = broken_to_drul_[d];
       if (s && s->get_system () == l)
         return s;
     }
-  while (flip (&d) != LEFT);
 
   return 0;
 }
@@ -202,21 +198,18 @@ spanned_time_interval (Item *l, Item *r)
   Drul_array<Item *> bounds (l, r);
   Interval_t<Moment> iv;
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (bounds[d] && bounds[d]->get_column ())
         iv[d] = robust_scm2moment (bounds[d]->get_column ()->get_property ("when"),
                                    iv[d]);
     }
-  while (flip (&d) != LEFT);
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (!bounds[d] || !bounds[d]->get_column ())
         iv[d] = iv[-d];
     }
-  while (flip (&d) != LEFT);
 
   return iv;
 }
index 83304acff7a4b39cd2a814827f4bf5b24d9da083..20e4b59fc34f2bfd9312dabc7c1408ed3210d700 100644 (file)
@@ -227,8 +227,7 @@ Ledger_line_spanner::print (SCM smob)
       if (last == reqs.end ())
         continue;
 
-      Direction d = DOWN;
-      do
+      for (DOWN_and_UP (d))
         {
           if (!staff_extent.contains (last->second[d].position_)
               && !staff_extent.contains (i->second[d].position_))
@@ -237,8 +236,7 @@ Ledger_line_spanner::print (SCM smob)
                 = (last->second[d].head_extent_[RIGHT]
                    + i->second[d].head_extent_[LEFT]) / 2;
 
-              Direction which = LEFT;
-              do
+              for (LEFT_and_RIGHT (which))
                 {
                   Ledger_request &lr = ((which == LEFT) ? * last : *i).second[d];
 
@@ -253,10 +251,8 @@ Ledger_line_spanner::print (SCM smob)
                   lr.ledger_extent_.at (-which)
                     = which * max (which * lr.ledger_extent_[-which], which * limit);
                 }
-              while (flip (&which) != LEFT);
             }
         }
-      while (flip (&d) != DOWN);
     }
 
   // create ledgers for note heads
index 418a0648748abd9736b7a9032ddfea504640606a..2d43a71fa4f0006943990e89e390fcdf4c71b28b 100644 (file)
@@ -270,8 +270,7 @@ Line_spanner::print (SCM smob)
 
   Drul_array<Offset> span_points;
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Offset z (robust_scm2double (ly_assoc_get (ly_symbol2scm ("X"),
                                                  bounds[d], SCM_BOOL_F), 0.0),
@@ -280,7 +279,6 @@ Line_spanner::print (SCM smob)
 
       span_points[d] = z;
     }
-  while (flip (&d) != LEFT);
 
   Drul_array<Real> gaps (0, 0);
   Drul_array<bool> arrows (0, 0);
@@ -291,7 +289,7 @@ Line_spanner::print (SCM smob)
   Real magstep
     = pow (2, robust_scm2double (me->get_property ("font-size"), 0.0) / 6);
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       gaps[d] = robust_scm2double (ly_assoc_get (ly_symbol2scm ("padding"),
                                                  bounds[d], SCM_BOOL_F), 0.0);
@@ -304,15 +302,13 @@ Line_spanner::print (SCM smob)
       if (!common_y[d])
         common_y[d] = me;
     }
-  while (flip (&d) != LEFT);
 
   Grob *my_common_y = common_y[LEFT]->common_refpoint (common_y[RIGHT], Y_AXIS);
 
   if (!simple_y)
     {
-      do
+      for (LEFT_and_RIGHT (d))
         span_points[d][Y_AXIS] += common_y[d]->relative_coordinate (my_common_y, Y_AXIS);
-      while (flip (&d) != LEFT);
     }
 
   Interval normalized_endpoints = robust_scm2interval (me->get_property ("normalized-endpoints"), Interval (0, 1));
@@ -329,7 +325,7 @@ Line_spanner::print (SCM smob)
     }
 
   Stencil line;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       span_points[d] += -d * gaps[d] * magstep * dz.direction ();
 
@@ -350,15 +346,13 @@ Line_spanner::print (SCM smob)
           line.add_stencil (s);
         }
     }
-  while (flip (&d) != LEFT);
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (stencils[d])
         span_points[d] += dz_dir *
                           (stencils[d]->extent (X_AXIS)[-d] / dz_dir[X_AXIS]);
     }
-  while (flip (&d) != LEFT);
 
   Offset adjust = dz.direction () * Staff_symbol_referencer::staff_space (me);
 
index 4d4c0bdf6a6966925a91ec7d254808fa60554a57..1acb34f783cf83dab6b0cc503f8d55fb47852a0e 100644 (file)
@@ -333,11 +333,10 @@ Stencil
 Lookup::frame (Box b, Real thick, Real blot)
 {
   Stencil m;
-  Direction d = LEFT;
   for (Axis a = X_AXIS; a < NO_AXES; a = Axis (a + 1))
     {
       Axis o = Axis ((a + 1) % NO_AXES);
-      do
+      for (LEFT_and_RIGHT (d))
         {
           Box edges;
           edges[a] = b[a][d] + 0.5 * thick * Interval (-1, 1);
@@ -346,7 +345,6 @@ Lookup::frame (Box b, Real thick, Real blot)
 
           m.add_stencil (round_filled_box (edges, blot));
         }
-      while (flip (&d) != LEFT);
     }
   return m;
 }
index 4ce2fddeb86724b23b2da75f03fd482b8b357253..21ec770ea13d43c2a2f5ccba4ee6491f1f785a74 100644 (file)
@@ -47,8 +47,7 @@ Lyric_hyphen::print (SCM smob)
   Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
 
   Interval span_points;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Interval iv = bounds[d]->break_status_dir ()
                     ? Axis_group_interface::generic_bound_extent (bounds[d], common, X_AXIS)
@@ -58,7 +57,6 @@ Lyric_hyphen::print (SCM smob)
                        ? bounds[d]->relative_coordinate (common, X_AXIS)
                        : iv[-d];
     }
-  while (flip (&d) != LEFT);
 
   Real lt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
   Real th = robust_scm2double (me->get_property ("thickness"), 1) * lt;
@@ -125,14 +123,12 @@ Lyric_hyphen::set_spacing_rods (SCM smob)
   Spanner *sp = dynamic_cast<Spanner *> (me);
 
   r.distance_ = robust_scm2double (me->get_property ("minimum-distance"), 0);
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       r.item_drul_[d] = sp->get_bound (d);
       if (r.item_drul_[d])
         r.distance_ += -d * r.item_drul_[d]->extent (r.item_drul_[d], X_AXIS)[-d];
     }
-  while (flip (&d) != LEFT);
 
   if (r.item_drul_[LEFT]
       && r.item_drul_[RIGHT])
index 69865104f9fc8a7d67252c7bd1fab13ed0687ced..7fede1a3e70a095d71401d65b65cf7035b5d4054 100644 (file)
@@ -127,8 +127,7 @@ Multi_measure_rest_engraver::process_music ()
           /*
             Stack different scripts.
           */
-          Direction d = DOWN;
-          do
+          for (DOWN_and_UP (d))
             {
               Grob *last = 0;
               for (vsize i = 0; i < numbers_.size (); i++)
@@ -141,7 +140,6 @@ Multi_measure_rest_engraver::process_music ()
                     }
                 }
             }
-          while (flip (&d) != DOWN);
         }
 
       for (vsize i = 0; i < numbers_.size (); i++)
index 9ffaf4e18c03986b1852919ea893f652f6f9606f..c0f26f5c857c394f1db2de658594919de77e5414 100644 (file)
@@ -42,8 +42,7 @@ Multi_measure_rest::bar_width (Spanner *me)
 {
   SCM spacing_pair = me->get_property ("spacing-pair");
   Interval iv;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Item *col = me->get_bound (d)->get_column ();
       SCM align_sym
@@ -54,7 +53,6 @@ Multi_measure_rest::bar_width (Spanner *me)
 
       iv[d] = coldim[-d];
     }
-  while (flip (&d) != LEFT);
 
   return iv;
 }
index b6275b07216cc598316508a4e43402c228ae35aa..0ad31ec1265d4d30cb8724c7a3bf0aacb2ca707b 100644 (file)
@@ -291,9 +291,8 @@ New_fingering_engraver::position_scripts (SCM orientations,
       f->set_property ("direction", scm_from_int (hordir));
     }
 
-  Direction d = DOWN;
   Drul_array< vector<Finger_tuple> > vertical (down, up);
-  do
+  for (DOWN_and_UP (d))
     {
       for (vsize i = 0; i < vertical[d].size (); i++)
         {
@@ -311,7 +310,6 @@ New_fingering_engraver::position_scripts (SCM orientations,
           f->set_property ("direction", scm_from_int (d));
         }
     }
-  while (flip (&d) != DOWN);
 }
 
 void
index 7c43dddd4860bac3e2a608659ee92f0610d4e592..c0391f5015d4a51e72f40ecd266ec1d79d243482 100644 (file)
@@ -360,13 +360,11 @@ check_meshing_chords (Grob *me,
         }
     }
 
-  Direction d = UP;
-  do
+  for (UP_and_DOWN (d))
     {
       for (vsize i = 0; i < clash_groups[d].size (); i++)
         (*offsets)[d][i] += d * shift_amount;
     }
-  while ((flip (&d)) != UP);
 }
 
 MAKE_SCHEME_CALLBACK (Note_collision_interface, calc_positioning_done, 1)
@@ -378,8 +376,7 @@ Note_collision_interface::calc_positioning_done (SCM smob)
 
   Drul_array<vector<Grob *> > clash_groups = get_clash_groups (me);
 
-  Direction d = UP;
-  do
+  for (UP_and_DOWN (d))
     {
       for (vsize i = clash_groups[d].size (); i--;)
         {
@@ -389,13 +386,12 @@ Note_collision_interface::calc_positioning_done (SCM smob)
           clash_groups[d][i]->extent (me, X_AXIS);
         }
     }
-  while (flip (&d) != UP);
 
   SCM autos (automatic_shift (me, clash_groups));
   SCM hand (forced_shift (me));
 
   Real wid = 0.0;
-  do
+  for (UP_and_DOWN (d))
     {
       if (clash_groups[d].size ())
         {
@@ -405,7 +401,6 @@ Note_collision_interface::calc_positioning_done (SCM smob)
             wid = fh->extent (h, X_AXIS).length ();
         }
     }
-  while (flip (&d) != UP);
 
   vector<Grob *> done;
   Real left_most = 1e6;
@@ -460,13 +455,11 @@ Note_collision_interface::get_clash_groups (Grob *me)
         }
     }
 
-  Direction d = UP;
-  do
+  for (UP_and_DOWN (d))
     {
       vector<Grob *> &clashes (clash_groups[d]);
       vector_sort (clashes, Note_column::shift_less);
     }
-  while ((flip (&d)) != UP);
 
   return clash_groups;
 }
@@ -482,8 +475,7 @@ Note_collision_interface::automatic_shift (Grob *me,
   Drul_array < vector<int> > shifts;
   SCM tups = SCM_EOL;
 
-  Direction d = UP;
-  do
+  for (UP_and_DOWN (d))
     {
       vector<int> &shift (shifts[d]);
       vector<Grob *> &clashes (clash_groups[d]);
@@ -508,12 +500,10 @@ Note_collision_interface::automatic_shift (Grob *me,
             }
         }
     }
-  while ((flip (&d)) != UP);
 
   Drul_array<vector<Slice> > extents;
   Drul_array<vector<Real> > offsets;
-  d = UP;
-  do
+  for (UP_and_DOWN (d))
     {
       for (vsize i = 0; i < clash_groups[d].size (); i++)
         {
@@ -524,7 +514,6 @@ Note_collision_interface::automatic_shift (Grob *me,
           offsets[d].push_back (d * 0.5 * i);
         }
     }
-  while ((flip (&d)) != UP);
 
   /*
    * do horizontal shifts of each direction
@@ -535,7 +524,7 @@ Note_collision_interface::automatic_shift (Grob *me,
    *   x|
   */
 
-  do
+  for (UP_and_DOWN (d))
     {
       for (vsize i = 1; i < clash_groups[d].size (); i++)
         {
@@ -547,7 +536,6 @@ Note_collision_interface::automatic_shift (Grob *me,
               offsets[d][j] += d * 0.5;
         }
     }
-  while ((flip (&d)) != UP);
 
   /*
     see input/regression/dot-up-voice-collision.ly
@@ -571,14 +559,13 @@ Note_collision_interface::automatic_shift (Grob *me,
 
   check_meshing_chords (me, &offsets, extents, clash_groups);
 
-  do
+  for (UP_and_DOWN (d))
     {
       for (vsize i = 0; i < clash_groups[d].size (); i++)
         tups = scm_cons (scm_cons (clash_groups[d][i]->self_scm (),
                                    scm_from_double (offsets[d][i])),
                          tups);
     }
-  while (flip (&d) != UP);
 
   return tups;
 }
index 79a57bd47e6d83fcf7fd8ffbb89b57eb94b51658..477236775d553d750f40e4d795e1f52aa71dcccb 100644 (file)
@@ -222,8 +222,6 @@ Note_spacing::stem_dir_correction (Grob *me, Item *rcolumn,
   Interval bar_xextent;
   Interval bar_yextent;
 
-  Direction d = LEFT;
-
   bool acc_right = false;
 
   Grob *bar = Spacing_interface::extremal_break_aligned_grob (me, RIGHT,
@@ -232,7 +230,7 @@ Note_spacing::stem_dir_correction (Grob *me, Item *rcolumn,
   if (bar && dynamic_cast<Item *> (bar)->get_column () == rcolumn)
     bar_yextent = Staff_spacing::bar_y_positions (bar);
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       vector<Grob *> const &items (ly_scm2link_array (props [d]));
       for (vsize i = 0; i < items.size (); i++)
@@ -280,7 +278,6 @@ Note_spacing::stem_dir_correction (Grob *me, Item *rcolumn,
             }
         }
     }
-  while (flip (&d) != LEFT);
 
   Real correction = 0.0;
 
index b3d5fe1f7b12d9767e9edf1975e2f8b3d258b74c..2b0910f8873600feebf136424c8ffa823d0f93d6 100644 (file)
@@ -161,8 +161,7 @@ Optimal_page_breaking::solve ()
     }
 
   /* try a larger number of systems than the ideal line breaking number. This
-     is more or less C&P, but the loop bounds make it difficult to try something
-     like do {...} while (flip(&d) != UP). */
+     is more or less C&P. */
   bound = ideal_line_division;
   for (vsize sys_count = ideal_sys_count + 1; sys_count <= max_sys_count; sys_count++)
     {
index cbe9928b6e977b12b31d4e31aa913c9e2c667232..f70a30b404e1125ed6ee252c1a820f581b8d52d6 100644 (file)
@@ -56,8 +56,7 @@ Ottava_bracket::print (SCM smob)
   Output_def *layout = me->layout ();
 
   Drul_array<bool> broken;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Item *b = me->get_bound (d);
       broken[d] = (b->break_status_dir () != CENTER);
@@ -75,7 +74,6 @@ Ottava_bracket::print (SCM smob)
             }
         }
     }
-  while (flip (&d) != LEFT);
 
   SCM properties = Font_interface::text_font_alist_chain (me);
   SCM markup = me->get_property ("text");
@@ -91,7 +89,7 @@ Ottava_bracket::print (SCM smob)
     TODO: we should check if there are ledgers, and modify length of
     the spanner to that.
   */
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Item *b = me->get_bound (d);
 
@@ -122,7 +120,6 @@ Ottava_bracket::print (SCM smob)
       else
         span_points[d] = ext[d];
     }
-  while (flip (&d) != LEFT);
 
   /*
     0.3 is ~ italic correction.
@@ -144,13 +141,12 @@ Ottava_bracket::print (SCM smob)
   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
                                                 Interval (0, 0));
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       edge_height[d] *= -get_grob_direction (me);
       if (broken[d])
         edge_height[d] = 0.0;
     }
-  while (flip (&d) != LEFT);
 
   Stencil b;
   Interval empty;
index aafae77401e461555bd3701b35dd022c274de3a3..bd39702bdb59da5c14ef516551455c8f9ce57673 100644 (file)
@@ -99,8 +99,7 @@ Ottava_spanner_engraver::typeset_all ()
 {
   if (finished_)
     {
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           if (!finished_->get_bound (RIGHT))
             {
@@ -108,7 +107,6 @@ Ottava_spanner_engraver::typeset_all ()
               finished_->set_bound (d, e);
             }
         }
-      while (flip (&d) != LEFT);
 
       finished_ = 0;
     }
index a8c5e0eea8d7ed1d1d163606ba91f327f4907912..cdf3d595ca554ec9ee0c1afcf5deaf9fa7aa493f 100644 (file)
@@ -168,14 +168,12 @@ Paper_column::minimum_distance (Grob *left, Grob *right)
   Drul_array<Grob *> cols (left, right);
   Drul_array<Skyline> skys = Drul_array<Skyline> (Skyline (RIGHT), Skyline (LEFT));
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Skyline_pair *sp = Skyline_pair::unsmob (cols[d]->get_property ("horizontal-skylines"));
       if (sp)
         skys[d] = (*sp)[-d];
     }
-  while (flip (&d) != LEFT);
 
   skys[RIGHT].merge (Separation_item::conditional_skyline (right, left));
 
index 4c8efd4d0f7d61b93f33092e724e835c12f3b7f9..534d5812ec95c1c8cfaa88670a8f2fdda2e4e3cf 100644 (file)
@@ -51,8 +51,7 @@ Piano_pedal_bracket::print (SCM smob)
     common = common->common_refpoint (textbit, X_AXIS);
 
   Interval span_points (0, 0);
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Item *b = me->get_bound (d);
       broken[d] = b->break_status_dir () != CENTER;
@@ -71,7 +70,6 @@ Piano_pedal_bracket::print (SCM smob)
       else
         span_points[d] = b->relative_coordinate (common, X_AXIS);
     }
-  while (flip (&d) != LEFT);
 
   /* For 'Mixed' style pedals, i.e.  a bracket preceded by text:  Ped._____|
      need to shorten by the extent of the text grob
index 4c08264687e746063dcd57c3bd38a571fa84df4a..8ba647e2019d8201d3698dbaa39cdd74f6671e90 100644 (file)
@@ -146,13 +146,11 @@ Rest_collision::calc_positioning_done (SCM smob)
             rests[d]->warning (_ ("cannot resolve rest collision: rest direction not set"));
         }
 
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         vector_sort (ordered_rests[d], rest_shift_less);
-      while (flip (&d) != LEFT)
-        ;
 
-      do
+
+      for (LEFT_and_RIGHT (d))
         {
           if (ordered_rests[d].size () < 1)
             {
@@ -162,7 +160,6 @@ Rest_collision::calc_positioning_done (SCM smob)
               return SCM_BOOL_T;
             }
         }
-      while (flip (&d) != LEFT);
 
       Grob *common = common_refpoint_of_array (ordered_rests[DOWN], me, Y_AXIS);
       common = common_refpoint_of_array (ordered_rests[UP], common, Y_AXIS);
@@ -182,7 +179,7 @@ Rest_collision::calc_positioning_done (SCM smob)
                              2 * int (ceil (diff)));
         }
 
-      do
+      for (LEFT_and_RIGHT (d))
         {
           for (vsize i = ordered_rests[d].size () - 1; i-- > 0;)
             {
@@ -194,7 +191,6 @@ Rest_collision::calc_positioning_done (SCM smob)
                 Rest::translate (ordered_rests[d][i], d * (int) ceil (diff) * 2);
             }
         }
-      while (flip (&d) != LEFT);
     }
   else
     {
index d5eaa4de3fd57c578d9c88aa1dbc176d9875df14..f7b38397c5d632de983f5051ac2697aab550fd1f 100644 (file)
@@ -37,14 +37,12 @@ Rod::columnize ()
       || !item_drul_[RIGHT])
     return;
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Paper_column *pc = item_drul_[d]->get_column ();
       distance_ += -d * item_drul_[d]->relative_coordinate (pc, X_AXIS);
       item_drul_[d] = pc;
     }
-  while ((flip (&d)) != LEFT);
 }
 
 void
index d2655dc773f08f17b76b4d995a25afac41d2d66c..0a014a38008bb3e57aafb92a3671aa90b0c8ac95 100644 (file)
@@ -132,8 +132,7 @@ Script_column::order_grobs (vector<Grob *> grobs)
       scripts_drul[d] = scm_cons (g->self_scm (), scripts_drul[d]);
     }
 
-  Direction d = DOWN;
-  do
+  for (DOWN_and_UP (d))
     {
       SCM ss = scm_reverse_x (scripts_drul[d], SCM_EOL);
       ss = scm_stable_sort_x (ss, ly_grob_script_priority_less_proc);
@@ -172,7 +171,6 @@ Script_column::order_grobs (vector<Grob *> grobs)
             }
         }
     }
-  while (flip (&d) != DOWN);
 }
 
 ADD_INTERFACE (Script_column,
index 32597210e1d1057e3bc7c675e2019bda646c171a..d6d231de305e2b90c6aabdb80ea581c6dfb35064 100644 (file)
@@ -93,10 +93,8 @@ fit_factor (Offset dz_unit, Offset dz_perp, Real close_to_edge_length,
                 d * dot_product (z, dz_perp));
 
       bool close_to_edge = false;
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         close_to_edge = close_to_edge || -d * (p[X_AXIS] - curve_xext[d]) < close_to_edge_length;
-      while (flip (&d) != LEFT);
 
       if (close_to_edge)
         continue;
@@ -333,11 +331,11 @@ Slur_configuration::score_extra_encompass (Slur_score_state const &state)
         to prevent numerical inaccuracies in
         Bezier::get_other_coordinate ().
       */
-      Direction d = LEFT;
+
       bool found = false;
       Real y = 0.0;
 
-      do
+      for (LEFT_and_RIGHT (d))
         {
           /*
             We need to check for the bound explicitly, since the
@@ -358,7 +356,6 @@ Slur_configuration::score_extra_encompass (Slur_score_state const &state)
             }
 
         }
-      while (flip (&d) != LEFT);
 
       if (!found)
         {
@@ -396,11 +393,11 @@ Slur_configuration::score_extra_encompass (Slur_score_state const &state)
 void
 Slur_configuration::score_edges (Slur_score_state const &state)
 {
-  Direction d = LEFT;
+
   Offset dz = attachment_[RIGHT]
               - attachment_[LEFT];
   Real slope = dz[Y_AXIS] / dz[X_AXIS];
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Real y = attachment_[d][Y_AXIS];
       Real dy = fabs (y - state.base_attachments_[d][Y_AXIS]);
@@ -419,7 +416,6 @@ Slur_configuration::score_edges (Slur_score_state const &state)
       string dir_str = d == LEFT ? "L" : "R";
       add_score (demerit, dir_str + " edge");
     }
-  while (flip (&d) != LEFT);
 }
 
 void
index 543137dc486b368edea25cb69ac2eaf536512df8..eaadde5c587031a50ae5ad35be5e55ed59d22f84 100644 (file)
@@ -156,10 +156,9 @@ Slur_score_state::get_bound_info () const
 {
   Drul_array<Bound_info> extremes;
 
-  Direction d = LEFT;
   Direction dir = dir_;
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       extremes[d].bound_ = slur_->get_bound (d);
       if (Note_column::has_interface (extremes[d].bound_))
@@ -203,7 +202,6 @@ Slur_score_state::get_bound_info () const
 
         }
     }
-  while (flip (&d) != LEFT);
 
   return extremes;
 }
@@ -240,8 +238,7 @@ Slur_score_state::fill (Grob *me)
       common_[a] = common_refpoint_of_array (columns, me, a);
       common_[a] = common_refpoint_of_array (extra_objects, common_[a], a);
 
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           /*
             If bound is not in note-columns, we don't want to know about
@@ -250,7 +247,6 @@ Slur_score_state::fill (Grob *me)
           if (a != Y_AXIS)
             common_[a] = common_[a]->common_refpoint (sp->get_bound (d), a);
         }
-      while (flip (&d) != LEFT);
     }
 
   extremes_ = get_bound_info ();
@@ -287,8 +283,7 @@ Slur_score_state::fill (Grob *me)
               && !Clef::has_interface (extra_encompass_infos_[i].grob_)
               && !Time_signature::has_interface (extra_encompass_infos_[i].grob_)))
         {
-          Direction d = LEFT;
-          do
+          for (LEFT_and_RIGHT (d))
             additional_ys[d] = minmax (dir_,
                                        additional_ys[d],
                                        (dir_
@@ -298,14 +293,11 @@ Slur_score_state::fill (Grob *me)
                                                          base_attachments_[RIGHT][X_AXIS],
                                                          base_attachments_[LEFT][X_AXIS])
                                               + (dir_ == LEFT ? 0 : -1)))));
-          while (flip (&d) != LEFT);
         }
     }
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     end_ys[d] += additional_ys[d];
-  while (flip (&d) != LEFT);
 
   configurations_ = enumerate_attachments (end_ys);
   for (vsize i = 0; i < columns_.size (); i++)
@@ -314,14 +306,13 @@ Slur_score_state::fill (Grob *me)
   valid_ = true;
 
   musical_dy_ = 0.0;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (!is_broken_
           && extremes_[d].slur_head_)
         musical_dy_ += d
                        * extremes_[d].slur_head_->relative_coordinate (common_[Y_AXIS], Y_AXIS);
     }
-  while (flip (&d) != LEFT);
 
   edge_has_beams_
     = (extremes_[LEFT].stem_ && Stem::get_beam (extremes_[LEFT].stem_))
@@ -457,8 +448,7 @@ Drul_array<Real>
 Slur_score_state::get_y_attachment_range () const
 {
   Drul_array<Real> end_ys;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (extremes_[d].note_column_)
         {
@@ -471,7 +461,6 @@ Slur_score_state::get_y_attachment_range () const
       else
         end_ys[d] = base_attachments_[d][Y_AXIS] + parameters_.region_size_ * dir_;
     }
-  while (flip (&d) != LEFT);
 
   return end_ys;
 }
@@ -480,13 +469,11 @@ bool
 spanner_less (Spanner *s1, Spanner *s2)
 {
   Slice b1, b2;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       b1[d] = s1->get_bound (d)->get_column ()->get_rank ();
       b2[d] = s2->get_bound (d)->get_column ()->get_rank ();
     }
-  while (flip (&d) != LEFT);
 
   return b2[LEFT] <= b1[LEFT] && b2[RIGHT] >= b1[RIGHT]
          && (b2[LEFT] != b1[LEFT] || b2[RIGHT] != b1[RIGHT]);
@@ -496,8 +483,7 @@ Drul_array<Offset>
 Slur_score_state::get_base_attachments () const
 {
   Drul_array<Offset> base_attachment;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Grob *stem = extremes_[d].stem_;
       Grob *head = extremes_[d].slur_head_;
@@ -532,9 +518,8 @@ Slur_score_state::get_base_attachments () const
         }
       base_attachment[d] = Offset (x, y);
     }
-  while (flip (&d) != LEFT);
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (!extremes_[d].note_column_)
         {
@@ -570,9 +555,8 @@ Slur_score_state::get_base_attachments () const
           base_attachment[d] = Offset (x, y);
         }
     }
-  while (flip (&d) != LEFT);
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       for (int a = X_AXIS; a < NO_AXES; a++)
         {
@@ -585,7 +569,6 @@ Slur_score_state::get_base_attachments () const
             }
         }
     }
-  while (flip (&d) != LEFT);
 
   return base_attachment;
 }
@@ -687,9 +670,9 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
       os[RIGHT] = base_attachments_[RIGHT];
       for (int j = 0; dir_ * os[RIGHT][Y_AXIS] <= dir_ * end_ys[RIGHT]; j++)
         {
-          Direction d = LEFT;
+
           Drul_array<bool> attach_to_stem (false, false);
-          do
+          for (LEFT_and_RIGHT (d))
             {
               os[d][X_AXIS] = base_attachments_[d][X_AXIS];
               if (extremes_[d].stem_
@@ -711,14 +694,13 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
                     os[d][X_AXIS] = extremes_[d].stem_extent_[X_AXIS].center ();
                 }
             }
-          while (flip (&d) != LEFT);
 
           Offset dz;
           dz = os[RIGHT] - os[LEFT];
           if (dz[X_AXIS] < minimum_length
               || fabs (dz[Y_AXIS] / dz[X_AXIS]) > parameters_.max_slope_)
             {
-              do
+              for (LEFT_and_RIGHT (d))
                 {
                   if (extremes_[d].slur_head_
                       && !extremes_[d].slur_head_x_extent_.is_empty ())
@@ -727,11 +709,10 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
                       attach_to_stem[d] = false;
                     }
                 }
-              while (flip (&d) != LEFT);
             }
 
           dz = os[RIGHT] - os[LEFT];
-          do
+          for (LEFT_and_RIGHT (d))
             {
               if (extremes_[d].slur_head_
                   && !attach_to_stem[d])
@@ -745,7 +726,6 @@ Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
                      * sin (dz.arg ()) / 3;
                 }
             }
-          while (flip (&d) != LEFT);
 
           scores.push_back (Slur_configuration::new_config (os, scores.size ()));
 
index d82633da18b86b6838380e619bfffa9321ee503f..a41aada7a7e5c31ef9e0aaadefe74a79d9486ad3 100644 (file)
@@ -101,10 +101,8 @@ Slur::pure_height (SCM smob, SCM start_scm, SCM end_scm)
       Interval d = encompasses[i]->pure_height (parent, start, end);
       if (!d.is_empty ())
         {
-          Direction downup = DOWN;
-          do
+          for (DOWN_and_UP (downup))
             ret.add_point (d[dir]);
-          while (flip (&downup) != DOWN);
 
           if (extremal_heights[LEFT] == infinity_f)
             extremal_heights[LEFT] = d[dir];
@@ -117,10 +115,8 @@ Slur::pure_height (SCM smob, SCM start_scm, SCM end_scm)
 
   Interval extremal_span;
   extremal_span.set_empty ();
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     extremal_span.add_point (extremal_heights[d]);
-  while (flip (&d) != LEFT);
   ret[-dir] = minmax (dir, extremal_span[-dir], ret[-dir]);
 
   /*
@@ -314,10 +310,8 @@ Slur::outside_slur_callback (SCM grob, SCM offset_scm)
     return offset_scm;
 
   bool contains = false;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     contains |= slur_wid.contains (xext[d]);
-  while (flip (&d) != LEFT);
 
   if (!contains)
     return offset_scm;
@@ -335,8 +329,7 @@ Slur::outside_slur_callback (SCM grob, SCM offset_scm)
   Real EPS = 1.0e-5;
   if (avoid == ly_symbol2scm ("outside"))
     {
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           Real x = minmax (-d, xext[d], curve.control_[d == LEFT ? 0 : 3][X_AXIS] + -d * EPS);
           Real y = curve.get_other_coordinate (X_AXIS, x);
@@ -344,14 +337,12 @@ Slur::outside_slur_callback (SCM grob, SCM offset_scm)
           if (do_shift)
             break;
         }
-      while (flip (&d) != LEFT);
     }
   else
     {
       for (int a = X_AXIS; a < NO_AXES; a++)
         {
-          Direction d = LEFT;
-          do
+          for (LEFT_and_RIGHT (d))
             {
               vector<Real> coords = curve.get_other_coordinates (Axis (a), exts[a][d]);
               for (vsize i = 0; i < coords.size (); i++)
@@ -363,7 +354,6 @@ Slur::outside_slur_callback (SCM grob, SCM offset_scm)
               if (do_shift)
                 break;
             }
-          while (flip (&d) != LEFT);
           if (do_shift)
             break;
         }
index 4fe7885259a336b259e18061252a7cc83b9d7007..785f01039caed06049c4bede4fc60f36555bbc80 100644 (file)
@@ -134,10 +134,9 @@ Spacing_spanner::set_distances_for_loose_col (Grob *me, Grob *c,
                                               Drul_array<Item *> next_door,
                                               Spacing_options const *options)
 {
-  Direction d = LEFT;
   Drul_array<Real> dists (0, 0);
 
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Item *lc = dynamic_cast<Item *> ((d == LEFT) ? next_door[LEFT] : c);
       Item *rc = dynamic_cast<Item *> (d == LEFT ? c : next_door[RIGHT]);
@@ -171,7 +170,6 @@ Spacing_spanner::set_distances_for_loose_col (Grob *me, Grob *c,
             programming_error ("Subversive spacing wish");
         }
     }
-  while (flip (&d) != LEFT);
 
   Rod r;
   r.distance_ = dists[LEFT] + dists[RIGHT];
index 82eb11ef5f1d3816d2e59274c77b531d48236f81..27c99bb15933b06d8279cdf434e937ac6c30ad4b 100644 (file)
@@ -55,8 +55,7 @@ Spacing_interface::skylines (Grob *me, Grob *right_col)
 
   Drul_array<Grob *> columns (left_col, right_col);
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       for (vsize i = 0; i < items[d].size (); i++)
         {
@@ -88,7 +87,6 @@ Spacing_interface::skylines (Grob *me, Grob *right_col)
             }
         }
     }
-  while (flip (&d) != LEFT);
 
   return skylines;
 }
index 1af0ba372075b8746c3eb7c438d03b61129fc088..657ff0cd6a9d2b6541b87bfdd8f6a789dbdcf13b 100644 (file)
@@ -261,8 +261,7 @@ set_column_rods (vector<Grob *> const &cols, Real padding)
           Real left_stickout = skys ? (*skys)[RIGHT].max_height () : 0.0;
           bool done = true;
 
-          Direction d = LEFT;
-          do
+          for (LEFT_and_RIGHT (d))
             {
               if (j < i - 1)
                 cur_dist[d] += distances[j];
@@ -287,8 +286,10 @@ set_column_rods (vector<Grob *> const &cols, Real padding)
 
               cur_dist[d] = max (cur_dist[d], dist);
               done = done && !touches;
+
+              if (!rb)
+                break;
             }
-          while (flip (&d) != LEFT && rb);
 
           /* we need the empty check for gregorian notation, where there are a lot of
              extraneous paper-columns that we need to skip over */
index 92cb9cdf14b102875d0977938f862197ef828a58..9a8ff83a3ffca20c2579e67ec9770b716c5779bc 100644 (file)
@@ -50,8 +50,7 @@ Spanner::do_break_processing ()
       /*
         If we have a spanner spanning one column, we must break it
         anyway because it might provide a parent for another item.  */
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           Item *bound = left->find_prebroken_piece (d);
           if (!bound)
@@ -67,7 +66,6 @@ Spanner::do_break_processing ()
               broken_intos_.push_back (span);
             }
         }
-      while ((flip (&d)) != LEFT);
     }
   else
     {
@@ -95,13 +93,11 @@ Spanner::do_break_processing ()
           Drul_array<Item *> bounds;
           bounds[LEFT] = break_points[i - 1];
           bounds[RIGHT] = break_points[i];
-          Direction d = LEFT;
-          do
+          for (LEFT_and_RIGHT (d))
             {
               if (!bounds[d]->get_system ())
                 bounds[d] = bounds[d]->find_prebroken_piece (- d);
             }
-          while ((flip (&d)) != LEFT);
 
           if (!bounds[LEFT] || ! bounds[RIGHT])
             {
@@ -151,13 +147,11 @@ Spanner::get_break_index () const
 void
 Spanner::set_my_columns ()
 {
-  Direction i = (Direction) LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
-      if (!spanned_drul_[i]->get_system ())
-        set_bound (i, spanned_drul_[i]->find_prebroken_piece ((Direction) - i));
+      if (!spanned_drul_[d]->get_system ())
+        set_bound (d, spanned_drul_[d]->find_prebroken_piece ((Direction) - d));
     }
-  while (flip (&i) != LEFT);
 }
 
 Interval_t<int>
@@ -256,19 +250,15 @@ Spanner::spanner_length () const
       Drul_array<SCM> bounds (get_property ("left-bound-info"),
                               get_property ("right-bound-info"));
 
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         lr[d] = robust_scm2double (ly_assoc_get (ly_symbol2scm ("X"),
                                                  bounds[d], SCM_BOOL_F), -d);
-      while (flip (&d) != LEFT);
     }
 
   if (lr.is_empty ())
     {
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         lr[d] = spanned_drul_[d]->relative_coordinate (0, X_AXIS);
-      while (flip (&d) != LEFT);
     }
 
   if (lr.is_empty ())
@@ -360,11 +350,9 @@ Spanner::derived_mark () const
 {
   scm_gc_mark (pure_property_cache_);
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     if (spanned_drul_[d])
       scm_gc_mark (spanned_drul_[d]->self_scm ());
-  while (flip (&d) != LEFT)
     ;
 
   for (vsize i = broken_intos_.size (); i--;)
index 98627e5783f812ca3c396c6d1feacb636b60a3c7..3b0eef00b5f278e1c52000b3adc2a730d9a24007 100644 (file)
@@ -50,8 +50,7 @@ Staff_symbol::print (SCM smob)
   Real t = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
   t *= robust_scm2double (me->get_property ("thickness"), 1.0);
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       SCM width_scm = me->get_property ("width");
       if (d == RIGHT && scm_is_number (width_scm))
@@ -75,7 +74,6 @@ Staff_symbol::print (SCM smob)
 
       span_points[d] -= d * t / 2;
     }
-  while (flip (&d) != LEFT);
 
   Stencil m;
 
index 47e679712519e198cbc295763c3009cd17706d88..4b5a68510b2752cc43fe4a160e40add3d4673c0b 100644 (file)
@@ -225,8 +225,7 @@ Stem::extremal_heads (Grob *me)
       Grob *n = heads[i];
       int p = Staff_symbol_referencer::get_rounded_position (n);
 
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           if (d * p > d * extpos[d])
             {
@@ -234,7 +233,6 @@ Stem::extremal_heads (Grob *me)
               extpos[d] = p;
             }
         }
-      while (flip (&d) != DOWN);
     }
   return exthead;
 }
@@ -319,10 +317,8 @@ Stem::internal_pure_height (Grob *me, bool calc_beam)
     {
       Interval overshoot;
       Direction dir = get_grob_direction (me);
-      Direction d = DOWN;
-      do
+      for (DOWN_and_UP (d))
         overshoot[d] = d == dir ? dir * infinity_f : iv[d];
-      while (flip (&d) != DOWN);
 
       vector<Interval> heights;
       vector<Grob *> my_stems;
@@ -370,10 +366,8 @@ Stem::cache_pure_height (Grob *me, Interval iv, Interval my_iv)
 {
   Interval overshoot;
   Direction dir = get_grob_direction (me);
-  Direction d = DOWN;
-  do
+  for (DOWN_and_UP (d))
     overshoot[d] = d == dir ? dir * infinity_f : my_iv[d];
-  while (flip (&d) != DOWN);
 
   iv.intersect (overshoot);
   dynamic_cast<Item *> (me)->cache_pure_height (iv);
index 7208a2622bcfc5dccdad051d6bee0866ecab0c86..d4b523c06c63b82094346bc1d13d08af83ae4a4a 100644 (file)
@@ -47,10 +47,8 @@ System_start_delimiter::staff_bracket (Grob *me, Real height)
            * (height / 2 + overlap));
 
   Stencil bracket = Lookup::filled_box (box);
-  Direction d = DOWN;
-  do
+  for (DOWN_and_UP (d))
     bracket.add_at_edge (Y_AXIS, d, tips[d], -overlap);
-  while (flip (&d) != DOWN);
   bracket = Stencil (box, bracket.expr ());
 
   bracket.translate_axis (-0.8, X_AXIS);
index f58f1158d483ef54288b07aff00d81d64d66ce64..fdcc2b133d1b056f78482087218aac7abbc559ff 100644 (file)
@@ -874,14 +874,12 @@ System::calc_pure_relevant_grobs (SCM smob)
 
           if (Item *it = dynamic_cast<Item *> (elts[i]))
             {
-              Direction d = LEFT;
-              do
+              for (LEFT_and_RIGHT (d))
                 {
                   Item *piece = it->find_prebroken_piece (d);
                   if (piece && to_boolean (scm_apply_1 (pure_relevant_p, piece->self_scm (), SCM_EOL)))
                     relevant_grobs.push_back (piece);
                 }
-              while (flip (&d) != LEFT);
             }
         }
     }
index 62edbf68901e23fb69163f22827f5bfa1e67f800..bc14eb9bdf7ea04ffd8b38832bf5e02076bedb7c 100644 (file)
@@ -67,14 +67,12 @@ Tie_column::before_line_breaking (SCM smob)
   for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
     {
       Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
-      Direction dir = LEFT;
-      do
+      for (LEFT_and_RIGHT (dir))
         {
           if (dir * tie->get_bound (dir)->get_column ()->get_rank ()
               > dir * me->get_bound (dir)->get_column ()->get_rank ())
             me->set_bound (dir, Tie::head (tie, dir));
         }
-      while (flip (&dir) != LEFT);
     }
 
   return SCM_UNSPECIFIED;
index 6734003dc142bc4b722f5c996274b6975569ff38..40da0d3e8410663881acd57eb0d191a87626ee35 100644 (file)
@@ -347,16 +347,14 @@ Tie_engraver::typeset_tie (Grob *her)
   if (! (Tie::head (her, LEFT) && Tie::head (her, RIGHT)))
     warning (_ ("lonely tie"));
 
-  Direction d = LEFT;
   Drul_array<Grob *> new_head_drul;
   new_head_drul[LEFT] = Tie::head (her, LEFT);
   new_head_drul[RIGHT] = Tie::head (her, RIGHT);
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (!Tie::head (her, d))
         new_head_drul[d] = Tie::head (her, (Direction) - d);
     }
-  while (flip (&d) != LEFT);
 
   Spanner *sp = dynamic_cast<Spanner *> (her);
   sp->set_bound (LEFT, new_head_drul[LEFT]);
index c4e8a22eb9fc30854393ff1c7c20462dc0d36a43..d93df73abf2ef3db0d49169833cba4b7a2b7dd76 100644 (file)
@@ -56,8 +56,8 @@ Interval
 Tie_formatting_problem::get_attachment (Real y, Drul_array<int> columns) const
 {
   Interval attachments (0, 0);
-  Direction d = LEFT;
-  do
+
+  for (LEFT_and_RIGHT (d))
     {
       Tuple2<int> key (columns[d], int (d));
       Chord_outline_map::const_iterator i (chord_outlines_.find (key));
@@ -66,7 +66,6 @@ Tie_formatting_problem::get_attachment (Real y, Drul_array<int> columns) const
       else
         attachments[d] = i->second.height (y);
     }
-  while (flip (&d) != LEFT);
 
   return attachments;
 }
@@ -227,8 +226,7 @@ Tie_formatting_problem::set_column_chord_outline (vector<Item *> bounds,
 
     }
 
-  Direction updowndir = DOWN;
-  do
+  for (DOWN_and_UP (updowndir))
     {
       Interval x;
       Interval y;
@@ -244,7 +242,6 @@ Tie_formatting_problem::set_column_chord_outline (vector<Item *> bounds,
       if (!x.is_empty ())
         boxes.push_back (Box (x, y));
     }
-  while (flip (&updowndir) != DOWN);
 
   /* todo: the horizon_padding is somewhat arbitrary */
   chord_outlines_[key] = Skyline (boxes, details_.skyline_padding_, Y_AXIS, -dir);
@@ -340,8 +337,7 @@ Tie_formatting_problem::from_ties (vector<Grob *> const &ties)
 
   details_.from_grob (ties[0]);
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       vector<Item *> bounds;
 
@@ -356,19 +352,17 @@ Tie_formatting_problem::from_ties (vector<Grob *> const &ties)
 
       set_chord_outline (bounds, d);
     }
-  while (flip (&d) != LEFT);
 
   for (vsize i = 0; i < ties.size (); i++)
     {
       Tie_specification spec;
       spec.from_grob (ties[i]);
 
-      do
+      for (LEFT_and_RIGHT (d))
         {
           spec.note_head_drul_[d] = Tie::head (ties[i], d);
           spec.column_ranks_[d] = Tie::get_column_rank (ties[i], d);
         }
-      while (flip (&d) != LEFT);
       specifications_.push_back (spec);
     }
 }
@@ -565,8 +559,7 @@ Tie_formatting_problem::generate_configuration (int pos, Direction dir,
         It would be better to check D against HEAD-DIRECTION if
         applicable.
       */
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           Real y = conf->position_ * details_.staff_space_ * 0.5 + conf->delta_y_;
           if (get_stem_extent (conf->column_ranks_[d], d, X_AXIS).is_empty ()
@@ -577,7 +570,6 @@ Tie_formatting_problem::generate_configuration (int pos, Direction dir,
             = d * min (d * conf->attachment_x_[d],
                        d * (get_stem_extent (conf->column_ranks_[d], d, X_AXIS)[-d] - d * details_.stem_gap_));
         }
-      while (flip (&d) != LEFT);
     }
   return conf;
 }
@@ -631,8 +623,7 @@ Tie_formatting_problem::score_aptitude (Tie_configuration *conf,
       penalty += p;
   }
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (!spec.note_head_drul_[d])
         continue;
@@ -652,14 +643,12 @@ Tie_formatting_problem::score_aptitude (Tie_configuration *conf,
         penalty += p;
 
     }
-  while (flip (&d) != LEFT);
 
   if (ties_conf
       && ties_conf->size () == 1)
     {
-      Direction d = LEFT;
       Drul_array<Grob *> stems (0, 0);
-      do
+      for (LEFT_and_RIGHT (d))
         {
           if (!spec.note_head_drul_[d])
             continue;
@@ -669,7 +658,6 @@ Tie_formatting_problem::score_aptitude (Tie_configuration *conf,
               && Stem::is_normal_stem (stem))
             stems[d] = stem;
         }
-      while (flip (&d) != LEFT);
 
       bool tie_stem_dir_ok = true;
       bool tie_position_dir_ok = true;
@@ -1038,11 +1026,10 @@ vector<Tie_configuration_variation>
 Tie_formatting_problem::generate_extremal_tie_variations (Ties_configuration const &ties) const
 {
   vector<Tie_configuration_variation> vars;
-  Direction d = DOWN;
   for (int i = 1; i <= details_.multi_tie_region_size_; i++)
     {
       Drul_array<Tie_configuration *> configs (0, 0);
-      do
+      for (DOWN_and_UP (d))
         {
           const Tie_configuration &config = boundary (ties, d, 0);
           if (config.dir_ == d
@@ -1057,7 +1044,6 @@ Tie_formatting_problem::generate_extremal_tie_variations (Ties_configuration con
               vars.push_back (var);
             }
         }
-      while (flip (&d) != DOWN);
       if (configs[LEFT] && configs[RIGHT])
         {
           Tie_configuration_variation var;
@@ -1080,8 +1066,7 @@ Tie_formatting_problem::generate_single_tie_variations (Ties_configuration const
     sz = 1;
   for (int i = 0; i < sz; i++)
     {
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           if (i == 0
               && ties[0].dir_ == d)
@@ -1100,7 +1085,6 @@ Tie_formatting_problem::generate_single_tie_variations (Ties_configuration const
               vars.push_back (var);
             }
         }
-      while (flip (&d) != LEFT);
     }
   return vars;
 }
index 84dfa29a8239f76e2e6f946e29e2b5307051efca..aaac5fbbd484433bf7498315d7fc7ec3971fbb3c 100644 (file)
@@ -92,14 +92,12 @@ Tie::get_column_rank (Grob *me, Direction d)
 int
 Tie::get_position (Grob *me)
 {
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Grob *h = head (me, d);
       if (h)
         return (int) rint (Staff_symbol_referencer::get_position (h));
     }
-  while (flip (&d) != LEFT);
 
   /*
     TODO: this is theoretically possible for ties across more than 2
@@ -125,8 +123,7 @@ Direction
 Tie::get_default_dir (Grob *me)
 {
   Drul_array<Grob *> stems;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Grob *one_head = head (me, d);
       if (!one_head && dynamic_cast<Spanner *> (me))
@@ -138,7 +135,6 @@ Tie::get_default_dir (Grob *me)
 
       stems[d] = stem;
     }
-  while (flip (&d) != LEFT);
 
   if (stems[LEFT] && stems[RIGHT])
     {
index ba0ef6e236b3df365c876ae25d8b1528699bc0ac..37099683bf859b33cf91cbcf5fea282f60c74087 100644 (file)
@@ -106,10 +106,8 @@ Tuplet_bracket::parallel_beam (Grob *me_grob, vector<Grob *> const &cols,
     return 0;
 
   Drul_array<Grob *> beams;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     beams[d] = stems[d] ? Stem::get_beam (stems[d]) : 0;
-  while (flip (&d) != LEFT);
 
   *equally_long = false;
   if (! (beams[LEFT] && (beams[LEFT] == beams[RIGHT]) && !me->is_broken ()))
@@ -140,8 +138,7 @@ Tuplet_bracket::calc_connect_to_neighbors (SCM smob)
                              get_x_bound_item (me, RIGHT, dir));
 
   Drul_array<bool> connect_to_other (false, false);
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       Direction break_dir = bounds[d]->break_status_dir ();
       Spanner *orig_spanner = dynamic_cast<Spanner *> (me->original ());
@@ -161,7 +158,6 @@ Tuplet_bracket::calc_connect_to_neighbors (SCM smob)
            && neighbor_idx < orig_spanner->broken_intos_.size ()
            && orig_spanner->broken_intos_[neighbor_idx]->is_live ());
     }
-  while (flip (&d) != LEFT);
 
   if (connect_to_other[LEFT] || connect_to_other[RIGHT])
     return scm_cons (scm_from_bool (connect_to_other[LEFT]),
@@ -201,8 +197,7 @@ Tuplet_bracket::calc_x_positions (SCM smob)
                            Drul_array<bool> (false, false));
 
   Interval x_span;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       x_span[d] = bounds[d]->break_status_dir ()
                   ? Axis_group_interface::generic_bound_extent (bounds[d], commonx, X_AXIS)[d]
@@ -245,7 +240,6 @@ Tuplet_bracket::calc_x_positions (SCM smob)
           x_span[d] = coord - padding;
         }
     }
-  while (flip (&d) != LEFT);
 
   return ly_interval2scm (x_span - me->get_bound (LEFT)->relative_coordinate (commonx, X_AXIS));
 }
@@ -303,10 +297,8 @@ Tuplet_bracket::print (SCM smob)
   Interval positions = robust_scm2interval (scm_positions, Interval (0.0, 0.0));
 
   Drul_array<Offset> points;
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     points[d] = Offset (x_span[d], positions[d]);
-  while (flip (&d) != LEFT);
 
   Output_def *pap = me->layout ();
 
@@ -351,8 +343,7 @@ Tuplet_bracket::print (SCM smob)
         = robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
                                Drul_array<bool> (false, false));
 
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           if (connect_to_other[d])
             {
@@ -380,7 +371,6 @@ Tuplet_bracket::print (SCM smob)
                 }
             }
         }
-      while (flip (&d) != LEFT);
 
       Stencil brack = make_bracket (me, Y_AXIS,
                                     points[RIGHT] - points[LEFT],
@@ -392,12 +382,11 @@ Tuplet_bracket::print (SCM smob)
                                     Interval (-0.5, 0.5) * gap + 0.1,
                                     flare, shorten);
 
-      do
+      for (LEFT_and_RIGHT (d))
         {
           if (!edge_stencils[d].is_empty ())
             brack.add_stencil (edge_stencils[d]);
         }
-      while (flip (&d) != LEFT);
 
       mol.add_stencil (brack);
     }
@@ -430,29 +419,25 @@ Tuplet_bracket::make_bracket (Grob *me, // for line properties.
 
   Drul_array<Offset> straight_corners = corners;
 
-  Direction d = LEFT;
-  do
+  for (LEFT_and_RIGHT (d))
     straight_corners[d] += -d * shorten[d] / length * dz;
-  while (flip (&d) != LEFT);
 
   if (!gap.is_empty ())
     {
-      do
+      for (LEFT_and_RIGHT (d))
         gap_corners[d] = (dz * 0.5) + gap[d] / length * dz;
-      while (flip (&d) != LEFT);
     }
 
   Drul_array<Offset> flare_corners = straight_corners;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       flare_corners[d][bracket_axis] = straight_corners[d][bracket_axis];
       flare_corners[d][protrusion_axis] += height[d];
       straight_corners[d][bracket_axis] += -d * flare[d];
     }
-  while (flip (&d) != LEFT);
 
   Stencil m;
-  do
+  for (LEFT_and_RIGHT (d))
     {
       if (!gap.is_empty ())
         m.add_stencil (Line_interface::line (me, straight_corners[d],
@@ -462,8 +447,6 @@ Tuplet_bracket::make_bracket (Grob *me, // for line properties.
                                            flare_corners[d]));
     }
 
-  while (flip (&d) != LEFT);
-
   if (gap.is_empty ())
     m.add_stencil (Line_interface::line (me, straight_corners[LEFT],
                                          straight_corners[RIGHT]));
@@ -551,8 +534,7 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy)
                                 Note_column::get_stem (columns.back ()));
 
       Interval poss;
-      Direction side = LEFT;
-      do
+      for (LEFT_and_RIGHT (side))
         {
           // Trigger setting of stem lengths if necessary.
           if (Grob *beam = Stem::get_beam (stems[side]))
@@ -560,7 +542,6 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy)
           poss[side] = stems[side]->extent (stems[side], Y_AXIS)[get_grob_direction (stems[side])]
                        + stems[side]->get_parent (Y_AXIS)->relative_coordinate (commony, Y_AXIS);
         }
-      while (flip (&side) != LEFT);
 
       *dy = poss[RIGHT] - poss[LEFT];
       points.push_back (Offset (stems[LEFT]->relative_coordinate (commonx, X_AXIS) - x0, poss[LEFT]));
@@ -630,14 +611,13 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy)
       if (!tuplets[i]->is_live ())
         continue;
 
-      Direction d = LEFT;
       Drul_array<Real> positions
         = robust_scm2interval (tuplets[i]->get_property ("positions"),
                                Interval (0, 0));
 
       Real other_dy = positions[RIGHT] - positions[LEFT];
 
-      do
+      for (LEFT_and_RIGHT (d))
         {
           Real y
             = tuplet_y.linear_combination (d * sign (other_dy));
@@ -650,7 +630,7 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy)
 
           points.push_back (Offset (tuplet_x[d] - x0, y));
         }
-      while (flip (&d) != LEFT);
+
       // Check for number-on-bracket collisions
       Grob *number = unsmob_grob (tuplets[i]->get_object ("tuplet-number"));
       if (number)
@@ -779,10 +759,8 @@ Tuplet_bracket::get_default_dir (Grob *me)
           Direction d = Note_column::dir (columns[i]);
           extremal_positions[d] = minmax (d, 1.0 * Note_column::head_positions_interval (columns[i])[d], extremal_positions[d]);
         }
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         extremal_positions[d] = -d * (staff_extent[d] - extremal_positions[d]);
-      while (flip (&d) != LEFT);
 
       return extremal_positions[UP] <= extremal_positions[DOWN] ? UP : DOWN;
     }