ardour
OldSMF.hpp
Go to the documentation of this file.
1 /* This file is part of Evoral.
2  * Copyright(C) 2008 David 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_OLD_SMF_HPP
20 #define EVORAL_OLD_SMF_HPP
21 
22 #include "evoral/visibility.h"
23 
24 namespace Evoral {
25 
26 template<typename Time> class Event;
27 
30 template<typename Time>
31 class /*LIBEVORAL_API*/ SMF {
32 public:
33  SMF();
34  virtual ~SMF();
35 
36  void seek_to_start() const;
37 
38  uint16_t ppqn() const { return _ppqn; }
39  bool is_empty() const { return _empty; }
40  bool eof() const { return feof(_fd); }
41 
42  Time last_event_time() const { return _last_ev_time; }
43 
44  void begin_write();
45  void append_event_delta(uint32_t delta_t, const Event<Time>& ev);
47 
48  void flush();
49  int flush_header();
50  int flush_footer();
51 
52 protected:
53  int open(const std::string& path) THROW_FILE_ERROR;
54  void close() THROW_FILE_ERROR;
55 
56  int read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const;
57 
58 private:
61 
63  void write_footer();
64 
65  void write_chunk_header(const char id[4], uint32_t length);
66  void write_chunk(const char id[4], uint32_t length, void* data);
67  size_t write_var_len(uint32_t val);
68  uint32_t read_var_len() const;
69 
70  static const uint16_t _ppqn = 19200;
71 
72  FILE* _fd;
74  uint32_t _track_size;
75  uint32_t _header_size;
76  bool _empty;
77 };
78 
79 }; /* namespace Evoral */
80 
81 #endif /* EVORAL_OLD_SMF_HPP */
82 
bool is_empty() const
Definition: OldSMF.hpp:39
int read_event(uint32_t *delta_t, uint32_t *size, uint8_t **buf) const
Definition: OldSMF.cpp:212
void end_write() THROW_FILE_ERROR
Definition: OldSMF.cpp:315
bool _empty
true iff file contains(non-empty) events
Definition: OldSMF.hpp:76
uint32_t _header_size
size of SMF header, including MTrk chunk header
Definition: OldSMF.hpp:75
Definition: Beats.hpp:239
int open(const std::string &path) THROW_FILE_ERROR
Definition: OldSMF.cpp:60
uint16_t ppqn() const
Definition: OldSMF.hpp:38
size_t write_var_len(uint32_t val)
Definition: OldSMF.cpp:343
virtual ~SMF()
Definition: OldSMF.cpp:46
void close() THROW_FILE_ERROR
Definition: OldSMF.cpp:96
uint32_t _track_size
Definition: OldSMF.hpp:74
static const uint16_t _ppqn
Definition: OldSMF.hpp:70
void write_footer()
Definition: OldSMF.cpp:187
void write_chunk_header(const char id[4], uint32_t length)
Definition: OldSMF.cpp:323
bool eof() const
Definition: OldSMF.hpp:40
int flush_footer()
Definition: OldSMF.cpp:175
int flush_header()
Definition: OldSMF.cpp:145
void begin_write()
Definition: OldSMF.cpp:307
uint32_t read_var_len() const
void write_chunk(const char id[4], uint32_t length, void *data)
Definition: OldSMF.cpp:333
FILE * _fd
Definition: OldSMF.hpp:72
void seek_to_start() const
Definition: OldSMF.cpp:108
void seek_to_footer_position()
Definition: OldSMF.cpp:115
void flush()
Definition: OldSMF.cpp:138
void append_event_delta(uint32_t delta_t, const Event< Time > &ev)
Definition: OldSMF.cpp:284
Time _last_ev_time
last frame time written, relative to source start
Definition: OldSMF.hpp:73
#define THROW_FILE_ERROR
Definition: SMF.hpp:35
LIBARDOUR_API PBD::PropertyDescriptor< framecnt_t > length
Definition: region.cc:64
Time last_event_time() const
Definition: OldSMF.hpp:42