From 73065f814aceb9734a5c6be3370db87182dbf3fc Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 18 Aug 2025 16:24:22 -0600 Subject: [PATCH] modify API of Evoral::SMF::append_event_beats() to add meta-event legality If the (new) final argument is true, we allow writing SMF meta events to the underlying libsmf object (which doesn't care one way or another). --- libs/evoral/SMF.cc | 27 +++++++++++++++++++-------- libs/evoral/evoral/SMF.h | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/libs/evoral/SMF.cc b/libs/evoral/SMF.cc index 3d9dbd08db..483744a136 100644 --- a/libs/evoral/SMF.cc +++ b/libs/evoral/SMF.cc @@ -411,8 +411,6 @@ SMF::read_event(uint32_t* delta_t, uint32_t* bufsize, uint8_t** buf, event_id_t* } } -void -SMF::append_event_delta(uint32_t delta_t, uint32_t size, const uint8_t* buf, event_id_t note_id) bool SMF::is_meta (uint8_t const* buf, uint32_t size) { @@ -442,11 +440,13 @@ SMF::is_meta (uint8_t const* buf, uint32_t size) return false; } +int +SMF::append_event_delta (uint32_t delta_t, uint32_t size, const uint8_t* buf, event_id_t note_id, bool allow_meta) { Glib::Threads::Mutex::Lock lm (_smf_lock); if (size == 0) { - return; + return 0; } /* printf("SMF::append_event_delta @ %u:", delta_t); @@ -468,15 +468,24 @@ SMF::is_meta (uint8_t const* buf, uint32_t size) case 0xfc: case 0xfd: case 0xfe: - case 0xff: /* System Real Time or System Common event: not valid in SMF */ - return; + return 0; } - if (!midi_event_is_valid(buf, size)) { - cerr << "WARNING: SMF ignoring illegal MIDI event" << endl; - return; + if (buf[0] == 0xff) { /* meta event */ + + if (!is_meta (buf, size) || !allow_meta) { + return 0; + } + + } else { + + if (!midi_event_is_valid(buf, size)) { + cerr << "WARNING: SMF ignoring illegal MIDI event" << endl; + return 0; + } + } smf_event_t* event; @@ -534,6 +543,8 @@ SMF::is_meta (uint8_t const* buf, uint32_t size) assert(_smf_track); smf_track_add_event_delta_pulses(_smf_track, event, delta_t); _empty = false; + + return size; } void diff --git a/libs/evoral/evoral/SMF.h b/libs/evoral/evoral/SMF.h index 67ba0074b2..9914d54684 100644 --- a/libs/evoral/evoral/SMF.h +++ b/libs/evoral/evoral/SMF.h @@ -91,7 +91,7 @@ public: static bool is_meta (uint8_t const * buf, uint32_t size); void begin_write(); - void append_event_delta(uint32_t delta_t, uint32_t size, const uint8_t* buf, event_id_t note_id); + int append_event_delta (uint32_t delta_t, uint32_t size, const uint8_t* buf, event_id_t note_id, bool allow_meta = false); void end_write(std::string const &); void flush() {};