]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/auto-beam-engraver.cc
*** empty log message ***
[lilypond.git] / lily / auto-beam-engraver.cc
index 9f3926cd005592500125821bd95aa4dea801e673..186c923de4a43040229ee7a5101c00f825cbc59f 100644 (file)
@@ -21,9 +21,6 @@
 #include "duration.hh"
 #include "context.hh"
 
-/*
-  TODO: documentme.
- */
 class Auto_beam_engraver : public Engraver
 {
   TRANSLATOR_DECLARATIONS (Auto_beam_engraver);
@@ -78,7 +75,7 @@ private:
 void
 Auto_beam_engraver::process_music ()
 {
-  if (gh_string_p (get_property ("whichBar")))
+  if (scm_is_string (get_property ("whichBar")))
     {
       consider_end (shortest_mom_);
       junk_beam ();
@@ -157,10 +154,20 @@ Auto_beam_engraver::test_moment (Direction dir, Moment test_mom)
     function = scm_list_n (ly_symbol2scm ("begin"), SCM_UNDEFINED);
   else
     function = scm_list_n (ly_symbol2scm ("end"), SCM_UNDEFINED);
-
-  Moment one_beat = *unsmob_moment (get_property ("beatLength"));
-  int num = int ((*unsmob_moment (get_property ("measureLength")) / one_beat).main_part_);
-  int den = one_beat.den ();
+  
+  Moment beat_length (1,4);
+  if (Moment * m = unsmob_moment (get_property ("beatLength")))
+    {
+      beat_length = *m;
+    }
+  Moment measure_length (1,1);
+  int num = 4;
+  if (Moment* m = unsmob_moment (get_property ("measureLength")))
+    {
+      num = int ((*m / beat_length).main_part_);
+    }
+  
+  int den = beat_length.den ();
   SCM time = scm_list_n (scm_int2num (num), scm_int2num (den), SCM_UNDEFINED);
 
   SCM type = scm_list_n (scm_int2num (test_mom.num ()),
@@ -181,32 +188,29 @@ Auto_beam_engraver::test_moment (Direction dir, Moment test_mom)
   /* end beam at end of beat */
   if (dir == STOP)
     {
-      SCM beat (get_property ("beatLength"));
-      
-      if (unsmob_moment (beat))
-       moment = *unsmob_moment (beat);
+      moment = robust_scm2moment (get_property ("beatLength"), moment);
     }
 
   /* second guess: property generic time exception */
-  SCM m = scm_assoc (gh_append3 (function, wild, time), settings);
+  SCM m = scm_assoc (ly_append3 (function, wild, time), settings);
   
-  if (m != SCM_BOOL_F && unsmob_moment (ly_cdr (m)))
-    moment = * unsmob_moment (ly_cdr (m));
+  if (m != SCM_BOOL_F && unsmob_moment (scm_cdr (m)))
+    moment = * unsmob_moment (scm_cdr (m));
 
   /* third guess: property time exception, specific for duration type */
-  m = scm_assoc (gh_append3 (function, type, time), settings);
-  if (m != SCM_BOOL_F && unsmob_moment (ly_cdr (m)))
-    moment = * unsmob_moment (ly_cdr (m));
+  m = scm_assoc (ly_append3 (function, type, time), settings);
+  if (m != SCM_BOOL_F && unsmob_moment (scm_cdr (m)))
+    moment = * unsmob_moment (scm_cdr (m));
 
   /* fourth guess [user override]: property plain generic */
-  m = scm_assoc (gh_append3 (function, wild, wild), settings);
-  if (m != SCM_BOOL_F && unsmob_moment (ly_cdr (m)))
-    moment = * unsmob_moment (ly_cdr (m));
+  m = scm_assoc (ly_append3 (function, wild, wild), settings);
+  if (m != SCM_BOOL_F && unsmob_moment (scm_cdr (m)))
+    moment = * unsmob_moment (scm_cdr (m));
 
   /* fifth guess [user override]: property plain, specific for duration type */
-  m = scm_assoc (gh_append3 (function, type, wild), settings);
-  if (m != SCM_BOOL_F && unsmob_moment (ly_cdr (m)))
-    moment = * unsmob_moment (ly_cdr (m));
+  m = scm_assoc (ly_append3 (function, type, wild), settings);
+  if (m != SCM_BOOL_F && unsmob_moment (scm_cdr (m)))
+    moment = * unsmob_moment (scm_cdr (m));
   
   Rational r;
   if (moment.to_bool ())
@@ -215,10 +219,20 @@ Auto_beam_engraver::test_moment (Direction dir, Moment test_mom)
         We may have to fix this elsewhere (timing translator)
        r = unsmob_moment (get_property ("measurePosition"))->mod_rat (moment);
       */
-      Moment pos = * unsmob_moment (get_property ("measurePosition"));
+      Moment pos (0);
+      if (Moment  *m = unsmob_moment (get_property ("measurePosition")))
+       {
+         pos = *m;
+       }
+         
       if (pos < Moment (0))
        {
-         Moment length = * unsmob_moment (get_property ("measureLength"));
+         Moment length(1);
+
+         if ( Moment *m =  unsmob_moment (get_property ("measureLength")))
+           {
+             length = *m;
+           }
          pos = length - pos;
        }
       r = pos.main_part_.mod_rat (moment.main_part_);
@@ -284,7 +298,7 @@ Auto_beam_engraver::create_beam ()
       Beam::add_stem (beam, (*stems_)[i]);
     }
   
-  announce_grob (beam, SCM_EOL);
+  announce_grob (beam, (*stems_)[0]->self_scm ());
 
   return beam;
 }
@@ -300,12 +314,13 @@ Auto_beam_engraver::begin_beam ()
   
   stems_ = new Link_array<Item>;
   grouping_ = new Beaming_info_list;
-  beam_settings_ = updated_grob_properties (daddy_context_, ly_symbol2scm ("Beam"));
+  beam_settings_ = updated_grob_properties (context (), ly_symbol2scm ("Beam"));
   
   beam_start_moment_ = now_mom ();
-  beam_start_location_ = *unsmob_moment (get_property ("measurePosition"));
-  subdivide_beams_ = gh_scm2bool (get_property ("subdivideBeams"));
-  beat_length_ = *unsmob_moment (get_property ("beatLength"));
+  beam_start_location_ =
+    robust_scm2moment (get_property ("measurePosition"), Moment(0));
+  subdivide_beams_ = ly_scm2bool (get_property ("subdivideBeams"));
+  beat_length_ = robust_scm2moment (get_property ("beatLength"), Moment(1,4));
 }
 
 void
@@ -351,7 +366,6 @@ Auto_beam_engraver::typeset_beam ()
     {
       finished_grouping_->beamify (beat_length_, subdivide_beams_);
       Beam::set_beaming (finished_beam_, finished_grouping_);
-      typeset_grob (finished_beam_);
       finished_beam_ = 0;
     
       delete finished_grouping_;