#include <cassert>
#include <iostream>
#include <stdint.h>
+#include "libsmf/smf.h"
#include "evoral/Event.hpp"
#include "evoral/SMF.hpp"
-#include "libsmf/smf.h"
+#include "evoral/midi_util.h"
using namespace std;
smf_delete(_smf);
}
- _path = path;
- _smf = smf_load(_path.c_str());
+ _file_path = path;
+ _smf = smf_load(_file_path.c_str());
if (_smf == NULL) {
return -1;
}
smf_delete(_smf);
}
- _path = path;
+ _file_path = path;
_smf = smf_new();
if (smf_set_ppqn(_smf, ppqn) != 0) {
SMF::close() THROW_FILE_ERROR
{
if (_smf) {
- if (smf_save(_smf, _path.c_str()) != 0) {
+ if (smf_save(_smf, _file_path.c_str()) != 0) {
throw FileError();
}
smf_delete(_smf);
memcpy(*buf, event->midi_buffer, size_t(event_size));
*size = event_size;
+ assert(midi_event_is_valid(*buf, *size));
+
/*printf("SMF::read_event:\n");
for (size_t i = 0; i < *size; ++i) {
printf("%X ", (*buf)[i]);
printf("%X ", buf[i]);
} printf("\n");*/
+ if (!midi_event_is_valid(buf, size)) {
+ cerr << "WARNING: SMF ignoring illegal MIDI event" << endl;
+ return;
+ }
+
smf_event_t* event;
event = smf_event_new_from_pointer(buf, size);
void
SMF::end_write() THROW_FILE_ERROR
{
- if (smf_save(_smf, _path.c_str()) != 0)
+ if (smf_save(_smf, _file_path.c_str()) != 0)
throw FileError();
}