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
00034 class SMFReader {
00035 public:
00036 class PrematureEOF : public std::exception {
00037 const char* what() const throw() { return "Unexpected end of file"; }
00038 };
00039 class CorruptFile : public std::exception {
00040 const char* what() const throw() { return "Corrupted file"; }
00041 };
00042 class UnsupportedTime : public std::exception {
00043 const char* what() const throw() { return "Unsupported time stamp type (SMPTE)"; }
00044 };
00045
00046 explicit SMFReader(const std::string filename="");
00047 ~SMFReader();
00048
00049 bool open(const std::string& filename) throw (std::logic_error, UnsupportedTime);
00050
00051 bool seek_to_track(unsigned track) throw (std::logic_error);
00052
00053 uint16_t type() const { return _type; }
00054 uint16_t ppqn() const { return _ppqn; }
00055 size_t num_tracks() { return _num_tracks; }
00056
00057 int read_event(size_t buf_len,
00058 uint8_t* buf,
00059 uint32_t* ev_size,
00060 uint32_t* ev_delta_time)
00061 throw (std::logic_error, PrematureEOF, CorruptFile);
00062
00063 void close();
00064
00065 static uint32_t read_var_len(FILE* fd) throw (PrematureEOF);
00066
00067 protected:
00069 static const uint32_t HEADER_SIZE = 22;
00070
00071 std::string _filename;
00072 FILE* _fd;
00073 uint16_t _type;
00074 uint16_t _ppqn;
00075 uint16_t _num_tracks;
00076 uint32_t _track;
00077 uint32_t _track_size;
00078 };
00079
00080
00081 }
00082
00083 #endif // RAUL_SMF_READER_HPP
00084