From aa2fb8c1d46abc4a24934f9b63610fcb05fbdbbd Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 22 Oct 2024 14:35:31 -0600 Subject: [PATCH] SMF: add a set_length() method which will place TrkEnd meta-events --- libs/evoral/SMF.cc | 16 ++++++++++++++++ libs/evoral/evoral/SMF.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/libs/evoral/SMF.cc b/libs/evoral/SMF.cc index d5af69dc58..f8af97be0b 100644 --- a/libs/evoral/SMF.cc +++ b/libs/evoral/SMF.cc @@ -34,6 +34,7 @@ #include "libsmf/smf.h" #include "temporal/tempo.h" +#include "temporal/beats.h" #include "evoral/Event.h" #include "evoral/SMF.h" @@ -528,6 +529,21 @@ SMF::end_write(string const & path) fclose(f); } +void +SMF::set_length (Temporal::Beats const & b) +{ + if (!_smf) { + return; + } + + for (uint16_t n = 0; n < _smf->number_of_tracks; ++n) { + smf_track_t* trk = smf_get_track_by_number (_smf, n+1); + if (trk) { + smf_track_add_eot_pulses (trk, (int) floor (b.get_ticks() * ((double) ppqn() / Temporal::ticks_per_beat))); + } + } +} + double SMF::round_to_file_precision (double val) const { diff --git a/libs/evoral/evoral/SMF.h b/libs/evoral/evoral/SMF.h index 0c9908cf63..656a63b2ab 100644 --- a/libs/evoral/evoral/SMF.h +++ b/libs/evoral/evoral/SMF.h @@ -39,6 +39,7 @@ typedef smf_tempo_struct smf_tempo_t; namespace Temporal { class TempoMap; + class Beats; } namespace Evoral { @@ -89,6 +90,7 @@ public: void end_write(std::string const &); void flush() {}; + void set_length (Temporal::Beats const &); double round_to_file_precision (double val) const;