]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/auto-beam-engraver.cc
release: 1.3.65
[lilypond.git] / lily / auto-beam-engraver.cc
index c6177c5f7a6725338621e9d625f6abf6c0440647..7e939e7c8e4ce4976b744087ec5f56558628bab7 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1999 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
   
  */
 #include "beaming.hh"
@@ -11,7 +11,6 @@
 #include "musical-request.hh"
 #include "bar.hh"
 #include "beam.hh"
-#include "chord-tremolo.hh"
 #include "rest.hh"
 #include "stem.hh"
 #include "debug.hh"
 
 ADD_THIS_TRANSLATOR (Auto_beam_engraver);
 
+
+/*
+  TODO: remove all references to Timing_engraver; should read properties.
+  
+ */
 Auto_beam_engraver::Auto_beam_engraver ()
 {
   stem_l_arr_p_ = 0;
@@ -44,7 +48,7 @@ Auto_beam_engraver::do_try_music (Music*)
 } 
 
 void
-Auto_beam_engraver::do_process_requests ()
+Auto_beam_engraver::do_process_music ()
 {
   consider_end_and_begin (shortest_mom_);
 }
@@ -53,11 +57,12 @@ void
 Auto_beam_engraver::consider_end_and_begin (Moment test_mom)
 {
   if (!timer_l_)
-      return;
+    return;
+  
+  int num;
+  int den;
+  timer_l_->get_time_signature (&num, &den);
   
-  Time_description const *time = &timer_l_->time_;
-  int num = time->whole_per_measure_ / time->one_beat_;
-  int den = time->one_beat_.den_i ();
   String time_str = String ("time") + to_str (num) + "_" + to_str (den);
 
   String type_str;
@@ -66,6 +71,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:
@@ -98,59 +110,67 @@ Auto_beam_engraver::consider_end_and_begin (Moment test_mom)
   /*
     first guess: end beam at end of beat
   */
-  Moment end_mom = time->one_beat_;
+  SCM one (get_property ("beatLength"));
+
+  Moment end_mom;
+  if (unsmob_moment (one))
+    end_mom = *unsmob_moment (one);
 
   /*
     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").ch_C());
+  if (unsmob_moment (begin))
+    begin_mom = * unsmob_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").ch_C());
+  if (unsmob_moment (end))
+    end_mom = * unsmob_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).ch_C());
+      if (unsmob_moment (end_mult))
+       end_mom = * unsmob_moment (end_mult);
+
+      SCM begin_mult = get_property ((time_str + "beamAutoBegin" + type_str).ch_C());
+      if (unsmob_moment (begin_mult))
+       begin_mom = * unsmob_moment (begin_mult);
     }
 
   /*
     fourth guess [user override]: property plain generic
   */
-  begin = get_property ("beamAutoBegin", 0);
-  if (begin.length_i ())
-    begin_mom = begin.to_rat ();
+  begin = get_property ("beamAutoBegin");
+  if (unsmob_moment (begin))
+    begin_mom = * unsmob_moment (begin);
+
+
   
-  end = get_property ("beamAutoEnd", 0);
-  if (end.length_i ())
-    end_mom = end.to_rat ();
+  end = get_property ("beamAutoEnd");
+  if (unsmob_moment (end))
+    end_mom = * unsmob_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).ch_C());
+      if (unsmob_moment (end_mult))
+       end_mom = * unsmob_moment (end_mult);
+
+      SCM begin_mult = get_property ((String ("beamAutoBegin") + type_str).ch_C());
+      if (unsmob_moment (begin_mult))
+       begin_mom = * unsmob_moment (begin_mult);
     }
 
   Rational r;
   if (end_mom)
-    r = time->whole_in_measure_.mod_rat (end_mom);
+    r = timer_l_->measure_position ().mod_rat (end_mom);
   else
     r = Moment (1);
 
@@ -160,12 +180,12 @@ Auto_beam_engraver::consider_end_and_begin (Moment test_mom)
   /*
     Allow already started autobeam to end
    */
-  Scalar on = get_property ("noAutoBeaming", 0);
-  if (on.to_bool ())
+  SCM on = get_property ("noAutoBeaming");
+  if (to_boolean (on))
     return;
 
   if (begin_mom)
-    r = time->whole_in_measure_.mod_rat (begin_mom);
+    r = timer_l_->measure_position ().mod_rat (begin_mom);
   if (!stem_l_arr_p_ && (!begin_mom || !r))
     begin_beam ();
 }
@@ -179,37 +199,28 @@ Auto_beam_engraver::begin_beam ()
   assert (!grouping_p_);
   grouping_p_ = new Beaming_info_list;
   beam_start_moment_ = now_mom ();
-  beam_start_location_ = timer_l_->time_.whole_in_measure_;
+  beam_start_location_ = timer_l_->measure_position ();
 }
 
 Beam*
 Auto_beam_engraver::create_beam_p ()
 {
-  Beam* beam_p = new Beam;
+  Beam* beam_p = new Beam (get_property ("basicBeamProperties"));
 
   for (int i = 0; i < stem_l_arr_p_->size (); i++)
     {
       /*
        watch out for stem tremolos and abbreviation beams
        */
-      if ((*stem_l_arr_p_)[i]->beam_l_)
+      if ((*stem_l_arr_p_)[i]->beam_l ())
        {
-         delete beam_p;
          return 0;
        }
       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;
   announce_element (Score_element_info (beam_p, 0));
+
   return beam_p;
 }
 
@@ -274,7 +285,7 @@ Auto_beam_engraver::do_removal_processing ()
 {
   /* finished beams may be typeset */
   typeset_beam ();
-  /* but unfinished may need another announce/acknoledge pass */
+  /* but unfinished may need another announce/acknowledge pass */
   if (stem_l_arr_p_)
     junk_beam ();
 }
@@ -282,9 +293,9 @@ Auto_beam_engraver::do_removal_processing ()
 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");
+  return (to_boolean (wg)) == gr;
 }
 
 void
@@ -297,15 +308,11 @@ Auto_beam_engraver::acknowledge_element (Score_element_info info)
     {
       if (Beam *b = dynamic_cast<Beam *> (info.elem_l_))
        {
-         junk_beam ();
-       }
-      else if (Chord_tremolo *b = dynamic_cast<Chord_tremolo*> (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_))
        {
@@ -325,14 +332,14 @@ Auto_beam_engraver::acknowledge_element (Score_element_info info)
       /*
        Don't (start) auto-beam over empty stems; skips or rests
        */
-      if (!stem_l->head_l_arr_.size ())
+      if (!stem_l->heads_i ())
        {
          if (stem_l_arr_p_)
            end_beam ();
          return;
        }
 
-      if (stem_l->beam_l_)
+      if (stem_l->beam_l ())
        {
          if (stem_l_arr_p_)
            junk_beam ();
@@ -405,3 +412,4 @@ Auto_beam_engraver::process_acknowledged ()
        }
     }
 }
+