summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/evoral/src/LibSMF.cpp11
-rw-r--r--libs/evoral/test/SMFTest.cpp10
-rw-r--r--libs/evoral/test/SMFTest.hpp14
3 files changed, 33 insertions, 2 deletions
diff --git a/libs/evoral/src/LibSMF.cpp b/libs/evoral/src/LibSMF.cpp
index 832d5f3225..2aa64b27d6 100644
--- a/libs/evoral/src/LibSMF.cpp
+++ b/libs/evoral/src/LibSMF.cpp
@@ -52,7 +52,10 @@ LibSMF<Time>::open(const std::string& path) THROW_FILE_ERROR
smf_delete(_smf);
}
- _smf = smf_load(path.c_str());
+ _path = path;
+ assert(_path != "");
+
+ _smf = smf_load(_path.c_str());
if (!_smf) {
_smf = smf_new();
if (smf_set_ppqn(_smf, _ppqn) != 0) {
@@ -62,6 +65,11 @@ LibSMF<Time>::open(const std::string& path) THROW_FILE_ERROR
if(_smf == NULL) {
return -1;
}
+
+ _smf_track = smf_track_new();
+ assert(_smf_track);
+
+ smf_add_track(_smf, _smf_track);
}
_smf_track = smf_get_track_by_number(_smf, 1);
@@ -78,7 +86,6 @@ template<typename Time>
void
LibSMF<Time>::close() THROW_FILE_ERROR
{
- assert(false);
if (_smf) {
if (smf_save(_smf, _path.c_str()) != 0) {
throw typename MIDIFile<Time>::FileError();
diff --git a/libs/evoral/test/SMFTest.cpp b/libs/evoral/test/SMFTest.cpp
index fcfa6ef1dd..f401ea1abd 100644
--- a/libs/evoral/test/SMFTest.cpp
+++ b/libs/evoral/test/SMFTest.cpp
@@ -5,6 +5,16 @@ using namespace std;
CPPUNIT_TEST_SUITE_REGISTRATION( SMFTest );
void
+SMFTest::createNewFileTest ()
+{
+ TestSMF<Time> smf;
+ smf.open("NewFile.mid");
+ smf.close();
+ CPPUNIT_ASSERT(access(smf.path().c_str(), R_OK) == 0);
+ unlink(smf.path().c_str());
+}
+
+void
SMFTest::takeFiveTest ()
{
TestSMF<Time> smf;
diff --git a/libs/evoral/test/SMFTest.hpp b/libs/evoral/test/SMFTest.hpp
index 9787af8fc1..e4d390a07f 100644
--- a/libs/evoral/test/SMFTest.hpp
+++ b/libs/evoral/test/SMFTest.hpp
@@ -14,18 +14,31 @@ using namespace Evoral;
template<typename Time>
class TestSMF : public LibSMF<Time> {
public:
+ std::string path() const { return _path; }
+
int open(const std::string& path) THROW_FILE_ERROR {
+ _path = path;
return LibSMF<Time>::open(path);
}
+ void close() THROW_FILE_ERROR {
+ return LibSMF<Time>::close();
+ }
+
int read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const {
return LibSMF<Time>::read_event(delta_t, size, buf);
}
+
+private:
+
+ std::string _path;
+
};
class SMFTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE (SMFTest);
+ CPPUNIT_TEST (createNewFileTest);
CPPUNIT_TEST (takeFiveTest);
CPPUNIT_TEST_SUITE_END ();
@@ -45,6 +58,7 @@ class SMFTest : public CppUnit::TestFixture
delete type_map;
}
+ void createNewFileTest(void);
void takeFiveTest (void);
private: