00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RAUL_SMF_READER_HPP
00019 #define RAUL_SMF_READER_HPP
00020
00021 #include <stdexcept>
00022 #include <string>
00023 #include <inttypes.h>
00024 #include <raul/TimeStamp.hpp>
00025
00026 namespace Raul {
00027
00028
00033 class SMFReader {
00034 public:
00035 class PrematureEOF : public std::exception {
00036 const char* what() const throw() { return "Unexpected end of file"; }
00037 };
00038 class CorruptFile : public std::exception {
00039 const char* what() const throw() { return "Corrupted file"; }
00040 };
00041 class UnsupportedTime : public std::exception {
00042 const char* what() const throw() { return "Unsupported time stamp type (SMPTE)"; }
00043 };
00044
00045 SMFReader(const std::string filename="");
00046 ~SMFReader();
00047
00048 bool open(const std::string& filename) throw (std::logic_error, UnsupportedTime);
00049
00050 bool seek_to_track(unsigned track) throw (std::logic_error);
00051
00052 uint16_t type() const { return _type; }
00053 uint16_t ppqn() const { return _ppqn; }
00054 size_t num_tracks() { return _num_tracks; }
00055
00056 int read_event(size_t buf_len,
00057 uint8_t* buf,
00058 uint32_t* ev_size,
00059 uint32_t* ev_delta_time)
00060 throw (std::logic_error, PrematureEOF, CorruptFile);
00061
00062 void close();
00063
00064 static uint32_t read_var_len(FILE* fd) throw (PrematureEOF);
00065
00066 protected:
00068 static const uint32_t HEADER_SIZE = 22;
00069
00070 std::string _filename;
00071 FILE* _fd;
00072 uint16_t _type;
00073 uint16_t _ppqn;
00074 uint16_t _num_tracks;
00075 uint32_t _track;
00076 uint32_t _track_size;
00077 };
00078
00079
00080 }
00081
00082 #endif // RAUL_SMF_READER_HPP
00083