Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[ardour.git] / libs / evoral / evoral / SMFReader.hpp
1 /* This file is part of Evoral.
2  * Copyright(C) 2008 Dave 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 namespace Evoral {
28
29
30 /** Standard MIDI File (Type 0) Reader
31  *
32  * Currently this only reads SMF files with tempo-based timing.
33  */
34 class SMFReader {
35 public:
36         class PrematureEOF : public std::exception {
37                 const char* what() const throw() { return "Unexpected end of file"; }
38         };
39         class CorruptFile : public std::exception {
40                 const char* what() const throw() { return "Corrupted file"; }
41         };
42         class UnsupportedTime : public std::exception {
43                 const char* what() const throw() { return "Unsupported time stamp type (SMPTE)"; }
44         };
45
46         SMFReader(const std::string& filename="");
47         ~SMFReader();
48
49         bool open(const std::string& filename) throw (std::logic_error, UnsupportedTime);
50
51         bool seek_to_track(unsigned track) throw (std::logic_error);
52
53         const std::string& filename() const { return _filename; };
54
55         uint16_t type()       const { return _type; }
56         uint16_t ppqn()       const { return _ppqn; }
57         uint16_t num_tracks() const { return _num_tracks; }
58
59         int read_event(size_t    buf_len,
60                        uint8_t*  buf,
61                        uint32_t* ev_size,
62                        uint32_t* ev_delta_time)
63                 throw (std::logic_error, PrematureEOF, CorruptFile);
64
65         void close();
66
67         static uint32_t read_var_len(FILE* fd) throw (PrematureEOF);
68
69 protected:
70         /** size of SMF header, including MTrk chunk header */
71         static const uint32_t HEADER_SIZE = 22;
72
73         std::string _filename;
74         FILE*       _fd;
75         uint16_t    _type;
76         uint16_t    _ppqn;
77         uint16_t    _num_tracks;
78         uint32_t    _track;
79         uint32_t    _track_size;
80 };
81
82
83 } // namespace Evoral
84
85 #endif // EVORAL_SMF_READER_HPP
86