ardour
SMFReader.hpp
Go to the documentation of this file.
1 /* This file is part of Evoral.
2  * Copyright(C) 2008 David Robillard <http://drobilla.net>
3  * Copyright(C) 2000-2008 Paul Davis
4  *
5  * Evoral is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 2 of the License, or(at your option) any later
8  * version.
9  *
10  * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef EVORAL_SMF_READER_HPP
20 #define EVORAL_SMF_READER_HPP
21 
22 #include <exception>
23 #include <stdexcept>
24 #include <string>
25 #include <inttypes.h>
26 
27 #include "evoral/visibility.h"
28 
29 namespace Evoral {
30 
31 
37 public:
38  class PrematureEOF : public std::exception {
39  const char* what() const throw() { return "Unexpected end of file"; }
40  };
41  class CorruptFile : public std::exception {
42  const char* what() const throw() { return "Corrupted file"; }
43  };
44  class UnsupportedTime : public std::exception {
45  const char* what() const throw() { return "Unsupported time stamp type (SMPTE)"; }
46  };
47 
48  SMFReader(const std::string& filename="");
49  ~SMFReader();
50 
51  bool open(const std::string& filename) throw (std::logic_error, UnsupportedTime);
52 
53  bool seek_to_track(unsigned track) throw (std::logic_error);
54 
55  const std::string& filename() const { return _filename; };
56 
57  uint16_t type() const { return _type; }
58  uint16_t ppqn() const { return _ppqn; }
59  uint16_t num_tracks() const { return _num_tracks; }
60 
61  int read_event(size_t buf_len,
62  uint8_t* buf,
63  uint32_t* ev_size,
64  uint32_t* ev_delta_time)
65  throw (std::logic_error, PrematureEOF, CorruptFile);
66 
67  void close();
68 
69  static uint32_t read_var_len(FILE* fd) throw (PrematureEOF);
70 
71 protected:
73  static const uint32_t HEADER_SIZE = 22;
74 
75  std::string _filename;
76  FILE* _fd;
77  uint16_t _type;
78  uint16_t _ppqn;
79  uint16_t _num_tracks;
80  uint32_t _track;
81  uint32_t _track_size;
82 };
83 
84 
85 } // namespace Evoral
86 
87 #endif // EVORAL_SMF_READER_HPP
88 
uint16_t ppqn() const
Definition: SMFReader.hpp:58
const char * what() const
Definition: SMFReader.hpp:45
std::string _filename
Definition: SMFReader.hpp:75
#define LIBEVORAL_API
Definition: visibility.h:45
uint16_t num_tracks() const
Definition: SMFReader.hpp:59
const char * what() const
Definition: SMFReader.hpp:42
const char * what() const
Definition: SMFReader.hpp:39
uint16_t _num_tracks
Definition: SMFReader.hpp:79
uint32_t _track_size
Definition: SMFReader.hpp:81
const std::string & filename() const
Definition: SMFReader.hpp:55
uint16_t type() const
Definition: SMFReader.hpp:57