give MIDIRegion a tempo/meter based on their SMF or the SMF standard (120, 4/4)

This commit is contained in:
Paul Davis
2025-08-08 22:26:04 -06:00
parent cec3db54f0
commit be913373cb
2 changed files with 24 additions and 0 deletions

View File

@@ -157,6 +157,8 @@ class LIBARDOUR_API MidiRegion : public Region
void model_shifted (timecnt_t qn_distance);
void model_automation_state_changed (Evoral::Parameter const &);
void set_tempo_stuff_from_source ();
std::set<Evoral::Parameter> _filtered_parameters; ///< parameters that we ask our source not to return when reading
PBD::ScopedConnection _model_connection;
PBD::ScopedConnection _model_shift_connection;

View File

@@ -70,6 +70,8 @@ MidiRegion::MidiRegion (const SourceList& srcs)
: Region (srcs)
, _ignore_shift (false)
{
set_tempo_stuff_from_source ();
/* by default MIDI regions are transparent,
* this should probably be set depending on use-case,
* (eg. loop recording, vs copy/edit/paste)
@@ -106,6 +108,26 @@ MidiRegion::~MidiRegion ()
{
}
void
MidiRegion::set_tempo_stuff_from_source ()
{
std::shared_ptr<Evoral::SMF> smf = std::dynamic_pointer_cast<Evoral::SMF> (midi_source ());
assert (smf);
bool provided;
Temporal::TempoMap::SharedPtr new_map (smf->tempo_map (provided));
if (!provided) {
new_map.reset (new Temporal::TempoMap());
}
Temporal::TempoPoint const tp (new_map->tempo_at (start()));
Temporal::MeterPoint const mp (new_map->meter_at (start()));
_tempo = tp;
_meter = mp;
}
/** Export the MIDI data of the MidiRegion to a new MIDI file (SMF).
*/
bool