]> git.donarmstrong.com Git - lilypond.git/blobdiff - midi2ly/lilypond-voice.cc
patch::: 1.5.10.jcn2
[lilypond.git] / midi2ly / lilypond-voice.cc
index d7676b26341796d31b52b2f7b17a340b74db2235..a19eec037865c9169e51cd8a9d571d8a5e16faf9 100644 (file)
@@ -1,7 +1,7 @@
 //
 // lilypond-voice.cc -- implement Lilypond_voice
 //
-// copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
+// (c) 1997--2001 Jan Nieuwenhuizen <janneke@gnu.org>
 
 #include "string-convert.hh"
 #include "midi2ly-global.hh"
@@ -17,19 +17,40 @@ extern Lilypond_score* lilypond_score_l_g;
 Lilypond_voice::Lilypond_voice (Lilypond_staff* lilypond_staff_l)
 {
   lilypond_staff_l_ = lilypond_staff_l;
-  last_item_l_ =0;
-  last_note_l_ =0;
+  threads_.push (new Cons_list<Lilypond_item>);
+  mom_ = 0;
 }
-
+  
 void
-Lilypond_voice::add_item (Lilypond_item* lilypond_item_l)
+Lilypond_voice::add_items (Link_array<Lilypond_item>& items)
 {
-  last_item_l_  = lilypond_item_l;
-  if (Lilypond_note* n = dynamic_cast<Lilypond_note*> (lilypond_item_l))
+  int thread = 0;
+  for (int i = 0; i < items.size (); i++)
     {
-      last_note_l_  = n;
+      Lilypond_item* item = items[i];
+
+      int to_thread;
+      if (Lilypond_note* n = dynamic_cast<Lilypond_note*> (item))
+       to_thread = thread++;
+      else
+       to_thread = 0;
+      
+      if (to_thread >= threads_.size ())
+       threads_.push (new Cons_list<Lilypond_item>);
+      
+      if (to_thread == 0 && item->at_mom () > mom_)
+       {
+         /* urg: skip should use refer to end-colum, not separate moment */
+         Rational r = item->at_mom () - mom_;
+         Lilypond_column* start = lilypond_score_l_g->find_column_l (mom_);
+         threads_[to_thread]->append (new Cons<Lilypond_item> (new Lilypond_skip (start, r), 0));
+         mom_ = item->at_mom ();
+       }
+
+      threads_[to_thread]->append (new Cons<Lilypond_item> (item, 0));
+      if (to_thread == 0)
+       mom_ += item->duration_mom ();
     }
-  lilypond_item_l_list_.append (new Cons<Lilypond_item> (lilypond_item_l, 0));
 }
 
 /**
@@ -40,7 +61,7 @@ Lilypond_voice::get_clef () const
 {
   Lilypond_note * n =0;
 
-  for (Cons<Lilypond_item> *cp = lilypond_item_l_list_.head_; !n && cp; cp = cp->next_)
+  for (Cons<Lilypond_item> *cp = threads_[0]->head_; !n && cp; cp = cp->next_)
     {
       n = dynamic_cast<Lilypond_note*> (cp->car_);
     }
@@ -64,7 +85,7 @@ void
 Lilypond_voice::output (Lilypond_stream& lilypond_stream_r)
 {
   lilypond_stream_r << "{ ";
-  if (lilypond_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
+  if (threads_[0]->size_i () > FAIRLY_LONG_VOICE_i)
     lilypond_stream_r << '\n';
 
 
@@ -73,7 +94,10 @@ Lilypond_voice::output (Lilypond_stream& lilypond_stream_r)
   int current_bar_i = 0;
   Rational bar_mom = lilypond_staff_l_->lilypond_time_signature_l_->bar_mom ();
 
-  for (Cons<Lilypond_item>* i = lilypond_item_l_list_.head_; i; i = i->next_)
+  Link_array <Cons<Lilypond_item> > heads;
+  for (int i = 1; i < threads_.size (); i++)
+    heads.push (threads_[i]->head_);
+  for (Cons<Lilypond_item>* i = threads_[0]->head_; i; i = i->next_)
     {
       Rational at_mom = i->car_->lilypond_column_l_->at_mom ();
       int bar_i = (int) (at_mom / bar_mom) + 1;
@@ -91,12 +115,34 @@ Lilypond_voice::output (Lilypond_stream& lilypond_stream_r)
          current_bar_i = bar_i;
        }
 
-      lilypond_stream_r << *i->car_;
+      if (dynamic_cast<Lilypond_note*> (i->car_)
+         && heads.size ()
+         && heads[0]
+         && heads[0]->car_->at_mom () == at_mom)
+       {
+         lilypond_stream_r << '<';
+      
+         lilypond_stream_r << *i->car_;
+
+         for (int h = 0;
+              h < heads.size ()
+                && heads[h]
+                && heads[h]->car_->at_mom () == at_mom;
+              h++)
+           {
+             lilypond_stream_r << *heads[h]->car_;
+             heads[h] = heads[h]->next_;
+           }
+         lilypond_stream_r << '>';
+       }
+      else
+       lilypond_stream_r << *i->car_;
+      
       if (Lilypond_key* k = dynamic_cast<Lilypond_key*> (i->car_))
        lilypond_staff_l_->lilypond_key_l_ = lilypond_score_l_g->lilypond_key_l_ = k;
     }
 
-  if (lilypond_item_l_list_.size_i () > FAIRLY_LONG_VOICE_i)
+  if (threads_[0]->size_i () > FAIRLY_LONG_VOICE_i)
     lilypond_stream_r << '\n';
 
   lilypond_stream_r << "} ";