]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/auto-beam-engraver.cc
release: 1.3.2
[lilypond.git] / lily / auto-beam-engraver.cc
index 77094004d368cc2bb6b450dd0eb620b541afb910..fd519c340cf011b24f1bfc1e45db4cb783c31807 100644 (file)
@@ -6,7 +6,7 @@
   (c) 1999 Jan Nieuwenhuizen <janneke@gnu.org>
   
  */
-#include "new-beaming.hh"
+#include "beaming.hh"
 #include "auto-beam-engraver.hh"
 #include "musical-request.hh"
 #include "bar.hh"
@@ -37,18 +37,8 @@ Auto_beam_engraver::do_creation_processing ()
 }
 
 bool
-Auto_beam_engraver::do_try_music (Music* m
+Auto_beam_engraver::do_try_music (Music*) 
 {
-  /*
-    Mag dit?  Nu word-i toch maar geswallowed, en
-    komt er dus ook geen announce...
-   */
-  if (Skip_req* s = dynamic_cast <Skip_req*> (m))
-    {
-      if (stem_l_arr_p_)
-       end_beam ();
-      return true;
-    }
   return false;
 } 
 
@@ -75,6 +65,13 @@ Auto_beam_engraver::consider_end_and_begin (Moment test_mom)
   if (test_mom.den () != 1)
     type_str = type_str + "_" + to_str (test_mom.den ());
 
+  /*
+    URG
+    
+    FIXME: SHOULD USE ALIST
+    
+   */
+
   /*
     Determine end moment for auto beaming (and begin, mostly 0==anywhere) 
     In order of increasing priority:
@@ -112,49 +109,53 @@ Auto_beam_engraver::consider_end_and_begin (Moment test_mom)
   /*
     second guess: property generic time exception
   */
-  Scalar begin = get_property (time_str + "beamAutoBegin", 0);
-  if (begin.length_i ())
-    begin_mom = begin.to_rat ();
+  SCM begin = get_property (time_str + "beamAutoBegin", 0);
+  if (SMOB_IS_TYPE_B(Moment, begin))
+    begin_mom = * SMOB_TO_TYPE(Moment, begin);
 
-  Scalar end = get_property (time_str + "beamAutoEnd", 0);
-  if (end.length_i ())
-    end_mom = end.to_rat ();
+  SCM end = get_property (time_str + "beamAutoEnd", 0);
+  if (SMOB_IS_TYPE_B (Moment, end))
+    end_mom = * SMOB_TO_TYPE(Moment,end);
 
   /*
     third guess: property time exception, specific for duration type
   */
   if (type_str.length_i ())
     {
-      Scalar end_mult = get_property (time_str + "beamAutoEnd" + type_str, 0);
-      if (end_mult.length_i ())
-       end_mom = end_mult.to_rat ();
-      Scalar begin_mult = get_property (time_str + "beamAutoBegin" + type_str, 0);
-      if (begin_mult.length_i ())
-       begin_mom = begin_mult.to_rat ();
+      SCM end_mult = get_property (time_str + "beamAutoEnd" + type_str, 0);
+      if (SMOB_IS_TYPE_B (Moment, end_mult))
+       end_mom = * SMOB_TO_TYPE (Moment,end_mult);
+
+      SCM begin_mult = get_property (time_str + "beamAutoBegin" + type_str, 0);
+      if (SMOB_IS_TYPE_B (Moment, begin_mult))
+       begin_mom = * SMOB_TO_TYPE (Moment,begin_mult);
     }
 
   /*
     fourth guess [user override]: property plain generic
   */
   begin = get_property ("beamAutoBegin", 0);
-  if (begin.length_i ())
-    begin_mom = begin.to_rat ();
+  if (SMOB_IS_TYPE_B(Moment, begin))
+    begin_mom = * SMOB_TO_TYPE(Moment, begin);
+
+
   
   end = get_property ("beamAutoEnd", 0);
-  if (end.length_i ())
-    end_mom = end.to_rat ();
+  if (SMOB_IS_TYPE_B (Moment, end))
+    end_mom = * SMOB_TO_TYPE (Moment,end);
 
   /*
     fifth guess [user override]: property plain, specific for duration type
   */
   if (type_str.length_i ())
     {
-      Scalar end_mult = get_property (String ("beamAutoEnd") + type_str, 0);
-      if (end_mult.length_i ())
-       end_mom = end_mult.to_rat ();
-      Scalar begin_mult = get_property (String ("beamAutoBegin") + type_str, 0);
-      if (begin_mult.length_i ())
-       begin_mom = begin_mult.to_rat ();
+      SCM end_mult = get_property (String ("beamAutoEnd") + type_str, 0);
+      if (SMOB_IS_TYPE_B (Moment, end_mult))
+       end_mom = * SMOB_TO_TYPE (Moment,end_mult);
+
+      SCM begin_mult = get_property (String ("beamAutoBegin") + type_str, 0);
+      if (SMOB_IS_TYPE_B (Moment, begin_mult))
+       begin_mom = * SMOB_TO_TYPE (Moment,begin_mult);
     }
 
   Rational r;
@@ -169,8 +170,8 @@ Auto_beam_engraver::consider_end_and_begin (Moment test_mom)
   /*
     Allow already started autobeam to end
    */
-  Scalar on = get_property ("beamAuto", 0);
-  if (!on.to_bool ())
+  SCM on = get_property ("noAutoBeaming", 0);
+  if (gh_boolean_p (on) && gh_scm2bool (on))
     return;
 
   if (begin_mom)
@@ -197,18 +198,19 @@ Auto_beam_engraver::create_beam_p ()
   Beam* beam_p = new Beam;
 
   for (int i = 0; i < stem_l_arr_p_->size (); i++)
-    beam_p->add_stem ((*stem_l_arr_p_)[i]);
-
-  /* urg, copied from Beam_engraver */
-  Scalar prop = get_property ("beamslopedamping", 0);
-  if (prop.isnum_b ()) 
-    beam_p->set_elt_property (damping_scm_sym, gh_int2scm( prop));
-
-  prop = get_property ("beamquantisation", 0);
-  if (prop.isnum_b ()) 
-    beam_p->quantisation_ = (Beam::Quantisation)(int)prop;
+    {
+      /*
+       watch out for stem tremolos and abbreviation beams
+       */
+      if ((*stem_l_arr_p_)[i]->beam_l_)
+       {
+         return 0;
+       }
+      beam_p->add_stem ((*stem_l_arr_p_)[i]);
+    }
+  
   announce_element (Score_element_info (beam_p, 0));
+
   return beam_p;
 }
 
@@ -222,7 +224,8 @@ Auto_beam_engraver::end_beam ()
   else
     {
       finished_beam_p_ = create_beam_p ();
-      finished_grouping_p_ = grouping_p_;
+      if (finished_beam_p_)
+       finished_grouping_p_ = grouping_p_;
       delete stem_l_arr_p_;
       stem_l_arr_p_ = 0;
       grouping_p_ = 0;
@@ -248,6 +251,17 @@ Auto_beam_engraver::typeset_beam ()
 void
 Auto_beam_engraver::do_post_move_processing ()
 {
+  /*
+    don't beam over skips
+   */
+  if (stem_l_arr_p_)
+    {
+      Moment now = now_mom ();
+      if (extend_mom_ < now)
+       {
+         end_beam ();
+       }
+    }
 }
 
 void
@@ -259,17 +273,19 @@ Auto_beam_engraver::do_pre_move_processing ()
 void
 Auto_beam_engraver::do_removal_processing ()
 {
-  if (stem_l_arr_p_)
-    end_beam ();
+  /* finished beams may be typeset */
   typeset_beam ();
+  /* but unfinished may need another announce/acknowledge pass */
+  if (stem_l_arr_p_)
+    junk_beam ();
 }
 
 bool
 Auto_beam_engraver::same_grace_state_b (Score_element* e)
 {
-  bool gr = (e->get_elt_property (grace_scm_sym) != SCM_BOOL_F) ;
-
-  return gr == get_property ("weAreGraceContext",0).to_bool ();
+  bool gr = e->get_elt_property ("grace") == SCM_BOOL_T;
+  SCM wg =get_property ("weAreGraceContext",0);
+  return (gh_boolean_p (wg) && gh_scm2bool (wg)) == gr;
 }
 
 void
@@ -282,68 +298,78 @@ Auto_beam_engraver::acknowledge_element (Score_element_info info)
     {
       if (Beam *b = dynamic_cast<Beam *> (info.elem_l_))
        {
-         junk_beam ();
+         end_beam ();
        }
       else if (Bar *b = dynamic_cast<Bar *> (info.elem_l_))
        {
-         junk_beam ();
+         end_beam ();
        }
       else if (Rest* rest_l = dynamic_cast<Rest *> (info.elem_l_))
        {
          end_beam ();
        }
-      else if (Stem* stem_l = dynamic_cast<Stem *> (info.elem_l_))
+    }
+  
+  if (Stem* stem_l = dynamic_cast<Stem *> (info.elem_l_))
+    {
+      Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
+      if (!rhythmic_req)
        {
-         Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
-         if (!rhythmic_req)
-           {
-             programming_error ("Stem must have rhythmic structure");
-             return;
-           }
-         
-         if (stem_l->beam_l_)
-           {
-             junk_beam ();
-             return ;
-           }
-             
-             /*
-               now that we have last_add_mom_, perhaps we can (should) do away
-               with these individual junk_beams
-             */
+         programming_error ("Stem must have rhythmic structure");
+         return;
+       }
+      
+      /*
+       Don't (start) auto-beam over empty stems; skips or rests
+       */
+      if (!stem_l->head_l_arr_.size ())
+       {
+         if (stem_l_arr_p_)
+           end_beam ();
+         return;
+       }
 
-         int durlog  =rhythmic_req->duration_.durlog_i_;
-         if (durlog <= 2)
+      if (stem_l->beam_l_)
+       {
+         if (stem_l_arr_p_)
+           junk_beam ();
+         return ;
+       }
+             
+      int durlog  =rhythmic_req->duration_.durlog_i_;
+      if (durlog <= 2)
+       {
+         if (stem_l_arr_p_)
            end_beam ();
-         else 
+         return;
+       }
+
+      /*
+       if shortest duration would change
+       reconsider ending/starting beam first.
+      */
+      Moment mom = rhythmic_req->duration_.length_mom ();
+      consider_end_and_begin (mom);
+      if (!stem_l_arr_p_)
+       return;
+      if (mom < shortest_mom_)
+       {
+         if (stem_l_arr_p_->size ())
            {
-             /*
-               if shortest duration would change
-               reconsider ending/starting beam first.
-             */
-             Moment mom = rhythmic_req->duration_.length_mom ();
-             consider_end_and_begin (mom);
+             shortest_mom_ = mom;
+             consider_end_and_begin (shortest_mom_);
              if (!stem_l_arr_p_)
                return;
-             if (mom < shortest_mom_)
-               {
-                 if (stem_l_arr_p_->size ())
-                   {
-                     shortest_mom_ = mom;
-                     consider_end_and_begin (shortest_mom_);
-                     if (!stem_l_arr_p_)
-                       return;
-                   }
-                 shortest_mom_ = mom;
-               }
-             Moment now = now_mom ();
-
-             grouping_p_->add_stem (now - beam_start_moment_ + beam_start_location_, durlog - 2);
-             stem_l_arr_p_->push (stem_l);
-             last_add_mom_ = now;
-             extend_mom_ = extend_mom_ >? now + rhythmic_req->length_mom ();
            }
+         shortest_mom_ = mom;
        }
+      Moment now = now_mom ();
+      
+      grouping_p_->add_stem (now - beam_start_moment_ + beam_start_location_,
+                            durlog - 2);
+      stem_l_arr_p_->push (stem_l);
+      last_add_mom_ = now;
+      extend_mom_ = extend_mom_ >? now + rhythmic_req->length_mom ();
     }
 }
 
@@ -376,3 +402,4 @@ Auto_beam_engraver::process_acknowledged ()
        }
     }
 }
+