]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/sequential-iterator.cc
* scm/define-markup-commands.scm (fill-line): use
[lilypond.git] / lily / sequential-iterator.cc
index 81e9dac2963a6e12bd38a2a1014c970b4d0c1264..a1133033cd8dc8fe94791bc013d864f6d8823508 100644 (file)
@@ -6,12 +6,12 @@
   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+#include "sequential-iterator.hh"
+
 #include "translator-group.hh"
 #include "context.hh"
-#include "sequential-iterator.hh"
 #include "music-list.hh"
-
-Grace_fixup *get_grace_fixups (SCM cursor);
+#include "grace-fixup.hh"
 
 /*
   
@@ -24,8 +24,8 @@ Grace_fixup *get_grace_fixups (SCM cursor);
   Invariant for the data structure.
 
 
-  if (gh_pair_p (cursor_))
-    iter_->music_ == unsmob_music (ly_car (cursor_))
+  if (scm_is_pair (cursor_))
+    iter_->music_ == unsmob_music (scm_car (cursor_))
   else
     iter_ == 0;
 
@@ -38,7 +38,6 @@ Grace_fixup *get_grace_fixups (SCM cursor);
 Sequential_iterator::Sequential_iterator ()
 {
   here_mom_ = Moment (0);
-  list_ = SCM_EOL;
   cursor_ = SCM_EOL; 
   grace_fixups_ = 0;
   iter_ = 0;
@@ -61,23 +60,24 @@ Sequential_iterator::do_quit ()
 
 
 void
-Sequential_iterator::derived_mark ()const
+Sequential_iterator::derived_mark () const
 {
   if (iter_)
     scm_gc_mark (iter_->self_scm ());
-  scm_gc_mark (list_);
   scm_gc_mark (cursor_);
 }
 
 
 void
-Sequential_iterator::derived_substitute (Context *f,Context *t)
+Sequential_iterator::derived_substitute (Context *f, Context *t)
 {
   if (iter_)
-    iter_->substitute_outlet (f,t);
-  
+    iter_->substitute_outlet (f, t);
 }
 
+/*
+  TODO: this should be made lazily.
+ */
 Grace_fixup *
 create_grace_fixup_list (SCM cursor)
 {
@@ -86,9 +86,9 @@ create_grace_fixup_list (SCM cursor)
   Grace_fixup *head = 0;
   Grace_fixup **tail = &head;
 
-  for (; gh_pair_p (cursor); cursor = ly_cdr (cursor))
+  for (; scm_is_pair (cursor); cursor = scm_cdr (cursor))
     {
-      Music *mus = unsmob_music (ly_car (cursor));
+      Music *mus = unsmob_music (scm_car (cursor));
       Moment s = mus->start_mom ();
       Moment l = mus->get_length () - s;
 
@@ -121,13 +121,12 @@ create_grace_fixup_list (SCM cursor)
 void
 Sequential_iterator::construct_children ()
 {
-  list_ = get_music_list ();
-  cursor_ = list_; 
+  cursor_ = get_music_list ();
 
   iter_ = 0;
-  if (gh_pair_p (cursor_))
+  if (scm_is_pair (cursor_))
     {
-      Music *m  =unsmob_music (ly_car (cursor_));
+      Music *m = unsmob_music (scm_car (cursor_));
       iter_ = unsmob_iterator (get_iterator (m));
     }
   
@@ -136,6 +135,7 @@ Sequential_iterator::construct_children ()
       next_element (true);
     }
 
+  last_mom_ = Moment (-1);
   here_mom_ = get_music ()->start_mom ();
   grace_fixups_ = create_grace_fixup_list (cursor_);
 
@@ -143,7 +143,7 @@ Sequential_iterator::construct_children ()
     iter_->ok () is tautology, but what the heck.
    */
   if (iter_ && iter_->ok ()) 
-    descend_to_child ();
+    descend_to_child (iter_->get_outlet ());
 }
 
 
@@ -161,7 +161,8 @@ Sequential_iterator::next_element (bool)
       && get_grace_fixup ())
     {
       Grace_fixup *gf = get_grace_fixup ();
-      
+
+      last_mom_ = here_mom_;
       here_mom_ += gf->length_;
       here_mom_.grace_part_ += gf->grace_start_;
 
@@ -169,6 +170,7 @@ Sequential_iterator::next_element (bool)
     }
   else if (len.grace_part_ && !len.main_part_)
     {
+      last_mom_ = here_mom_;
       here_mom_.grace_part_ =0;
     }
   else
@@ -180,38 +182,19 @@ Sequential_iterator::next_element (bool)
        in that chunk should be in len.grace_part_
 
       */
+      last_mom_ = here_mom_;;
       here_mom_ += len;
     }
   
-  cursor_ = ly_cdr (cursor_);
+  cursor_ = scm_cdr (cursor_);
 
   iter_->quit ();
-  if (gh_pair_p (cursor_))
-    iter_ = unsmob_iterator (get_iterator (unsmob_music (ly_car (cursor_))));
+  if (scm_is_pair (cursor_))
+    iter_ = unsmob_iterator (get_iterator (unsmob_music (scm_car (cursor_))));
   else
     iter_ = 0;
 }
 
-/*
-  move to context of child iterator if it is deeper down in the
-  hierarchy.
-  */
-void
-Sequential_iterator::descend_to_child ()
-{
-  Context * child_report = child_report = iter_->get_outlet ();
-  Context * me_report = get_outlet ();
-
-  Context * c = child_report;
-  while (c && c != me_report)
-    {
-      c = c->daddy_context_;
-    }
-  
-  if (c == me_report)
-    set_translator (child_report);
-}
-
 
 
 void
@@ -244,7 +227,7 @@ Sequential_iterator::process (Moment until)
       if (iter_->ok ())
        return ;
 
-      descend_to_child ();
+      descend_to_child (iter_->get_outlet ());
       next_element (true);
     }
 }
@@ -299,7 +282,6 @@ Sequential_iterator::next_grace_fixup ()
   grace_fixups_ = n;
 }
 
-
 Grace_fixup*
 Sequential_iterator::get_grace_fixup () const
 {