diff options
Diffstat (limited to 'libs/evoral')
-rw-r--r-- | libs/evoral/evoral/SMF.hpp | 1 | ||||
-rw-r--r-- | libs/evoral/src/SMF.cpp | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/libs/evoral/evoral/SMF.hpp b/libs/evoral/evoral/SMF.hpp index 8bd05444c4..02d0710409 100644 --- a/libs/evoral/evoral/SMF.hpp +++ b/libs/evoral/evoral/SMF.hpp @@ -50,6 +50,7 @@ public: SMF() : _smf(0), _smf_track(0), _empty(true) {}; virtual ~SMF(); + static bool test(const std::string& path); int open(const std::string& path, int track=1) THROW_FILE_ERROR; int create(const std::string& path, int track=1, uint16_t ppqn=19200) THROW_FILE_ERROR; void close() THROW_FILE_ERROR; diff --git a/libs/evoral/src/SMF.cpp b/libs/evoral/src/SMF.cpp index b84507818c..6557a01b80 100644 --- a/libs/evoral/src/SMF.cpp +++ b/libs/evoral/src/SMF.cpp @@ -67,6 +67,28 @@ SMF::seek_to_track(int track) } } +/** Attempt to open the SMF file just to see if it is valid. + * + * \return true on success + * false on failure + */ +bool +SMF::test(const std::string& path) +{ + PBD::StdioFileDescriptor d (path, "r"); + FILE* f = d.allocate (); + if (f == 0) { + return false; + } + + smf_t* test_smf; + if ((test_smf = smf_load (f)) == NULL) { + return false; + } + smf_delete (test_smf); + return true; +} + /** Attempt to open the SMF file for reading and/or writing. * * \return 0 on success |