+ if (SMFSource::valid_midi_file (path)) {
+
+ boost::shared_ptr<SMFSource> ms;
+ try {
+ ms = boost::dynamic_pointer_cast<SMFSource> (
+ SourceFactory::createExternal (DataType::MIDI, *_session,
+ path, 0, Source::Flag (0), false));
+ } 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>"));
+
+ format_text.set_text ("MIDI");
+ samplerate_value.set_text ("-");
+ tags_entry.get_buffer()->set_text ("");
+ timecode_clock.set (0);
+ tags_entry.set_sensitive (false);
+
+ if (ms) {
+ if (ms->is_type0()) {
+ channels_value.set_text (to_string<uint32_t>(ms->channels().size()));
+ } else {
+ if (ms->num_tracks() > 1) {
+ channels_value.set_text (to_string(ms->num_tracks()) + _("(Tracks)"));
+ } else {
+ channels_value.set_text (to_string(ms->num_tracks()));
+ }
+ }
+ length_clock.set (ms->length(ms->timeline_position()));
+ switch (ms->num_tempos()) {
+ case 0:
+ tempomap_value.set_text (_("No tempo data"));
+ break;
+ case 1: {
+ Evoral::SMF::Tempo* t = ms->nth_tempo (0);
+ assert (t);
+ tempomap_value.set_text (string_compose (_("%1/%2 \u2669 = %3"),
+ t->numerator,
+ t->denominator,
+ t->tempo ()));
+ break;
+ }
+ default:
+ tempomap_value.set_text (string_compose (_("map with %1 sections"),
+ ms->num_tempos()));
+ break;
+ }
+ } else {
+ channels_value.set_text ("");
+ length_clock.set (0);
+ tempomap_value.set_text (_("No tempo data"));
+ }
+
+ if (_session && ms) {
+ play_btn.set_sensitive (true);
+ } else {
+ play_btn.set_sensitive (false);
+ }
+
+ return true;
+ }
+