-#include "evoral/LibSMF.hpp"
-#include "evoral/Event.hpp"
-#include <cassert>
+/* 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
+ */
+#include <cassert>
#include <iostream>
+#include "evoral/Event.hpp"
+#include "evoral/LibSMF.hpp"
+#include "libsmf/smf.h"
using namespace std;
namespace Evoral {
+template<typename Time>
+LibSMF<Time>::~LibSMF()
+{
+ if (_smf) {
+ smf_delete(_smf);
+ _smf = 0;
+ _smf_track = 0;
+ }
+}
/** Attempt to open the SMF file for reading and writing.
*
*/
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);
_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 MIDIFile<Time>::FileError();
+ }
if(_smf == NULL) {
return -1;
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 MIDIFile<Time>::FileError();
+ }
smf_delete(_smf);
_smf = 0;
_smf_track = 0;
template<typename Time>
void
-LibSMF<Time>::append_event_unlocked(uint32_t delta_t, const Event<Time>& ev)
+LibSMF<Time>::append_event_delta(uint32_t delta_t, const Event<Time>& ev)
{
assert(ev.size() > 0);
template<typename Time>
void
-LibSMF<Time>::begin_write(FrameTime start_frame)
+LibSMF<Time>::begin_write()
{
assert(_smf_track);
smf_track_delete(_smf_track);
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 MIDIFile<Time>::FileError();
}
template class LibSMF<double>;