#include <cmath>
#include <iostream>
#include <stdint.h>
+
+#include <glib/gstdio.h>
+
#include "libsmf/smf.h"
+
#include "evoral/Event.hpp"
#include "evoral/SMF.hpp"
#include "evoral/midi_util.h"
bool
SMF::test(const std::string& path)
{
- FILE* f = fopen(path.c_str(), "r");
+ FILE* f = g_fopen(path.c_str(), "r");
if (f == 0) {
return false;
}
smf_delete(_smf);
}
- _file_path = path;
-
- FILE* f = fopen(_file_path.c_str(), "r");
+ FILE* f = g_fopen(path.c_str(), "r");
if (f == 0) {
return -1;
} else if ((_smf = smf_load(f)) == 0) {
smf_delete(_smf);
}
- _file_path = path;
-
_smf = smf_new();
if (_smf == NULL) {
{
/* put a stub file on disk */
- FILE* f = fopen (_file_path.c_str(), "w+");
+ FILE* f = g_fopen (path.c_str(), "w+");
if (f == 0) {
return -1;
}
}
memcpy(*buf, event->midi_buffer, size_t(event_size));
*size = event_size;
+ if (((*buf)[0] & 0xF0) == 0x90 && (*buf)[2] == 0) {
+ /* normalize note on with velocity 0 to proper note off */
+ (*buf)[0] = 0x80 | ((*buf)[0] & 0x0F); /* note off */
+ (*buf)[2] = 0x40; /* default velocity */
+ }
if (!midi_event_is_valid(*buf, *size)) {
cerr << "WARNING: SMF ignoring illegal MIDI event" << endl;
}
void
-SMF::end_write() THROW_FILE_ERROR
+SMF::end_write(string const & path) THROW_FILE_ERROR
{
Glib::Threads::Mutex::Lock lm (_smf_lock);
- FILE* f = fopen (_file_path.c_str(), "w+");
+
+ if (!_smf) {
+ return;
+ }
+
+ FILE* f = g_fopen (path.c_str(), "w+");
if (f == 0) {
- throw FileError (_file_path);
+ throw FileError (path);
}
if (smf_save(_smf, f) != 0) {
fclose(f);
- throw FileError (_file_path);
+ throw FileError (path);
}
fclose(f);
return round (val * div) / div;
}
-void
-SMF::set_path (const std::string& p)
-{
- _file_path = p;
-}
-
} // namespace Evoral