summaryrefslogtreecommitdiff
path: root/libs/evoral/src/SMF.cpp
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2010-05-16 20:54:50 +0000
committerCarl Hetherington <carl@carlh.net>2010-05-16 20:54:50 +0000
commitf1114dedeecf4279a4c19a85be0c11e9fde5610b (patch)
tree090a85771cda9f207a924e38c8f14290adbda033 /libs/evoral/src/SMF.cpp
parent50615cd17c06a5f4c8a196182407ceee7d182635 (diff)
Move FileManager code into libpbd. Use it for SMF read/write.
git-svn-id: svn://localhost/ardour2/branches/3.0@7108 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/evoral/src/SMF.cpp')
-rw-r--r--libs/evoral/src/SMF.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/libs/evoral/src/SMF.cpp b/libs/evoral/src/SMF.cpp
index 73e3651f45..007055def8 100644
--- a/libs/evoral/src/SMF.cpp
+++ b/libs/evoral/src/SMF.cpp
@@ -26,6 +26,7 @@
#include "evoral/Event.hpp"
#include "evoral/SMF.hpp"
#include "evoral/midi_util.h"
+#include "pbd/file_manager.h"
using namespace std;
@@ -82,7 +83,14 @@ SMF::open(const std::string& path, int track) THROW_FILE_ERROR
}
_file_path = path;
- _smf = smf_load(_file_path.c_str());
+
+ PBD::StdioFileDescriptor d (_file_path, "r");
+ FILE* f = d.allocate ();
+ if (f == 0) {
+ return -1;
+ }
+
+ _smf = smf_load (f);
if (_smf == NULL) {
return -1;
}
@@ -149,7 +157,13 @@ void
SMF::close() THROW_FILE_ERROR
{
if (_smf) {
- if (smf_save(_smf, _file_path.c_str()) != 0) {
+ PBD::StdioFileDescriptor d (_file_path, "w+");
+ FILE* f = d.allocate ();
+ if (f == 0) {
+ throw FileError ();
+ }
+
+ if (smf_save(_smf, f) != 0) {
throw FileError();
}
smf_delete(_smf);
@@ -259,8 +273,15 @@ SMF::begin_write()
void
SMF::end_write() THROW_FILE_ERROR
{
- if (smf_save(_smf, _file_path.c_str()) != 0)
+ PBD::StdioFileDescriptor d (_file_path, "w+");
+ FILE* f = d.allocate ();
+ if (f == 0) {
+ throw FileError ();
+ }
+
+ if (smf_save(_smf, f) != 0) {
throw FileError();
+ }
}
double