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