]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
Issue 4550 (2/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / beam.cc
index a9a19b38c72fae30731caa1f58dea78b65499a6d..d1032184a9c4da42075c2547a0baaaf9a503a4e1 100644 (file)
 
 #include <map>
 
+using std::map;
+using std::string;
+using std::vector;
+
 Beam_stem_segment::Beam_stem_segment ()
 {
   max_connect_ = 1000;          // infinity
@@ -119,11 +123,13 @@ Beam::get_beam_translation (Grob *me)
   Real beam_thickness = get_beam_thickness (me);
   Real fract = robust_scm2double (me->get_property ("length-fraction"), 1.0);
 
-  Real beam_translation = beam_count < 4
-                          ? (2 * staff_space + line - beam_thickness) / 2.0
-                          : (3 * staff_space + line - beam_thickness) / 3.0;
-
-  return fract * beam_translation;
+  /*
+    if fract != 1.0, as is the case for grace notes, we want the gap
+    to decrease too. To achieve this, we divide the thickness by
+    fract */
+  return (beam_count < 4
+          ? (2 * staff_space * fract + line * fract - beam_thickness) / 2.0
+          : (3 * staff_space * fract + line * fract - beam_thickness) / 3.0);
 }
 
 /* Maximum beam_count. */
@@ -136,7 +142,7 @@ Beam::get_beam_count (Grob *me)
   for (vsize i = 0; i < stems.size (); i++)
     {
       Grob *stem = stems[i];
-      m = max (m, (Stem::beam_multiplicity (stem).length () + 1));
+      m = std::max (m, (Stem::beam_multiplicity (stem).length () + 1));
     }
   return m;
 }
@@ -145,11 +151,11 @@ MAKE_SCHEME_CALLBACK (Beam, calc_normal_stems, 1);
 SCM
 Beam::calc_normal_stems (SCM smob)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
 
   extract_grob_set (me, "stems", stems);
   SCM val = Grob_array::make_array ();
-  Grob_array *ga = Grob_array::unsmob (val);
+  Grob_array *ga = unsmob<Grob_array> (val);
   for (vsize i = 0; i < stems.size (); i++)
     if (Stem::is_normal_stem (stems[i]))
       ga->add (stems[i]);
@@ -161,7 +167,7 @@ MAKE_SCHEME_CALLBACK (Beam, calc_direction, 1);
 SCM
 Beam::calc_direction (SCM smob)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
 
   /* Beams with less than 2 two stems don't make much sense, but could happen
      when you do
@@ -203,7 +209,8 @@ Beam::calc_direction (SCM smob)
              placing this here avoids warnings downstream */
           if (heads.size())
             {
-               if (heads[0]->get_property ("style") == ly_symbol2scm ("kievan"))
+               if (scm_is_eq (heads[0]->get_property ("style"),
+                              ly_symbol2scm ("kievan")))
                  {
                     if (dir == CENTER)
                       dir = DOWN;
@@ -256,7 +263,7 @@ position_with_maximal_common_beams (SCM left_beaming, SCM right_beaming,
       for (SCM s = scm_car (right_beaming); scm_is_pair (s); s = scm_cdr (s))
         {
           int k = -right_dir * scm_to_int (scm_car (s)) + i;
-          if (scm_c_memq (scm_from_int (k), left_beaming) != SCM_BOOL_F)
+          if (scm_is_true (scm_c_memq (scm_from_int (k), left_beaming)))
             count++;
         }
 
@@ -274,7 +281,7 @@ MAKE_SCHEME_CALLBACK (Beam, calc_beaming, 1)
 SCM
 Beam::calc_beaming (SCM smob)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
 
   extract_grob_set (me, "stems", stems);
 
@@ -353,7 +360,7 @@ Beam::calc_beam_segments (SCM smob)
 {
   /* ugh, this has a side-effect that we need to ensure that
      Stem #'beaming is correct */
-  Grob *me_grob = Grob::unsmob (smob);
+  Grob *me_grob = unsmob<Grob> (smob);
   (void) me_grob->get_property ("beaming");
 
   Spanner *me = dynamic_cast<Spanner *> (me_grob);
@@ -434,7 +441,7 @@ Beam::calc_beam_segments (SCM smob)
        i != stem_segments.end (); i++)
     {
       vector<Beam_stem_segment> segs = (*i).second;
-      vector_sort (segs, less<Beam_stem_segment> ());
+      vector_sort (segs, std::less<Beam_stem_segment> ());
 
       Beam_segment current;
 
@@ -508,7 +515,7 @@ Beam::calc_beam_segments (SCM smob)
                           Grob *neighbor_stem = stems[seg.stem_index_ + event_dir];
                           Real neighbor_stem_x = neighbor_stem->relative_coordinate (commonx, X_AXIS);
 
-                          length = min (length,
+                          length = std::min (length,
                                         fabs (neighbor_stem_x - seg.stem_x_) * max_proportion[seg.dir_]);
                         }
                       current.horizontal_[event_dir] += event_dir * length;
@@ -533,7 +540,7 @@ Beam::calc_beam_segments (SCM smob)
 
                           for (vsize k = 0; k < heads.size (); k++)
                             current.horizontal_[event_dir]
-                              = event_dir * min (event_dir * current.horizontal_[event_dir],
+                              = event_dir * std::min (event_dir * current.horizontal_[event_dir],
                                                  - gap_length / 2
                                                  + event_dir
                                                  * heads[k]->extent (commonx,
@@ -570,7 +577,7 @@ MAKE_SCHEME_CALLBACK (Beam, calc_x_positions, 1);
 SCM
 Beam::calc_x_positions (SCM smob)
 {
-  Spanner *me = Spanner::unsmob (smob);
+  Spanner *me = unsmob<Spanner> (smob);
   SCM segments = me->get_property ("beam-segments");
   Interval x_positions;
   x_positions.set_empty ();
@@ -611,7 +618,7 @@ MAKE_SCHEME_CALLBACK (Beam, print, 1);
 SCM
 Beam::print (SCM grob)
 {
-  Spanner *me = Spanner::unsmob (grob);
+  Spanner *me = unsmob<Spanner> (grob);
   /*
     TODO - mild code dup for all the commonx calls.
     Some use just common_refpoint_of_array, some (in print and
@@ -739,7 +746,7 @@ Beam::print (SCM grob)
 
       Direction stem_dir = stems.size () ? to_dir (stems[0]->get_property ("direction")) : UP;
 
-      Stencil score = *Stencil::unsmob (Text_interface::interpret_markup
+      Stencil score = *unsmob<Stencil> (Text_interface::interpret_markup
                                        (me->layout ()->self_scm (), properties, annotation));
 
       if (!score.is_empty ())
@@ -766,7 +773,7 @@ Beam::get_default_dir (Grob *me)
       for (DOWN_and_UP (d))
         {
           if (sign (positions[d]) == d)
-            extremes[d] = d * max (d * positions[d], d * extremes[d]);
+            extremes[d] = d * std::max (d * positions[d], d * extremes[d]);
         }
     }
 
@@ -793,7 +800,7 @@ Beam::get_default_dir (Grob *me)
       if (stem_dir)
         {
           count[stem_dir]++;
-          total[stem_dir] += max (int (- stem_dir * Stem::head_positions (s) [-stem_dir]), 0);
+          total[stem_dir] += std::max (int (- stem_dir * Stem::head_positions (s) [-stem_dir]), 0);
         }
     }
 
@@ -870,11 +877,11 @@ Beam::consider_auto_knees (Grob *me)
     {
       Grob *stem = stems[i];
 
-      Interval head_extents = Stem::head_positions (stem);
-      if (!head_extents.is_empty ())
+      Interval head_extents;
+      if (Stem::head_count (stem))
         {
-          head_extents[LEFT] += -1;
-          head_extents[RIGHT] += 1;
+          head_extents = Stem::head_positions (stem);
+          head_extents.widen (1);
           head_extents *= staff_space * 0.5;
 
           /*
@@ -947,7 +954,7 @@ MAKE_SCHEME_CALLBACK (Beam, calc_stem_shorten, 1)
 SCM
 Beam::calc_stem_shorten (SCM smob)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
 
   /*
     shortening looks silly for x staff beams
@@ -961,7 +968,7 @@ Beam::calc_stem_shorten (SCM smob)
   int beam_count = get_beam_count (me);
 
   SCM shorten_list = me->get_property ("beamed-stem-shorten");
-  if (shorten_list == SCM_EOL)
+  if (scm_is_null (shorten_list))
     return scm_from_int (0);
 
   Real staff_space = Staff_symbol_referencer::staff_space (me);
@@ -982,7 +989,7 @@ MAKE_SCHEME_CALLBACK (Beam, quanting, 3);
 SCM
 Beam::quanting (SCM smob, SCM ys_scm, SCM align_broken_intos)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
   Drul_array<Real> ys = robust_scm2drul (ys_scm, Drul_array<Real> (infinity_f, -infinity_f));
   bool cbs = to_boolean (align_broken_intos);
 
@@ -1003,7 +1010,7 @@ where_are_the_whole_beams (SCM beaming)
 
   for (SCM s = scm_car (beaming); scm_is_pair (s); s = scm_cdr (s))
     {
-      if (scm_c_memq (scm_car (s), scm_cdr (beaming)) != SCM_BOOL_F)
+      if (scm_is_true (scm_c_memq (scm_car (s), scm_cdr (beaming))))
 
         l.add_point (scm_to_int (scm_car (s)));
     }
@@ -1064,7 +1071,7 @@ MAKE_SCHEME_CALLBACK (Beam, set_stem_lengths, 1);
 SCM
 Beam::set_stem_lengths (SCM smob)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
 
   /* trigger callbacks. */
   (void) me->get_property ("direction");
@@ -1139,14 +1146,14 @@ Beam::set_beaming (Grob *me, Beaming_pattern const *beaming)
         {
           Grob *stem = stems[i];
           SCM beaming_prop = stem->get_property ("beaming");
-          if (beaming_prop == SCM_EOL
-              || index_get_cell (beaming_prop, d) == SCM_EOL)
+          if (scm_is_null (beaming_prop)
+              || scm_is_null (index_get_cell (beaming_prop, d)))
             {
               int count = beaming->beamlet_count (i, d);
               if (i > 0
                   && i + 1 < stems.size ()
                   && Stem::is_invisible (stem))
-                count = min (count, beaming->beamlet_count (i, -d));
+                count = std::min (count, beaming->beamlet_count (i, -d));
 
               if ( ((i == 0 && d == LEFT)
                     || (i == stems.size () - 1 && d == RIGHT))
@@ -1217,19 +1224,19 @@ MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Beam, rest_collision_callback, 2, 1, "");
 SCM
 Beam::rest_collision_callback (SCM smob, SCM prev_offset)
 {
-  Grob *rest = Grob::unsmob (smob);
+  Grob *rest = unsmob<Grob> (smob);
   if (scm_is_number (rest->get_property ("staff-position")))
     return scm_from_int (0);
 
   Real offset = robust_scm2double (prev_offset, 0.0);
 
-  Grob *st = Grob::unsmob (rest->get_object ("stem"));
+  Grob *st = unsmob<Grob> (rest->get_object ("stem"));
   Grob *stem = st;
   if (!stem)
     return scm_from_double (0.0);
-  Grob *beam = Grob::unsmob (stem->get_object ("beam"));
+  Grob *beam = unsmob<Grob> (stem->get_object ("beam"));
   if (!beam
-      || !Beam::has_interface (beam)
+      || !has_interface<Beam> (beam)
       || !Beam::normal_stem_count (beam))
     return scm_from_double (0.0);
 
@@ -1281,7 +1288,7 @@ Beam::rest_collision_callback (SCM smob, SCM prev_offset)
     = staff_space * (robust_scm2double (stem->get_property ("stemlet-length"), 0.0)
                      + robust_scm2double (rest->get_property ("minimum-distance"), 0.0));
 
-  Real shift = d * min (d * (beam_y - d * minimum_distance - rest_dim), 0.0);
+  Real shift = d * std::min (d * (beam_y - d * minimum_distance - rest_dim), 0.0);
 
   shift /= staff_space;
 
@@ -1312,11 +1319,11 @@ Beam::pure_rest_collision_callback (SCM smob,
 {
   Real previous = robust_scm2double (prev_offset, 0.0);
 
-  Grob *me = Grob::unsmob (smob);
-  Grob *stem = Grob::unsmob (me->get_object ("stem"));
+  Grob *me = unsmob<Grob> (smob);
+  Grob *stem = unsmob<Grob> (me->get_object ("stem"));
   if (!stem)
     return scm_from_double (previous);
-  Grob *beam = Grob::unsmob (stem->get_object ("beam"));
+  Grob *beam = unsmob<Grob> (stem->get_object ("beam"));
   if (!beam
       || !Beam::normal_stem_count (beam)
       || !is_direction (beam->get_property_data ("direction")))
@@ -1360,7 +1367,7 @@ Beam::pure_rest_collision_callback (SCM smob,
                    + Stem::head_positions (right)[beamdir]) / 2.0
                   + 4.0 * beamdir; // four staff-positions
   /* and that the closest beam never crosses staff center by more than two positions */
-  beam_pos = max (-2.0, beam_pos * beamdir) * beamdir;
+  beam_pos = std::max (-2.0, beam_pos * beamdir) * beamdir;
 
   Real minimum_distance
     = ss * (robust_scm2double (stem->get_property ("stemlet-length"), 0.0)
@@ -1370,7 +1377,7 @@ Beam::pure_rest_collision_callback (SCM smob,
                 - me->extent (me, Y_AXIS)[beamdir];
 
   /* Always move by a whole number of staff spaces, always away from the beam */
-  offset = floor (min (0.0, (offset - previous) / ss * beamdir))
+  offset = floor (std::min (0.0, (offset - previous) / ss * beamdir))
            * ss * beamdir + previous;
 
   return scm_from_double (offset);
@@ -1417,7 +1424,7 @@ MAKE_SCHEME_CALLBACK (Beam, calc_cross_staff, 1)
 SCM
 Beam::calc_cross_staff (SCM smob)
 {
-  return scm_from_bool (is_cross_staff (Grob::unsmob (smob)));
+  return scm_from_bool (is_cross_staff (unsmob<Grob> (smob)));
 }
 
 int
@@ -1432,7 +1439,7 @@ Beam::get_direction_beam_count (Grob *me, Direction d)
         Should we take invisible stems into account?
       */
       if (get_grob_direction (stems[i]) == d)
-        bc = max (bc, (Stem::beam_multiplicity (stems[i]).length () + 1));
+        bc = std::max (bc, (Stem::beam_multiplicity (stems[i]).length () + 1));
     }
 
   return bc;