]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/recording-group-engraver.cc
add \defaultchild to InnerStaffGroup.
[lilypond.git] / lily / recording-group-engraver.cc
index 3a13dc0e25c7d2cbd72a8a20c9de5fefd0eb78df..5b98ba672dff822ac075818d3842ea3e0cbb41f3 100644 (file)
@@ -1,11 +1,10 @@
-/*   
+/*
   recording-group-engraver.cc -- implement Recording_group_engraver
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2003--2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
-
- */
+  (c) 2003--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+*/
 
 #include "context.hh"
 #include "engraver-group-engraver.hh"
 
 class Recording_group_engraver : public Engraver_group_engraver
 {
-  void start ();
 public:
   TRANSLATOR_DECLARATIONS (Recording_group_engraver);
   virtual bool try_music (Music *m);
-  virtual void start_translation_timestep ();
+  void add_music (SCM, SCM);
   virtual void stop_translation_timestep ();
   virtual void finalize ();
   virtual void initialize ();
-  Protected_scm accumulator_;
+  virtual void derived_mark () const;
+  SCM now_events_;
+  SCM accumulator_;
 };
 
 void
-Recording_group_engraver::initialize ()
+Recording_group_engraver::derived_mark () const
 {
-  Engraver_group_engraver::initialize ();
-  start ();
+  Engraver_group_engraver::derived_mark ();
+  scm_gc_mark (now_events_);
+  scm_gc_mark (accumulator_);
 }
 
-Recording_group_engraver::Recording_group_engraver ()
+void
+Recording_group_engraver::initialize ()
 {
+  Engraver_group_engraver::initialize ();
 }
 
-void
-Recording_group_engraver::start_translation_timestep ()
+Recording_group_engraver::Recording_group_engraver ()
 {
-  Engraver_group_engraver::start_translation_timestep ();
-
-
-  /*
-    We have to do this both in initialize () and
-    start_translation_timestep (), since start_translation_timestep ()
-    isn't called on the first time-step.
-   */
-  start () ;
+  accumulator_ = SCM_EOL;
+  now_events_ = SCM_EOL;
 }
 
 void
-Recording_group_engraver::start ()
+Recording_group_engraver::add_music (SCM music, SCM success)
 {
-  if (!is_pair (accumulator_))
-    accumulator_ = scm_cons (SCM_EOL, SCM_EOL);
-  if (!is_pair (ly_car (accumulator_)))
-    {
-      /*
-       Need to store transposition for every moment; transposition changes during pieces.
-       */
-      scm_set_car_x (accumulator_, scm_cons (scm_cons (now_mom ().smobbed_copy (),
-                                                    get_property ("instrumentTransposition")),
-                                                    SCM_EOL));
-    }
+  now_events_ = scm_cons (scm_cons (music, success), now_events_);
 }
 
 void
 Recording_group_engraver::stop_translation_timestep ()
 {
   Engraver_group_engraver::stop_translation_timestep ();
-  scm_set_cdr_x (accumulator_, scm_cons (ly_car (accumulator_), ly_cdr (accumulator_)));
 
-  scm_set_car_x (accumulator_, SCM_EOL);
+  accumulator_ = scm_acons (scm_cons (now_mom ().smobbed_copy (),
+                                     get_property ("instrumentTransposition")),
+                           now_events_,
+                           accumulator_);
+  now_events_ = SCM_EOL;
 }
 
 void
@@ -80,33 +68,25 @@ Recording_group_engraver::finalize ()
   Engraver_group_engraver::finalize ();
   SCM proc = get_property ("recordEventSequence");
 
-  if (is_procedure (proc))
-    scm_call_2  (proc, daddy_context_->self_scm (), ly_cdr (accumulator_));
-
-  accumulator_ = SCM_EOL;
+  if (ly_c_procedure_p (proc))
+    scm_call_2 (proc, context ()->self_scm (), scm_cdr (accumulator_));
 }
 
 bool
-Recording_group_engraver::try_music (Music  *m)
+Recording_group_engraver::try_music (Music *m)
 {
   bool retval = Translator_group::try_music (m);
 
-  SCM seq = ly_cdar (accumulator_);
-  seq = scm_cons (scm_cons  (m->self_scm (), ly_bool2scm (retval)),
-                seq);
-  
-  scm_set_cdr_x  (ly_car (accumulator_), seq);
-
+  add_music (m->self_scm (), ly_bool2scm (retval));
   return retval;
 }
 
-
-ENTER_DESCRIPTION (Recording_group_engraver,
-                 "Engraver_group_engraver that records all music events "
-                 "for this context. Calls the procedure "
-                 "in @code{recordEventSequence} when finished.",
-                 "",
-                 "",
-                 "",
-                 "recordEventSequence",
-                 "");
+ADD_TRANSLATOR (Recording_group_engraver,
+               "Engraver_group_engraver that records all music events "
+               "for this context. Calls the procedure "
+               "in @code{recordEventSequence} when finished.",
+               "",
+               "",
+               "",
+               "recordEventSequence",
+               "");