]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
fix Skyline::distance calculation
[lilypond.git] / lily / beam.cc
index 497957b465b9a101a04e91a5ebff19e6b1d28776..0778c5838884749ae4a85bb2e912008c0100511a 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "beam.hh"
 
-#include "beaming.hh"
+#include "beaming-pattern.hh"
 #include "directional-element-interface.hh"
 #include "main.hh"
 #include "international.hh"
@@ -52,6 +52,7 @@
 
 Beam_stem_segment::Beam_stem_segment ()
 {
+  max_connect_ = 1000;         // infinity
   stem_ = 0;
   width_ = 0.0;
   stem_x_ = 0.0;
@@ -128,10 +129,9 @@ Beam::calc_direction (SCM smob)
   /* Beams with less than 2 two stems don't make much sense, but could happen
      when you do
 
-     [r8 c8 r8].
+     r8[ c8 r8]
 
-     For a beam that  only has one stem, we try to do some disappearance magic:
-     we revert the flag, and move on to The Eternal Engraving Fields. */
+  */
 
   Direction dir = CENTER;
 
@@ -296,6 +296,10 @@ typedef map<int, vector<Beam_stem_segment> >  Position_stem_segments_map;
 vector<Beam_segment>
 Beam::get_beam_segments (Grob *me_grob, Grob **common)
 {
+  /* ugh, this has a side-effect that we need to ensure that
+     Stem #'beaming is correct */
+  (void) me_grob->get_property ("quantized-positions");
+
   Spanner *me = dynamic_cast<Spanner*> (me_grob);
 
   extract_grob_set (me, "stems", stems);
@@ -347,6 +351,8 @@ Beam::get_beam_segments (Grob *me_grob, Grob **common)
              seg.width_ = stem_width;
              seg.stem_index_ = i;
              seg.dir_ = d;
+             seg.max_connect_ = robust_scm2int (stem->get_property ("max-beam-connect"), 1000);
+             
              Direction stem_dir = get_grob_direction (stem);
              
              seg.gapped_
@@ -366,10 +372,11 @@ Beam::get_beam_segments (Grob *me_grob, Grob **common)
        i != stem_segments.end (); i++)
     {
       vector<Beam_stem_segment> segs = (*i).second;
-      vector_sort (segs, default_compare);
+      vector_sort (segs, less<Beam_stem_segment> ());
 
       Beam_segment current;
-      current.vertical_count_ = (*i).first;
+
+      int vertical_count =  (*i).first;
       for (vsize j = 0; j < segs.size (); j++)
        {
          /*
@@ -382,12 +389,14 @@ Beam::get_beam_segments (Grob *me_grob, Grob **common)
                                         j == segs.size() - 1 && event_dir==RIGHT);
              Drul_array<bool> inside (j > 0, j < segs.size()-1);
              bool event = on_bound[event_dir]
-               || abs (segs[j].rank_ - segs[j+event_dir].rank_) > 1;
+               || abs (segs[j].rank_ - segs[j+event_dir].rank_) > 1
+               || (abs (vertical_count) >= segs[j].max_connect_
+                   || abs (vertical_count) >= segs[j + event_dir].max_connect_);
              
              if (!event)
                continue;
 
-             current.vertical_count_ = (*i).first;
+             current.vertical_count_ = vertical_count;
              current.horizontal_[event_dir] = segs[j].stem_x_;
              if (segs[j].dir_ == event_dir)
                {
@@ -422,7 +431,6 @@ Beam::get_beam_segments (Grob *me_grob, Grob **common)
 
              if (event_dir == RIGHT)
                {
-                 current.vertical_count_ = (*i).first;
                  segments.push_back (current);
                  current = Beam_segment();
                }
@@ -553,7 +561,7 @@ Beam::get_default_dir (Grob *me)
     {
       Grob *s = stems[i];
       Direction stem_dir = CENTER;
-      SCM stem_dir_scm = s->get_property_data (ly_symbol2scm ("direction"));
+      SCM stem_dir_scm = s->get_property_data ("direction");
       if (is_direction (stem_dir_scm))
        {
          stem_dir = to_dir (stem_dir_scm);
@@ -609,7 +617,7 @@ Beam::set_stem_directions (Grob *me, Direction d)
     {
       Grob *s = stems[i];
 
-      SCM forcedir = s->get_property_data (ly_symbol2scm ("direction"));
+      SCM forcedir = s->get_property_data ("direction");
       if (!to_dir (forcedir))
        set_grob_direction (s, d);
     }
@@ -664,7 +672,7 @@ Beam::consider_auto_knees (Grob *me)
          */
          head_extents += stem->relative_coordinate (common, Y_AXIS);
 
-         if (to_dir (stem->get_property_data (ly_symbol2scm ("direction"))))
+         if (to_dir (stem->get_property_data ("direction")))
            {
              Direction stemdir = to_dir (stem->get_property ("direction"));
              head_extents[-stemdir] = -stemdir * infinity_f;
@@ -1165,8 +1173,6 @@ Beam::set_stem_lengths (SCM smob)
   for (vsize i = 0; i < stems.size (); i++)
     {
       Grob *s = stems[i];
-      if (Stem::is_invisible (s))
-       continue;
 
       bool french = to_boolean (s->get_property ("french-beaming"));
       Real stem_y = calc_stem_y (me, s, common,
@@ -1177,9 +1183,14 @@ Beam::set_stem_lengths (SCM smob)
        Make the stems go up to the end of the beam. This doesn't matter
        for normal beams, but for tremolo beams it looks silly otherwise.
       */
-      if (gap)
+      if (gap
+          && !Stem::is_invisible (s))
        stem_y += thick * 0.5 * get_grob_direction (s);
 
+      /*
+       Do set_stemend for invisible stems too, so tuplet brackets
+       have a reference point for sloping
+       */
       Stem::set_stemend (s, 2 * stem_y / staff_space);
     }
 
@@ -1187,7 +1198,7 @@ Beam::set_stem_lengths (SCM smob)
 }
 
 void
-Beam::set_beaming (Grob *me, Beaming_info_list const *beaming)
+Beam::set_beaming (Grob *me, Beaming_pattern const *beaming)
 {
   extract_grob_set (me, "stems", stems);
 
@@ -1204,11 +1215,11 @@ Beam::set_beaming (Grob *me, Beaming_info_list const *beaming)
          if (beaming_prop == SCM_EOL
              || index_get_cell (beaming_prop, d) == SCM_EOL)
            {
-             int count = beaming->infos_.at (i).beam_count_drul_[d];
+             int count = beaming->beamlet_count (i, d);
              if (i > 0
                  && i < stems.size () -1
                  && Stem::is_invisible (stem))
-               count = min (count, beaming->infos_.at (i).beam_count_drul_[-d]);
+               count = min (count, beaming->beamlet_count (i,-d));
 
              if ( ((i == 0 && d == LEFT)
                    || (i == stems.size ()-1 && d == RIGHT))
@@ -1297,7 +1308,7 @@ Beam::last_visible_stem (Grob *me)
 
   rest -> stem -> beam -> interpolate_y_position ()
 */
-MAKE_SCHEME_CALLBACK (Beam, rest_collision_callback, 2);
+MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Beam, rest_collision_callback, 2, 1);
 SCM
 Beam::rest_collision_callback (SCM smob, SCM prev_offset)
 {