diff --git a/libs/evoral/libsmf/smf.c b/libs/evoral/libsmf/smf.c index 5c6257f6fb..15894312c0 100644 --- a/libs/evoral/libsmf/smf.c +++ b/libs/evoral/libsmf/smf.c @@ -1023,6 +1023,45 @@ smf_get_length_pulses(const smf_t *smf) return (pulses); } +/** + * \return nonzero if the last event in the file has a non-zero delta time, + * and zero otherwise. A non-zero delta time is taken to indicate that the + * file creator explicitly set the length, although it is possible that + * this was done even with a zero delta time (if the last "real" event happened + * to be at the right time. + */ +int +smf_length_is_explicit (const smf_t *smf) +{ + int i; + size_t pulses = 0; + smf_event_t* last_event = NULL; + + for (i = 1; i <= smf->number_of_tracks; i++) { + smf_track_t *track; + smf_event_t *event; + + track = smf_get_track_by_number(smf, i); + assert(track); + + event = smf_track_get_last_event(track); + /* Empty track? */ + if (event == NULL) + continue; + + if (event->time_pulses > pulses) { + pulses = event->time_pulses; + last_event = event; + } + } + + if (last_event) { + return last_event->delta_time_pulses != 0; + } + + return 0; +} + /** * \return Nonzero, if there are no events in the SMF after this one. * Note that may be more than one "last event", if they occur at the same time. diff --git a/libs/evoral/libsmf/smf.h b/libs/evoral/libsmf/smf.h index 3f503ffc92..70206e70aa 100644 --- a/libs/evoral/libsmf/smf.h +++ b/libs/evoral/libsmf/smf.h @@ -346,6 +346,7 @@ int smf_seek_to_event(smf_t *smf, const smf_event_t *event) WARN_UNUSED_RESULT; size_t smf_get_length_pulses(const smf_t *smf) WARN_UNUSED_RESULT; int smf_event_is_last(const smf_event_t *event) WARN_UNUSED_RESULT; +int smf_length_is_explicit(const smf_t *event) WARN_UNUSED_RESULT; void smf_add_track(smf_t *smf, smf_track_t *track); void smf_track_remove_from_smf(smf_track_t *track);