2009-02-11 04:54:31 -05:00
|
|
|
/* This file is part of Evoral.
|
|
|
|
* Copyright(C) 2008 Dave Robillard <http://drobilla.net>
|
|
|
|
* Copyright(C) 2000-2008 Paul Davis
|
|
|
|
* Author: Hans Baier
|
|
|
|
*
|
|
|
|
* Evoral is free software; you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or(at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2009-02-14 12:35:34 -05:00
|
|
|
#ifndef EVORAL_SMF_HPP
|
|
|
|
#define EVORAL_SMF_HPP
|
2009-02-11 04:54:31 -05:00
|
|
|
|
2009-02-11 12:38:40 -05:00
|
|
|
#include <cassert>
|
2009-02-11 04:54:31 -05:00
|
|
|
|
2009-02-11 12:38:40 -05:00
|
|
|
struct smf_struct;
|
|
|
|
struct smf_track_struct;
|
|
|
|
typedef smf_struct smf_t;
|
|
|
|
typedef smf_track_struct smf_track_t;
|
2009-02-11 04:54:31 -05:00
|
|
|
|
|
|
|
namespace Evoral {
|
|
|
|
|
|
|
|
template<typename Time> class Event;
|
|
|
|
template<typename Time> class EventRingBuffer;
|
|
|
|
|
2009-02-14 12:39:49 -05:00
|
|
|
#define THROW_FILE_ERROR throw(typename SMF<Time>::FileError)
|
|
|
|
|
2009-02-11 04:54:31 -05:00
|
|
|
/** Standard Midi File (Type 0)
|
|
|
|
*/
|
|
|
|
template<typename Time>
|
2009-02-14 12:39:49 -05:00
|
|
|
class SMF {
|
2009-02-11 04:54:31 -05:00
|
|
|
public:
|
2009-02-14 12:39:49 -05:00
|
|
|
class FileError : public std::exception {
|
|
|
|
const char* what() const throw() { return "Unknown SMF error"; }
|
|
|
|
};
|
|
|
|
|
2009-02-14 12:35:34 -05:00
|
|
|
SMF() : _last_ev_time(0), _smf(0), _smf_track(0), _empty(true) {};
|
|
|
|
virtual ~SMF();
|
2009-02-14 12:54:45 -05:00
|
|
|
|
2009-02-14 15:52:15 -05:00
|
|
|
int open(const std::string& path, int track=1) THROW_FILE_ERROR;
|
2009-02-14 17:23:40 -05:00
|
|
|
int create(const std::string& path, int track=1, uint16_t ppqn=19200) THROW_FILE_ERROR;
|
2009-02-14 12:54:45 -05:00
|
|
|
void close() THROW_FILE_ERROR;
|
2009-02-14 15:52:15 -05:00
|
|
|
|
|
|
|
const std::string& path() const { return _path; };
|
2009-02-11 04:54:31 -05:00
|
|
|
|
|
|
|
void seek_to_start() const;
|
2009-02-14 15:52:15 -05:00
|
|
|
int seek_to_track(int track);
|
|
|
|
|
|
|
|
int read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const;
|
2009-02-11 04:54:31 -05:00
|
|
|
|
2009-02-14 15:52:15 -05:00
|
|
|
uint16_t num_tracks() const;
|
|
|
|
uint16_t ppqn() const;
|
|
|
|
bool is_empty() const { return _empty; }
|
|
|
|
bool eof() const { assert(false); return true; }
|
2009-02-11 04:54:31 -05:00
|
|
|
|
|
|
|
Time last_event_time() const { return _last_ev_time; }
|
|
|
|
|
2009-02-11 15:37:22 -05:00
|
|
|
void begin_write();
|
|
|
|
void append_event_delta(uint32_t delta_t, const Event<Time>& ev);
|
2009-02-11 12:59:33 -05:00
|
|
|
void end_write() THROW_FILE_ERROR;
|
2009-02-11 04:54:31 -05:00
|
|
|
|
|
|
|
void flush() {};
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const uint16_t _ppqn = 19200;
|
|
|
|
|
2009-02-11 12:38:40 -05:00
|
|
|
Time _last_ev_time; ///< last frame time written, relative to source start
|
2009-02-11 04:54:31 -05:00
|
|
|
|
|
|
|
std::string _path;
|
|
|
|
smf_t* _smf;
|
|
|
|
smf_track_t* _smf_track;
|
|
|
|
|
|
|
|
bool _empty; ///< true iff file contains(non-empty) events
|
|
|
|
};
|
|
|
|
|
|
|
|
}; /* namespace Evoral */
|
|
|
|
|
2009-02-14 12:35:34 -05:00
|
|
|
#endif /* EVORAL_SMF_HPP */
|
2009-02-11 04:54:31 -05:00
|
|
|
|