]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/auto-beam-engraver.cc
* The grand 2005-2006 replace.
[lilypond.git] / lily / auto-beam-engraver.cc
index 9559e044cd1ab303809def3f71f6ae11c80daeb1..54949f63b7d66a7b9d4177a7e4a637bc88331541 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1999--2005 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1999--2006 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "engraver.hh"
 
 #include "translator.icc"
 
-
 class Auto_beam_engraver : public Engraver
 {
   TRANSLATOR_DECLARATIONS (Auto_beam_engraver);
 
 protected:
-  PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
-  PRECOMPUTED_VIRTUAL void start_translation_timestep ();
-  PRECOMPUTED_VIRTUAL void process_music ();
+  void stop_translation_timestep ();
+  void start_translation_timestep ();
+  void process_music ();
   virtual bool try_music (Music *);
   virtual void finalize ();
+  virtual void derived_mark () const;
+
+  DECLARE_ACKNOWLEDGER (rest);
+  DECLARE_ACKNOWLEDGER (beam);
+  DECLARE_ACKNOWLEDGER (bar_line);
+  DECLARE_ACKNOWLEDGER (stem);
 
-  DECLARE_ACKNOWLEDGER(rest);
-  DECLARE_ACKNOWLEDGER(beam);
-  DECLARE_ACKNOWLEDGER(bar_line);
-  DECLARE_ACKNOWLEDGER(stem);
-  
-  PRECOMPUTED_VIRTUAL void process_acknowledged ();
+  void process_acknowledged ();
 
 private:
   bool test_moment (Direction, Moment);
@@ -72,13 +72,18 @@ private:
 
   // We act as if beam were created, and start a grouping anyway.
   Beaming_info_list *grouping_;
-  SCM beam_settings_;          // ugh. should protect ? 
+  SCM beam_settings_;
 
   Beaming_info_list *finished_grouping_;
 
   void check_bar_property ();
 };
 
+void
+Auto_beam_engraver::derived_mark () const
+{
+  scm_gc_mark (beam_settings_);
+}
 
 void
 Auto_beam_engraver::check_bar_property ()
@@ -144,7 +149,7 @@ Auto_beam_engraver::test_moment (Direction dir, Moment test)
                     test.smobbed_copy ())
     != SCM_BOOL_F;
 }
-    
+
 void
 Auto_beam_engraver::consider_begin (Moment test_mom)
 {
@@ -177,19 +182,19 @@ Auto_beam_engraver::create_beam ()
   if (to_boolean (get_property ("skipTypesetting")))
     return 0;
 
-  Spanner *beam = new Spanner (beam_settings_, context ()->get_grob_key ("Beam"));
   for (int i = 0; i < stems_->size (); i++)
-    {
-      /*
-       watch out for stem tremolos and abbreviation beams
-      */
-      if (Stem::get_beam ((*stems_)[i]))
-       {
-         scm_gc_unprotect_object (beam->self_scm ());
-         return 0;
-       }
-      Beam::add_stem (beam, (*stems_)[i]);
-    }
+    if (Stem::get_beam ((*stems_)[i]))
+      return 0;
+
+  /*
+    Can't use make_spanner_from_properties() because we have to use
+    beam_settings_.
+  */
+  Spanner *beam = new Spanner (beam_settings_,
+                              context ()->get_grob_key ("Beam"));
+
+  for (int i = 0; i < stems_->size (); i++)
+    Beam::add_stem (beam, (*stems_)[i]);
 
   announce_grob (beam, (*stems_)[0]->self_scm ());
 
@@ -235,9 +240,7 @@ void
 Auto_beam_engraver::end_beam ()
 {
   if (stems_->size () < 2)
-    {
-      junk_beam ();
-    }
+    junk_beam ();
   else
     {
       finished_beam_ = create_beam ();
@@ -277,9 +280,7 @@ Auto_beam_engraver::start_translation_timestep ()
     {
       Moment now = now_mom ();
       if (extend_mom_ < now)
-       {
-         end_beam ();
-       }
+       end_beam ();
     }
   forbid_ = 0;
 }
@@ -301,21 +302,19 @@ Auto_beam_engraver::finalize ()
 }
 
 
-
-
 void
 Auto_beam_engraver::acknowledge_beam (Grob_info info)
 {
+  (void)info;
   check_bar_property ();
   if (stems_)
-    {
-      end_beam ();
-    }
+    end_beam ();
 }
+
 void
 Auto_beam_engraver::acknowledge_bar_line (Grob_info info)
 {
+  (void)info;
   check_bar_property ();
   if (stems_)
     end_beam ();
@@ -324,6 +323,7 @@ Auto_beam_engraver::acknowledge_bar_line (Grob_info info)
 void
 Auto_beam_engraver::acknowledge_rest (Grob_info info)
 {
+  (void)info;
   check_bar_property ();
   if (stems_)
     end_beam ();
@@ -334,7 +334,7 @@ Auto_beam_engraver::acknowledge_stem (Grob_info info)
 {
   check_bar_property ();
   Item *stem = dynamic_cast<Item *> (info.grob ());
-  Music *m = info.music_cause ();
+  Music *m = info.ultimate_music_cause ();
   if (!m->is_mus_type ("rhythmic-event"))
     {
       programming_error ("stem must have rhythmic structure");
@@ -396,7 +396,7 @@ void
 Auto_beam_engraver::process_acknowledged ()
 {
   if (extend_mom_ > now_mom ())
-    return ; 
+    return;
 
   if (!process_acknowledged_count_)
     {
@@ -410,31 +410,26 @@ Auto_beam_engraver::process_acknowledged ()
          Moment now = now_mom ();
          if ((extend_mom_ < now)
              || ((extend_mom_ == now) && (last_add_mom_ != now)))
-           {
-             end_beam ();
-           }
+           end_beam ();
          else if (!stems_->size ())
-           {
-             junk_beam ();
-           }
+           junk_beam ();
        }
     }
 
   process_acknowledged_count_++;
 }
 
-ADD_ACKNOWLEDGER(Auto_beam_engraver,stem);
-ADD_ACKNOWLEDGER(Auto_beam_engraver,bar_line);
-ADD_ACKNOWLEDGER(Auto_beam_engraver,beam);
-ADD_ACKNOWLEDGER(Auto_beam_engraver,rest);
+ADD_ACKNOWLEDGER (Auto_beam_engraver, stem);
+ADD_ACKNOWLEDGER (Auto_beam_engraver, bar_line);
+ADD_ACKNOWLEDGER (Auto_beam_engraver, beam);
+ADD_ACKNOWLEDGER (Auto_beam_engraver, rest);
 ADD_TRANSLATOR (Auto_beam_engraver,
-               /* descr */ "Generate beams based on measure characteristics and observed "
+               /* doc */ "Generate beams based on measure characteristics and observed "
                "Stems.  Uses beatLength, measureLength and measurePosition to decide "
                "when to start and stop a beam.  Overriding beaming is done through "
                "@ref{Stem_engraver} properties @code{stemLeftBeamCount} and "
                "@code{stemRightBeamCount}. ",
-               /* creats*/ "Beam",
-               /* accepts */ "beam-forbid-event",
-               /* acks  */ "",
-               /* reads */ "autoBeaming autoBeamSettings beatLength subdivideBeams",
+               /* create */ "Beam",
+               /* accept */ "beam-forbid-event",
+               /* read */ "autoBeaming autoBeamSettings beatLength subdivideBeams",
                /* write */ "");