13
0

Significantly speed up display of MIDI file information (again)

This regressed with changes to SMFSource to unconditionally load
the model. "Black MIDI Trilogy 2" now shows again in under 4 sec.
Before this change it took roughly 3 mins (!) and the UI was marked
as unresponsive.
This commit is contained in:
Robin Gareus 2022-09-25 03:29:42 +02:00
parent 5d9fc950c5
commit 97b3aef0fa
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -338,14 +338,11 @@ SoundFileBox::setup_labels (const string& filename)
if (SMFSource::valid_midi_file (path)) { if (SMFSource::valid_midi_file (path)) {
boost::shared_ptr<SMFSource> ms; bool err = false;
try { Evoral::SMF smf;
ms = boost::dynamic_pointer_cast<SMFSource> ( if (smf.open (path)) {
SourceFactory::createExternal (DataType::MIDI, *_session, error << string_compose(_("Could not read file: %1."), path) << endmsg;
path, 0, Source::Flag (0), false)); err = true;
} catch (const std::exception& e) {
error << string_compose(_("Could not read file: %1 (%2)."),
path, e.what()) << endmsg;
} }
preview_label.set_markup (_("<b>Midi File Information</b>")); preview_label.set_markup (_("<b>Midi File Information</b>"));
@ -355,20 +352,20 @@ SoundFileBox::setup_labels (const string& filename)
timecode_clock.set (timepos_t ()); timecode_clock.set (timepos_t ());
tags_entry.set_sensitive (false); tags_entry.set_sensitive (false);
if (ms) { if (!err) {
if (ms->smf_format()==0) { if (smf.smf_format()==0) {
format_text.set_text ("MIDI Type 0"); format_text.set_text ("MIDI Type 0");
} else { } else {
format_text.set_text (string_compose("%1 (%2 Tracks)", ms->smf_format()==2 ? "MIDI Type 2" : "MIDI Type 1", ms->num_tracks())); format_text.set_text (string_compose("%1 (%2 Tracks)", smf.smf_format()==2 ? "MIDI Type 2" : "MIDI Type 1", smf.num_tracks()));
} }
channels_value.set_text (ARDOUR_UI_UTILS::midi_channels_as_string (ms->used_channels())); channels_value.set_text (ARDOUR_UI_UTILS::midi_channels_as_string (smf.used_channels()));
length_clock.set_duration (timecnt_t (0)); length_clock.set_duration (timecnt_t (0));
switch (ms->num_tempos()) { switch (smf.num_tempos()) {
case 0: case 0:
tempomap_value.set_text (_("No tempo data")); tempomap_value.set_text (_("No tempo data"));
break; break;
case 1: { case 1: {
Evoral::SMF::Tempo* t = ms->nth_tempo (0); Evoral::SMF::Tempo* t = smf.nth_tempo (0);
assert (t); assert (t);
tempomap_value.set_text (string_compose (_("%1/%2 \u2669 = %3"), tempomap_value.set_text (string_compose (_("%1/%2 \u2669 = %3"),
t->numerator, t->numerator,
@ -378,7 +375,7 @@ SoundFileBox::setup_labels (const string& filename)
} }
default: default:
tempomap_value.set_text (string_compose (_("map with %1 sections"), tempomap_value.set_text (string_compose (_("map with %1 sections"),
ms->num_tempos())); smf.num_tempos()));
break; break;
} }
} else { } else {
@ -387,7 +384,7 @@ SoundFileBox::setup_labels (const string& filename)
tempomap_value.set_text (_("No tempo data")); tempomap_value.set_text (_("No tempo data"));
} }
if (_session && ms) { if (_session && !err) {
play_btn.set_sensitive (true); play_btn.set_sensitive (true);
} else { } else {
play_btn.set_sensitive (false); play_btn.set_sensitive (false);