093267041bc31c82f2a4e7d12c08513080570335
[ardour.git] / libs / evoral / evoral / MIDIFile.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  * Author: Hans Baier
5  * 
6  * Evoral is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or(at your option) any later
9  * version.
10  * 
11  * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
14  * 
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #ifndef EVORAL_STANDARD_MIDI_FILE_HPP
21 #define EVORAL_STANDARD_MIDI_FILE_HPP
22
23 #include <string>
24 #include "evoral/types.hpp"
25
26 namespace Evoral {
27         
28 template<typename Time> class Event;
29 template<typename Time> class EventRingBuffer;
30
31 #define THROW_FILE_ERROR throw(typename MIDIFile<Time>::FileError)
32
33 /** Standard MIDI File interface
34  */
35 template<typename Time>
36 class MIDIFile {
37 public:
38         class FileError : public std::exception {
39                 const char* what() const throw() { return "libsmf error"; }
40         };
41
42         virtual void seek_to_start() const = 0;
43         
44         virtual uint16_t ppqn()     const = 0;
45         virtual bool     is_empty() const = 0;
46         virtual bool     eof()      const = 0;
47         
48         virtual Time last_event_time() const = 0;
49         
50         virtual void begin_write(FrameTime start_time) = 0;
51         virtual void append_event_unlocked(uint32_t delta_t, const Event<Time>& ev) = 0;
52         virtual void end_write() throw(FileError) = 0;
53         
54         virtual void flush() = 0;
55         virtual int  flush_header() = 0;
56         virtual int  flush_footer() = 0;
57
58 protected:
59         virtual int  open(const std::string& path) throw(FileError) = 0;
60         virtual void close() throw(FileError) = 0;
61         
62         virtual int read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const = 0;
63
64 };
65
66 }; /* namespace Evoral */
67
68 #endif /* EVORAL_STANDARD_MIDI_FILE_HPP */
69