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).
This commit is contained in:
Paul Davis 2025-08-18 16:24:22 -06:00
parent b60702e014
commit 73065f814a
2 changed files with 20 additions and 9 deletions

View file

@ -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

View file

@ -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() {};