1 /* This file is part of Evoral.
2 * Copyright(C) 2008 Dave Robillard <http://drobilla.net>
3 * Copyright(C) 2000-2008 Paul Davis
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
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.
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
19 #ifndef EVORAL_SMF_READER_HPP
20 #define EVORAL_SMF_READER_HPP
30 /** Standard MIDI File (Type 0) Reader
32 * Currently this only reads SMF files with tempo-based timing.
36 class PrematureEOF : public std::exception {
37 const char* what() const throw() { return "Unexpected end of file"; }
39 class CorruptFile : public std::exception {
40 const char* what() const throw() { return "Corrupted file"; }
42 class UnsupportedTime : public std::exception {
43 const char* what() const throw() { return "Unsupported time stamp type (SMPTE)"; }
46 SMFReader(const std::string& filename="");
49 bool open(const std::string& filename) throw (std::logic_error, UnsupportedTime);
51 bool seek_to_track(unsigned track) throw (std::logic_error);
53 const std::string& filename() const { return _filename; };
55 uint16_t type() const { return _type; }
56 uint16_t ppqn() const { return _ppqn; }
57 uint16_t num_tracks() const { return _num_tracks; }
59 int read_event(size_t buf_len,
62 uint32_t* ev_delta_time)
63 throw (std::logic_error, PrematureEOF, CorruptFile);
67 static uint32_t read_var_len(FILE* fd) throw (PrematureEOF);
70 /** size of SMF header, including MTrk chunk header */
71 static const uint32_t HEADER_SIZE = 22;
73 std::string _filename;
85 #endif // EVORAL_SMF_READER_HPP