1 /* This file is part of Evoral.
2 * Copyright(C) 2008 David 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
27 #include "evoral/visibility.h"
32 /** Standard MIDI File (Type 0) Reader
34 * Currently this only reads SMF files with tempo-based timing.
36 class LIBEVORAL_API SMFReader {
38 class PrematureEOF : public std::exception {
39 const char* what() const throw() { return "Unexpected end of file"; }
41 class CorruptFile : public std::exception {
42 const char* what() const throw() { return "Corrupted file"; }
44 class UnsupportedTime : public std::exception {
45 const char* what() const throw() { return "Unsupported time stamp type (SMPTE)"; }
48 SMFReader(const std::string& filename="");
51 bool open(const std::string& filename) throw (std::logic_error, UnsupportedTime);
53 bool seek_to_track(unsigned track) throw (std::logic_error);
55 const std::string& filename() const { return _filename; };
57 uint16_t type() const { return _type; }
58 uint16_t ppqn() const { return _ppqn; }
59 uint16_t num_tracks() const { return _num_tracks; }
61 int read_event(size_t buf_len,
64 uint32_t* ev_delta_time)
65 throw (std::logic_error, PrematureEOF, CorruptFile);
69 static uint32_t read_var_len(FILE* fd) throw (PrematureEOF);
72 /** size of SMF header, including MTrk chunk header */
73 static const uint32_t HEADER_SIZE = 22;
75 std::string _filename;
87 #endif // EVORAL_SMF_READER_HPP