Ardour  8.12
SMFReader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more 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 Street, 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="");
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;
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 
const char * what() const
Definition: SMFReader.h:42
const char * what() const
Definition: SMFReader.h:39
const char * what() const
Definition: SMFReader.h:45
const std::string & filename() const
Definition: SMFReader.h:55
uint32_t _track_size
Definition: SMFReader.h:81
bool open(const std::string &filename)
uint32_t _track
Definition: SMFReader.h:80
SMFReader(const std::string &filename="")
std::string _filename
Definition: SMFReader.h:75
uint16_t _type
Definition: SMFReader.h:77
int read_event(size_t buf_len, uint8_t *buf, uint32_t *ev_size, uint32_t *ev_delta_time)
bool seek_to_track(unsigned track)
uint16_t num_tracks() const
Definition: SMFReader.h:59
uint16_t ppqn() const
Definition: SMFReader.h:58
uint16_t type() const
Definition: SMFReader.h:57
uint16_t _ppqn
Definition: SMFReader.h:78
uint16_t _num_tracks
Definition: SMFReader.h:79
static uint32_t read_var_len(FILE *fd)
#define LIBEVORAL_API
Definition: editor.h:87
GTKMM_API const Gtk::BuiltinStockID FILE