RAUL
0.8.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 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 } // namespace Raul 00082 00083 #endif // RAUL_SMF_READER_HPP 00084