2 Copyright (C) 2008 Paul Davis
3 Written by Dave Robillard
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_smf_reader_h__
21 #define __ardour_smf_reader_h__
31 /** Standard MIDI File (Type 0) Reader
33 * Currently this only reads SMF files with tempo-based timing.
37 class PrematureEOF : public std::exception {
38 const char* what() const throw() { return "Unexpected end of file"; }
40 class CorruptFile : public std::exception {
41 const char* what() const throw() { return "Corrupted file"; }
43 class UnsupportedTime : public std::exception {
44 const char* what() const throw() { return "Unsupported time stamp type (SMPTE)"; }
47 SMFReader(const std::string filename="");
50 bool open(const std::string& filename) throw (std::logic_error, UnsupportedTime);
52 bool seek_to_track(unsigned track) throw (std::logic_error);
54 const std::string& filename() const { return _filename; };
56 uint16_t type() const { return _type; }
57 uint16_t ppqn() const { return _ppqn; }
58 uint16_t num_tracks() const { return _num_tracks; }
60 int read_event(size_t buf_len,
63 uint32_t* ev_delta_time)
64 throw (std::logic_error, PrematureEOF, CorruptFile);
68 static uint32_t read_var_len(FILE* fd) throw (PrematureEOF);
71 /** size of SMF header, including MTrk chunk header */
72 static const uint32_t HEADER_SIZE = 22;
74 std::string _filename;
86 #endif /* __ardour_smf_reader_h__ */