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

/home/pete/Work/TSE3.svn/tse3/src/tse3/MidiFile.h

Go to the documentation of this file.
00001 /*
00002  * @(#)MidiFile.h 3.00 30 June 1999
00003  *
00004  * Copyright (c) 2000 Pete Goodliffe (pete@cthree.org)
00005  *
00006  * This file is part of TSE3 - the Trax Sequencer Engine version 3.00.
00007  *
00008  * This library is modifiable/redistributable under the terms of the GNU
00009  * General Public License.
00010  *
00011  * You should have received a copy of the GNU General Public License along
00012  * with this program; see the file COPYING. If not, write to the Free Software
00013  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00014  *
00015  */
00016 
00017 #ifndef TSE3_MIDIFILE_H
00018 #define TSE3_MIDIFILE_H
00019 
00020 #include "tse3/listen/MidiFile.h"
00021 
00022 #include "tse3/Notifier.h"
00023 #include "tse3/Playable.h"
00024 
00025 #include <string>
00026 #include <iosfwd>
00027 #include <cstddef>
00028 
00029 namespace TSE3
00030 {
00031     class Song;
00032     class Track;
00033     class MidiFileImport;
00034     class Progress;
00035 
00061     class MidiFileImport : public Playable,
00062                            public Notifier<MidiFileImportListener>
00063     {
00064         public:
00065 
00081             MidiFileImport(const std::string &filename,
00082                            int                verbose = 0,
00083                            std::ostream      &out     = std::cout);
00084             ~MidiFileImport();
00085 
00098             Song *load(Progress *progress = 0);
00099 
00103             virtual PlayableIterator *iterator(Clock index);
00104 
00116             virtual Clock lastClock() const;
00117 
00118             friend class MidiFileImportIterator;
00119 
00120         private:
00121 
00125             void loadHeader();
00126 
00133             void loadMTrk(size_t &pos, Song *song, int mtrkNo);
00134 
00138             void loadMeta(size_t &pos, Song *song, Track *track,
00139                           int mtrkNo, Clock time, int &port,
00140                           Clock &end);
00141 
00150             int readFixed(size_t &pos, int length);
00151 
00159             int readVariable(size_t &pos);
00160 
00161             std::string   filename;
00162             int           verbose;
00163             std::ostream &out;
00164 
00165             unsigned char  *file;
00166             std::streampos  fileSize;
00167 
00168             int            filePPQN, fileFormat;        // set up by
00169             size_t         fileNoMTrks, fileHeaderSize; // loadHeader
00170             Clock          fileLastClock;               // set by the iterator
00171     };
00172 
00182     class MidiFileExport
00183     {
00184         public:
00185 
00203             MidiFileExport(int                format  = 1,
00204                            bool               compact = true,
00205                            int                verbose = 0,
00206                            std::ostream      &d_out = std::cout);
00207             ~MidiFileExport();
00208 
00218             void save(const std::string &filename, Song *song,
00219                       Progress *progress = 0);
00220 
00224             void save(std::ostream &out, Song *song, Progress *progress = 0);
00225 
00226             /*
00227              * Information about the MIDI file gleaned after having been saved.
00228              */
00229 
00238             int format() const { return _format; }
00239 
00248             size_t size() const { return _size; }
00249 
00258             int noMTrks() const { return _noMTrks; }
00259 
00269             bool compact() const { return _compact; }
00270 
00271         private:
00272 
00280             void writeMTrk(std::ostream &out, PlayableIterator *p,
00281                            const std::string &title = "");
00282 
00287             void writeMTrk_outputLoop(std::ostream &out, PlayableIterator *p);
00288 
00294             void writeMidiEvent(std::ostream &out, const MidiEvent &e);
00295 
00301             void writeMetaEvent(std::ostream &out, const MidiEvent &e);
00302 
00309             void writeFixed(std::ostream &out, int value, int length);
00310 
00317             void writeVariable(std::ostream &out, int value);
00318 
00326             void writeString(std::ostream &out, const std::string &str,
00327                              bool terminate = false);
00328 
00329             int           verbose;
00330             std::ostream &diag_out;
00331             int           _format;
00332             bool          _compact;
00333 
00334             /*
00335              * Things used in writeMTrk and lower
00336              */
00337             TSE3::Song    *song;
00338             size_t         _noMTrks;       // no of MTrks in the file so far
00339             std::streampos MTrkPos;        // where the current MTrk begins
00340             size_t         MTrkSize;       // whilst creating an MTrk, we have
00341                                            // to remember how big it is
00342             unsigned int   runningStatus;  // the current MIDI status byte
00343             Clock          lastEventClock; // use to calculate delta times
00344             size_t         _size;          // size of whole file
00345     };
00346 }
00347 
00348 #endif

Generated on Wed May 25 14:45:07 2005 for TSE3 by doxygen 1.3.2