diff options
author | Robin Gareus <robin@gareus.org> | 2015-12-27 03:40:48 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2015-12-27 03:40:48 +0100 |
commit | 8d45eecd456c81f7b334bfd72610f17164ac7a03 (patch) | |
tree | 65fcb88d5fa9de3b2639986e4a11f9ba7a345949 /libs/evoral | |
parent | 2c197fd89aa572f3c0a0db404ad17759fcc19a76 (diff) |
somewhat better solution to prev commit.
parse up to 32bit VLQs, match smf_format_vlq()
Diffstat (limited to 'libs/evoral')
-rw-r--r-- | libs/evoral/src/Event.cpp | 15 | ||||
-rw-r--r-- | libs/evoral/src/libsmf/smf_load.c | 10 |
2 files changed, 12 insertions, 13 deletions
diff --git a/libs/evoral/src/Event.cpp b/libs/evoral/src/Event.cpp index 3c1cc000bd..64caba3952 100644 --- a/libs/evoral/src/Event.cpp +++ b/libs/evoral/src/Event.cpp @@ -38,23 +38,16 @@ init_event_id_counter(event_id_t n) event_id_t next_event_id () { - /* libsmf supports reading variable-length data up to 4 bytes only. - * so we wrap around at 2^(4 * 7) - 1 - * - * interestingly enough libsmf happily writes data longer than that, but then - * fails to load it in ./libs/evoral/src/libsmf/smf_load.c:237 - * g_critical("SMF error: Variable Length Quantities longer than four bytes are not supported yet."); + /* TODO: handle 31bit overflow , event_id_t is an int32_t, + * and libsmf only supports loading uint32_t vlq's, see smf_extract_vlq() * * event-IDs only have to be unique per .mid file. * Previously (Ardour 4.2ish) Ardour re-generated those IDs when loading the * file but that lead to .mid files being modified on every load/save. * - * For now just assume that by the time 2^28 is reached, files with low ids have vanished. - * There is only one user who managed to get to 268 million events so far. - * quite a feat: id-counter="6483089" event-counter="276390506" - * Eventually a proper solution will have to be implemented. + * current user-record: is event-counter="276390506" (just abov 2^28) */ - return g_atomic_int_add (&_event_id_counter, 1) & 268435455; + return g_atomic_int_add (&_event_id_counter, 1); } #ifdef EVORAL_EVENT_ALLOC diff --git a/libs/evoral/src/libsmf/smf_load.c b/libs/evoral/src/libsmf/smf_load.c index a23a88fa49..001774cd14 100644 --- a/libs/evoral/src/libsmf/smf_load.c +++ b/libs/evoral/src/libsmf/smf_load.c @@ -214,13 +214,19 @@ smf_extract_vlq(const unsigned char *buf, const size_t buffer_length, uint32_t * { uint32_t val = 0; const unsigned char *c = buf; + int i = 0; - for (;;) { + for (;; ++i) { if (c >= buf + buffer_length) { g_critical("End of buffer in extract_vlq()."); return (-1); } + if (i == 4 && (val & 0xfe000000)) { + g_critical("SMF error: Variable Length Quantities longer than four bytes are not supported yet."); + return (-2); + } + val = (val << 7) + (*c & 0x7F); if (*c & 0x80) @@ -233,7 +239,7 @@ smf_extract_vlq(const unsigned char *buf, const size_t buffer_length, uint32_t * *value = val; *len = c - buf + 1; - if (*len > 4) { + if (*len > 5) { g_critical("SMF error: Variable Length Quantities longer than four bytes are not supported yet."); return (-2); } |