summaryrefslogtreecommitdiff
path: root/libs/ardour/smf_source.cc
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-02-19 03:24:44 +0000
committerDavid Robillard <d@drobilla.net>2008-02-19 03:24:44 +0000
commit012292b4bdf5bf843232243852b39e8892b837de (patch)
treecddefe42aab1301df0677d652d37ba757894d97b /libs/ardour/smf_source.cc
parentb79d5bfad3473f54ab24c0b7852fc4bfc9d9ebb0 (diff)
Less crash-happy MIDI reading on weird MIDI files.
Make "show existing automation" create/show automation tracks for all contained CC in MIDI tracks. Fix staggered time when importing multi-track MIDI files. git-svn-id: svn://localhost/ardour2/branches/3.0@3086 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/smf_source.cc')
-rw-r--r--libs/ardour/smf_source.cc47
1 files changed, 20 insertions, 27 deletions
diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc
index 4903cf384f..85cebf2b09 100644
--- a/libs/ardour/smf_source.cc
+++ b/libs/ardour/smf_source.cc
@@ -38,6 +38,7 @@
#include <ardour/midi_util.h>
#include <ardour/tempo.h>
#include <ardour/audioengine.h>
+#include <ardour/smf_reader.h>
#include "i18n.h"
@@ -272,20 +273,31 @@ SMFSource::read_event(uint32_t* delta_t, uint32_t* size, Byte** buf) const
assert(size);
assert(buf);
- *delta_t = read_var_len();
- assert(!feof(_fd));
+ try {
+ *delta_t = SMFReader::read_var_len(_fd);
+ } catch (...) {
+ return -1; // Premature EOF
+ }
+
+ if (feof(_fd)) {
+ return -1; // Premature EOF
+ }
const int status = fgetc(_fd);
- assert(status != EOF); // FIXME die gracefully
+
+ if (status == EOF) {
+ return -1; // Premature EOF
+ }
//printf("Status @ %X = %X\n", (unsigned)ftell(_fd) - 1, status);
if (status == 0xFF) {
- assert(!feof(_fd));
+ if (feof(_fd)) {
+ return -1; // Premature EOF
+ }
const int type = fgetc(_fd);
if ((unsigned char)type == 0x2F) {
- //cerr << _name << " hit EOT" << endl;
- return -1;
+ return -1; // hit end of track
} else {
*size = 0;
return 0;
@@ -444,12 +456,12 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt)
void
SMFSource::append_event_unlocked(const MidiEvent& ev)
{
- printf("%s - append chan = %u, time = %lf, size = %u, data = ", _path.c_str(),
+ /*printf("%s - append chan = %u, time = %lf, size = %u, data = ", _path.c_str(),
(unsigned)ev.channel(), ev.time(), ev.size());
for (size_t i=0; i < ev.size(); ++i) {
printf("%X ", ev.buffer()[i]);
}
- printf("\n");
+ printf("\n");*/
assert(ev.time() >= 0);
assert(ev.time() >= _last_ev_time);
@@ -838,25 +850,6 @@ SMFSource::write_var_len(uint32_t value)
return ret;
}
-uint32_t
-SMFSource::read_var_len() const
-{
- assert(!feof(_fd));
-
- uint32_t value;
- unsigned char c;
-
- if ( (value = getc(_fd)) & 0x80 ) {
- value &= 0x7F;
- do {
- assert(!feof(_fd));
- value = (value << 7) + ((c = getc(_fd)) & 0x7F);
- } while (c & 0x80);
- }
-
- return value;
-}
-
void
SMFSource::load_model(bool lock, bool force_reload)
{