]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/quote-iterator.cc
(struct Simple_spacer): remove
[lilypond.git] / lily / quote-iterator.cc
index ed26decf3f6dcc9b5a2aa4aa23b6985a558858cb..158f271e909f2ee49ccdb3a72aa0ca5d875e61b2 100644 (file)
@@ -27,15 +27,24 @@ public:
   int event_idx_;
   int end_idx_ ;
 
-  DECLARE_SCHEME_CALLBACK(constructor, ()); 
+  SCM transposed_musics_;
+  
+  DECLARE_SCHEME_CALLBACK (constructor, ()); 
 
 protected:
+  virtual void derived_mark ();
   virtual void construct_children ();
   virtual Moment pending_moment () const;
   virtual void process (Moment);
   virtual bool ok () const;
 };
 
+void
+Quote_iterator::derived_mark ()
+{
+  scm_gc_mark (transposed_musics_ );
+}
+
 Quote_iterator::Quote_iterator ()
 {
   event_vector_ = SCM_EOL;
@@ -53,17 +62,15 @@ moment_less (SCM a, SCM b)
 int
 binsearch_scm_vector (SCM vec, SCM key, bool (*is_less)(SCM a,SCM b))
 {
-  int lo;
-  int hi;
-  lo = 0;
-  hi = SCM_VECTOR_LENGTH (vec);
+  int lo = 0;
+  int hi = SCM_VECTOR_LENGTH (vec);
 
   /* binary search */
   do
   {
     int cmp = (lo + hi) / 2;
 
-      SCM when = gh_car (SCM_VECTOR_REF(vec, cmp));
+      SCM when = ly_caar (SCM_VECTOR_REF (vec, cmp));
       bool result =  (*is_less) (key, when);
       if (result)
           hi = cmp;
@@ -79,16 +86,7 @@ binsearch_scm_vector (SCM vec, SCM key, bool (*is_less)(SCM a,SCM b))
 void
 Quote_iterator::construct_children ()
 {
-  SCM tab = get_outlet()->get_property ("quotes");
-  if (scm_hash_table_p (tab) != SCM_BOOL_T)
-    {
-      get_music ()->origin ()->warning ("Context property `quotes' unset; cannot process quote.");
-      return ;
-    }
-
-  SCM name = get_music ()->get_mus_property ("quoted-name");
-  SCM dur = get_music ()->get_mus_property ("duration");
-
+  SCM dur = get_music ()->get_property ("duration");
   if (!unsmob_duration (dur))
     return ;
 
@@ -98,23 +96,20 @@ Quote_iterator::construct_children ()
   Moment stop = now + unsmob_duration (dur)->get_length ();
 
   start_moment_ = now;
-  
-  event_vector_ = scm_hash_ref (tab, name, SCM_BOOL_F);
+  event_vector_ = get_music ()->get_property ("quoted-events");
 
-  if (scm_vector_p (event_vector_) == SCM_BOOL_T)
+  if (ly_c_vector_p (event_vector_))
     {
       event_idx_ = binsearch_scm_vector (event_vector_, now.smobbed_copy (), &moment_less);
       end_idx_ = binsearch_scm_vector (event_vector_, stop.smobbed_copy (), &moment_less);
     }
-  else
-    get_music ()->origin ()->warning ("Can't find requested source");
 }
 
 
 bool
 Quote_iterator::ok () const
 {
-  return (event_idx_ <  end_idx_);
+  return (event_idx_ <= end_idx_);
 }
 
 
@@ -122,7 +117,7 @@ Moment
 Quote_iterator::pending_moment () const
 {
   SCM entry = SCM_VECTOR_REF (event_vector_, event_idx_);
-  return *unsmob_moment (gh_car (entry)) - start_moment_;
+  return *unsmob_moment (ly_caar (entry)) - start_moment_;
 }
 
 
@@ -136,7 +131,7 @@ Quote_iterator::process (Moment m)
     {
       entry = SCM_VECTOR_REF (event_vector_, event_idx_);
 
-      Moment em = *unsmob_moment (gh_car (entry));
+      Moment em = *unsmob_moment (ly_caar (entry));
 
       if (em > m)
        return ;
@@ -147,26 +142,46 @@ Quote_iterator::process (Moment m)
       event_idx_++;
     }
 
-  if (!gh_pair_p (entry))
-    return;
-  
-  for (SCM s = gh_cdr (entry); gh_pair_p (s); s = gh_cdr (s))
+  if (ly_c_pair_p (entry))
     {
-      SCM ev_acc = gh_car (s);
-
-
-      Music * mus = unsmob_music (gh_car (ev_acc));
-      if (mus)
+      Pitch * quote_pitch = unsmob_pitch (ly_cdar (entry));
+      Pitch * me_pitch = unsmob_pitch (get_outlet ()->get_property ("instrumentTransposition"));
+      
+      for (SCM s = ly_cdr (entry); ly_c_pair_p (s); s = ly_cdr (s))
        {
-         bool b = get_outlet ()->try_music (mus);
+         SCM ev_acc = ly_car (s);
+
+
+         Music * mus = unsmob_music (ly_car (ev_acc));
+         if (mus)
+           {
+             if (quote_pitch || me_pitch)
+               {
+                 Pitch qp, mp;
+                 if (quote_pitch)
+                   qp = *quote_pitch;
+                 if (me_pitch)
+                   mp = *me_pitch;
+
+                 Pitch diff = interval (mp, qp);
+
+                 SCM copy = ly_deep_mus_copy (mus->self_scm ());
+                 mus = unsmob_music (copy);
+                 transposed_musics_ = scm_cons (copy, transposed_musics_);
+                 
+                 mus->transpose (diff);
+               }
+
+             
+             bool b = get_outlet ()->try_music (mus);
       
-         if (!b)
-           mus->origin ()->warning (_f ("In quotation: junking event %s", mus->name()));
+             if (!b)
+               mus->origin ()->warning (_f ("In quotation: junking event %s", mus->name ()));
+           }
+         else
+           programming_error ("need music in quote.");
        }
-      else
-       programming_error ("need music in quote.");
     }
-
   event_idx_ ++; 
 }