Detect libsmf error and throw exceptions.
git-svn-id: svn://localhost/ardour2/branches/3.0@4532 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
13bcd43423
commit
33bbc5cd84
@ -51,15 +51,15 @@ public:
|
||||
|
||||
void begin_write(FrameTime start_time);
|
||||
void append_event_unlocked(uint32_t delta_t, const Event<Time>& ev);
|
||||
void end_write();
|
||||
void end_write() THROW_FILE_ERROR;
|
||||
|
||||
void flush() {};
|
||||
int flush_header() { return 0; }
|
||||
int flush_footer() { return 0; }
|
||||
|
||||
protected:
|
||||
int open(const std::string& path);
|
||||
void close();
|
||||
int open(const std::string& path) THROW_FILE_ERROR;
|
||||
void close() THROW_FILE_ERROR;
|
||||
|
||||
int read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const;
|
||||
|
||||
|
@ -45,15 +45,15 @@ public:
|
||||
|
||||
void begin_write(FrameTime start_time);
|
||||
void append_event_unlocked(uint32_t delta_t, const Event<Time>& ev);
|
||||
void end_write();
|
||||
void end_write() THROW_FILE_ERROR;
|
||||
|
||||
void flush();
|
||||
int flush_header();
|
||||
int flush_footer();
|
||||
|
||||
protected:
|
||||
int open(const std::string& path);
|
||||
void close();
|
||||
int open(const std::string& path) THROW_FILE_ERROR;
|
||||
void close() THROW_FILE_ERROR;
|
||||
|
||||
int read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const;
|
||||
|
||||
|
@ -28,12 +28,17 @@ namespace Evoral {
|
||||
template<typename Time> class Event;
|
||||
template<typename Time> class EventRingBuffer;
|
||||
|
||||
#define THROW_FILE_ERROR throw(typename StandardMIDIFile<Time>::FileError)
|
||||
|
||||
/** Standard MIDI File interface
|
||||
*/
|
||||
template<typename Time>
|
||||
class StandardMIDIFile {
|
||||
public:
|
||||
class FileError : public std::exception {
|
||||
const char* what() const throw() { return "libsmf error"; }
|
||||
};
|
||||
|
||||
virtual void seek_to_start() const = 0;
|
||||
|
||||
virtual uint16_t ppqn() const = 0;
|
||||
@ -44,15 +49,15 @@ public:
|
||||
|
||||
virtual void begin_write(FrameTime start_time) = 0;
|
||||
virtual void append_event_unlocked(uint32_t delta_t, const Event<Time>& ev) = 0;
|
||||
virtual void end_write() = 0;
|
||||
virtual void end_write() throw(FileError) = 0;
|
||||
|
||||
virtual void flush() = 0;
|
||||
virtual int flush_header() = 0;
|
||||
virtual int flush_footer() = 0;
|
||||
|
||||
protected:
|
||||
virtual int open(const std::string& path) = 0;
|
||||
virtual void close() = 0;
|
||||
virtual int open(const std::string& path) throw(FileError) = 0;
|
||||
virtual void close() throw(FileError) = 0;
|
||||
|
||||
virtual int read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const = 0;
|
||||
|
||||
|
@ -46,7 +46,7 @@ LibSMF<Time>::~LibSMF()
|
||||
*/
|
||||
template<typename Time>
|
||||
int
|
||||
LibSMF<Time>::open(const std::string& path)
|
||||
LibSMF<Time>::open(const std::string& path) THROW_FILE_ERROR
|
||||
{
|
||||
if (_smf) {
|
||||
smf_delete(_smf);
|
||||
@ -55,7 +55,9 @@ LibSMF<Time>::open(const std::string& path)
|
||||
_smf = smf_load(path.c_str());
|
||||
if (!_smf) {
|
||||
_smf = smf_new();
|
||||
smf_set_ppqn(_smf, _ppqn);
|
||||
if (smf_set_ppqn(_smf, _ppqn) != 0) {
|
||||
throw typename StandardMIDIFile<Time>::FileError();
|
||||
}
|
||||
|
||||
if(_smf == NULL) {
|
||||
return -1;
|
||||
@ -74,11 +76,13 @@ LibSMF<Time>::open(const std::string& path)
|
||||
|
||||
template<typename Time>
|
||||
void
|
||||
LibSMF<Time>::close()
|
||||
LibSMF<Time>::close() THROW_FILE_ERROR
|
||||
{
|
||||
assert(false);
|
||||
if (_smf) {
|
||||
smf_save(_smf, _path.c_str());
|
||||
if (smf_save(_smf, _path.c_str()) != 0) {
|
||||
throw typename StandardMIDIFile<Time>::FileError();
|
||||
}
|
||||
smf_delete(_smf);
|
||||
_smf = 0;
|
||||
_smf_track = 0;
|
||||
@ -178,9 +182,10 @@ LibSMF<Time>::begin_write(FrameTime start_frame)
|
||||
|
||||
template<typename Time>
|
||||
void
|
||||
LibSMF<Time>::end_write()
|
||||
LibSMF<Time>::end_write() THROW_FILE_ERROR
|
||||
{
|
||||
smf_save(_smf, _path.c_str());
|
||||
if (smf_save(_smf, _path.c_str()) != 0)
|
||||
throw typename StandardMIDIFile<Time>::FileError();
|
||||
}
|
||||
|
||||
template class LibSMF<double>;
|
||||
|
@ -57,7 +57,8 @@ SMF<Time>::~SMF()
|
||||
*/
|
||||
template<typename Time>
|
||||
int
|
||||
SMF<Time>::open(const std::string& path)
|
||||
SMF<Time>::open(const std::string& path) THROW_FILE_ERROR
|
||||
|
||||
{
|
||||
//cerr << "Opening SMF file " << path() << " writeable: " << writable() << endl;
|
||||
_fd = fopen(path.c_str(), "r+");
|
||||
@ -92,7 +93,7 @@ SMF<Time>::open(const std::string& path)
|
||||
|
||||
template<typename Time>
|
||||
void
|
||||
SMF<Time>::close()
|
||||
SMF<Time>::close() THROW_FILE_ERROR
|
||||
{
|
||||
if (_fd) {
|
||||
flush_header();
|
||||
@ -311,7 +312,7 @@ SMF<Time>::begin_write(FrameTime start_frame)
|
||||
|
||||
template<typename Time>
|
||||
void
|
||||
SMF<Time>::end_write()
|
||||
SMF<Time>::end_write() throw(typename StandardMIDIFile<Time>::FileError)
|
||||
{
|
||||
flush_header();
|
||||
flush_footer();
|
||||
|
@ -14,7 +14,7 @@ using namespace Evoral;
|
||||
template<typename Time>
|
||||
class TestSMF : public LibSMF<Time> {
|
||||
public:
|
||||
int open(const std::string& path) {
|
||||
int open(const std::string& path) THROW_FILE_ERROR {
|
||||
return LibSMF<Time>::open(path);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user