RAUL 0.7.0
|
00001 /* This file is part of Raul. 00002 * Copyright (C) 2007-2009 David Robillard <http://drobilla.net> 00003 * 00004 * Raul is free software; you can redistribute it and/or modify it under the 00005 * terms of the GNU General Public License as published by the Free Software 00006 * Foundation; either version 2 of the License, or (at your option) any later 00007 * version. 00008 * 00009 * Raul is distributed in the hope that it will be useful, but WITHOUT ANY 00010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. 00012 * 00013 * You should have received a copy of the GNU General Public License along 00014 * with this program; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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 } // namespace Raul 00081 00082 #endif // RAUL_SMF_READER_HPP 00083