Patch from agorka to add some includes required for building with the GCC shipped...
[ardour.git] / libs / evoral / src / SMF.cpp
index 5e17dcf6ce1053165a06227e321b0ae1885e18c0..372c37c0bb79b4ba5a493d8dd830dec5b6fc001f 100644 (file)
 #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;
 
@@ -79,8 +80,8 @@ SMF::open(const std::string& path, int track) THROW_FILE_ERROR
                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;
        }
@@ -116,7 +117,7 @@ SMF::create(const std::string& path, int track, uint16_t ppqn) THROW_FILE_ERROR
                smf_delete(_smf);
        }
        
-       _path = path;
+       _file_path = path;
 
        _smf = smf_new();
        if (smf_set_ppqn(_smf, ppqn) != 0) {
@@ -147,7 +148,7 @@ void
 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);
@@ -201,6 +202,8 @@ SMF::read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const
        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]);
@@ -224,6 +227,11 @@ SMF::append_event_delta(uint32_t delta_t, uint32_t size, const uint8_t* buf)
                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);
@@ -250,7 +258,7 @@ SMF::begin_write()
 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();
 }