]> git.donarmstrong.com Git - lilypond.git/commitdiff
More MIDI cleanup.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 17 Jan 2007 00:01:52 +0000 (01:01 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 17 Jan 2007 00:01:52 +0000 (01:01 +0100)
lily/audio-element.cc
lily/audio-staff.cc
lily/include/midi-item.hh
lily/include/midi-stream.hh
lily/include/midi-walker.hh
lily/midi-item.cc
lily/midi-stream.cc
lily/midi-walker.cc
lily/performance.cc

index cb498f5dbf7f9acf4c7944108ba20479b0200d7f..8d3a3e39534384768a34ae87f2de82df9ea8b66e 100644 (file)
@@ -5,6 +5,7 @@
 
   (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
+#include <cassert> 
 
 #include "audio-element.hh"
 
index 6871ab56b442ad8b6275d5bd227f4d3f9688fdb1..120313ef6455c2505e7af243992a8960590eb1df 100644 (file)
@@ -33,6 +33,6 @@ Audio_staff::output (Midi_stream &midi_stream, int channel)
   for (; i.ok (); i++)
     i.process ();
   
-  midi_stream << midi_track;
+  midi_stream.write (midi_track);
 }
 
index 6d77f21afc29872c1162f040b50f1ed61bb3cba9..f7ea0e0585c07cce1551692ef714b1b78660bb7d 100644 (file)
@@ -37,8 +37,6 @@ public:
   int channel_;
   DECLARE_CLASSNAME(Midi_channel_item);
   Midi_channel_item ();
-  virtual const char *name () const { return "Midi_channel_item"; }
-  virtual ~Midi_channel_item ();
 };
 
 /**
@@ -125,9 +123,6 @@ public:
   int clocks_per_1_;
 };
 
-/**
-   Turn a note on.
-*/
 class Midi_note : public Midi_channel_item
 {
 public:
@@ -145,9 +140,6 @@ public:
   Byte dynamic_byte_;
 };
 
-/**
-   Turn a note off
-*/
 class Midi_note_off : public Midi_note
 {
 public:
@@ -216,9 +208,6 @@ public:
   int number_;
   DECLARE_CLASSNAME(Midi_track);
 
-  /*
-    Compensate for starting grace notes.
-  */
   vector<Midi_event*> events_;
 
   Midi_track ();
index 18e38ca2c00c6cebb41367b32d9128d02ff170f4..1d9066e8654b5de80e9ee713689fbf21924ace52 100644 (file)
@@ -20,9 +20,9 @@ struct Midi_stream
   Midi_stream (string file_name_string);
   ~Midi_stream ();
 
-  Midi_stream &operator << (string str);
-  Midi_stream &operator << (Midi_item const &midi_c_r);
-  Midi_stream &operator << (int i);
+  void write (string);
+  void write (Midi_item const &);
+  void write (int);
 
   void open ();
 
index 604cf70072e2a98eb870be9c531bf975d37b380c..69bf4c8a9b939589e41caf9fa62cc2390cd174a3 100644 (file)
@@ -14,7 +14,7 @@
 
 struct Midi_note_event : PQueue_ent<int, Midi_note *>
 {
-  bool ignore_b_;
+  bool ignore_;
   Midi_note_event ();
 };
 
@@ -38,7 +38,7 @@ private:
   void do_start_note (Midi_note *note);
   void do_stop_notes (int);
   void output_event (int, Midi_item *l);
-
+  
   int channel_;
   Midi_track *track_;
   Audio_staff *staff_;
@@ -47,7 +47,6 @@ private:
   PQueue<Midi_note_event> stop_note_queue;
   int last_tick_;
 
-  vector<Midi_item*> midi_items_;
 };
 
 #endif // MIDI_WALKER_HH
index 0e68e03ded9d7a223b6ab7a7e27f1060df4b11b3..88f9aeb86f0525a8788ce7490f1d0799bf3dc96d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  midi-item.cc -- implement Midi items.
+  midi-item.cc -- implement MIDI items.
 
   source file of the GNU LilyPond music typesetter
 
@@ -148,11 +148,6 @@ Midi_item::Midi_item ()
 {
 }
 
-Midi_channel_item::~Midi_channel_item ()
-{
-  channel_ = 0;
-}
-
 Midi_channel_item::Midi_channel_item ()
 {
   channel_ = 0;
@@ -453,15 +448,11 @@ string
 Midi_track::data_string () const
 {
   string str = Midi_chunk::data_string ();
-  if (do_midi_debugging_global)
-    str += "\n";
 
   for (vector<Midi_event*>::const_iterator i (events_.begin());
        i != events_.end(); i ++)
     {
       str += (*i)->to_string ();
-      if (do_midi_debugging_global)
-       str += "\n";
     }
   return str;
 }
index 893ca3d8df1b5883ad9134c2249c8ccb4cf46f67..11afe02cf46b13e0dcc53f9a681348fdcbd558b3 100644 (file)
@@ -33,8 +33,8 @@ Midi_stream::~Midi_stream ()
   fclose (out_file_);
 }
 
-Midi_stream &
-Midi_stream::operator << (string str)
+void
+Midi_stream::write (string str)
 {
   size_t sz = sizeof (Byte);
   size_t n = str.length ();
@@ -42,34 +42,19 @@ Midi_stream::operator << (string str)
 
   if (written != sz * n)
     warning (_ ("cannot write to file: `%s'"));
-
-  return *this;
 }
 
-Midi_stream &
-Midi_stream::operator << (Midi_item const &midi_c_r)
+void
+Midi_stream::write (Midi_item const &midi)
 {
-  string str = midi_c_r.to_string ();
-
-  // ugh, should have separate debugging output with Midi*::print routines
-  if (do_midi_debugging_global)
-    {
-      str = String_convert::bin2hex (str) + "\n";
-      for (ssize i = str.find ("0a"); i != NPOS; i = str.find ("0a"))
-       {
-         str[i] = '\n';
-         str[i + 1] = '\t';
-       }
-    }
+  string str = midi.to_string ();
 
-  return operator << (str);
+  return write (str);
 }
 
-Midi_stream &
-Midi_stream::operator << (int i)
+void
+Midi_stream::write (int i)
 {
-  // output binary string ourselves
-  *this << Midi_item::i2varint_string (i);
-  return *this;
+  write (Midi_item::i2varint_string (i));
 }
 
index 48c4cf8723658aa6a4eb37ecd9b580f4500c8504..941e64c282932e753a97c1aa494327d339929ef8 100644 (file)
@@ -17,7 +17,7 @@
 
 Midi_note_event::Midi_note_event ()
 {
-  ignore_b_ = false;
+  ignore_ = false;
 }
 
 int
@@ -53,12 +53,10 @@ Midi_walker::Midi_walker (Audio_staff *audio_staff, Midi_track *track,
 
 Midi_walker::~Midi_walker ()
 {
-  do_stop_notes (last_tick_ + 384);
-
-  for (vsize i = 0; i < midi_items_.size (); i++)
-    delete midi_items_[i];
+  do_stop_notes (INT_MAX);
 }
 
+
 /**
    Find out if start_note event is needed, and do it if needed.
 */
@@ -80,7 +78,8 @@ Midi_walker::do_start_note (Midi_note *note)
            {
              /* let stopnote in queue be ignored,
                 new stop note wins */
-             stop_note_queue[i].ignore_b_ = true;
+             stop_note_queue[i].ignore_ = true;
+
              /* don't replay start note, */
              play_start = false;
              break;
@@ -105,8 +104,6 @@ Midi_walker::do_start_note (Midi_note *note)
 
       if (play_start)
        output_event (ptr->audio_column_->ticks (), note);
-
-      midi_items_.push_back (e.val);
     }
 }
 
@@ -119,7 +116,7 @@ Midi_walker::do_stop_notes (int max_ticks)
   while (stop_note_queue.size () && stop_note_queue.front ().key <= max_ticks)
     {
       Midi_note_event e = stop_note_queue.get ();
-      if (e.ignore_b_)
+      if (e.ignore_)
        {
          delete e.val;
          continue;
@@ -132,9 +129,6 @@ Midi_walker::do_stop_notes (int max_ticks)
     }
 }
 
-/**
-   Advance the track to #now#, output the item, and adjust current "moment".
-*/
 void
 Midi_walker::output_event (int now_ticks, Midi_item *l)
 {
@@ -165,7 +159,6 @@ Midi_walker::process ()
       if (Midi_channel_item *mci = dynamic_cast<Midi_channel_item*> (midi))
        mci->channel_ = channel_;
       
-      //midi->channel_ = track_->number_;
       if (Midi_note *note = dynamic_cast<Midi_note *> (midi))
        {
          if (note->audio_->length_mom_.to_bool ())
@@ -173,9 +166,6 @@ Midi_walker::process ()
        }
       else
        output_event (audio->audio_column_->ticks (), midi);
-
-
-      midi_items_.push_back (midi);
     }
 }
 
index 2c02fc32f94f3ff64aacab4a6dfc1bce18845982..439d9489f175727bc3ad0624179acaa49b8145d2 100644 (file)
@@ -38,7 +38,7 @@ Performance::output (Midi_stream &midi_stream) const
 {
   int tracks_ = audio_staffs_.size ();
 
-  midi_stream << Midi_header (1, tracks_, 384);
+  midi_stream.write (Midi_header (1, tracks_, 384));
   if (be_verbose_global)
     progress_indication (_ ("Track...") + " ");