jdkmidi class library documentation

Copyright © 2004 J.D. Koftinoff Software, Ltd.

Released under the GNU General Public License (GPL)




Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

src/jdkmidi_filewritemultitrack.cpp

Go to the documentation of this file.
00001 /*
00002  *  libjdkmidi-2004 C++ Class Library for MIDI
00003  *
00004  *  Copyright (C) 2004  J.D. Koftinoff Software, Ltd.
00005  *  www.jdkoftinoff.com
00006  *  jeffk@jdkoftinoff.com
00007  *
00008  *  *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 ***
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 #include "jdkmidi/world.h"
00025 #include "jdkmidi/filewritemultitrack.h"
00026 
00027 namespace jdkmidi
00028 {
00029   
00030   
00031   MIDIFileWriteMultiTrack::MIDIFileWriteMultiTrack(
00032     const MIDIMultiTrack *mlt_,
00033     MIDIFileWriteStream *strm_
00034     )
00035     :
00036     multitrack( mlt_ ),
00037     writer( strm_ )
00038   {
00039   }
00040   
00041   MIDIFileWriteMultiTrack::~MIDIFileWriteMultiTrack()
00042   {
00043   }
00044   
00045   bool MIDIFileWriteMultiTrack::Write( int num_tracks, int division )
00046   {
00047     bool f=true;
00048     if( !PreWrite() )
00049     {
00050       return false;
00051     }
00052     
00053     // first, write the header.
00054     
00055     writer.WriteFileHeader( (num_tracks>0), num_tracks, division );
00056     
00057     // now write each track
00058     
00059     for( int i=0; i<num_tracks; ++i )
00060     {
00061       if( writer.ErrorOccurred() )
00062       {
00063         f=false;
00064         break;
00065       }
00066       
00067       const MIDITrack *t = multitrack->GetTrack(i);
00068       
00069       MIDIClockTime last_event_time=0;
00070       
00071       writer.WriteTrackHeader(0); // will be rewritten later
00072       
00073       if( t )
00074       {
00075         for( int event_num=0; event_num<t->GetNumEvents(); ++event_num )
00076         {
00077           const MIDITimedBigMessage *ev = t->GetEventAddress( event_num );
00078           if( ev && !ev->IsNoOp() )
00079           {
00080             last_event_time = ev->GetTime();
00081             
00082             if( !ev->IsDataEnd() )
00083             {
00084               writer.WriteEvent( *ev );
00085               
00086               if( writer.ErrorOccurred() )
00087               {
00088                 f=false;
00089                 break;
00090               }
00091             }
00092           }
00093         }
00094       }
00095       writer.WriteEndOfTrack(0);
00096       writer.RewriteTrackLength();
00097     }
00098     
00099     if( !PostWrite() )
00100     {
00101       return false;
00102     }
00103     
00104     return f;
00105   }
00106   
00107   
00108   bool MIDIFileWriteMultiTrack::PreWrite()
00109   {
00110     return true;
00111   }
00112   
00113   bool MIDIFileWriteMultiTrack::PostWrite()
00114   {
00115     return true;
00116   }
00117   
00118   
00119   
00120 }