diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 656bbe8830..4433167948 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -346,8 +346,6 @@ public: std::shared_ptr get_routes_with_internal_returns() const; std::shared_ptr get_routes_with_regions_at (timepos_t const &) const; - std::shared_ptr get_nth_audio_track (uint32_t) const; - uint32_t nstripables (bool with_monitor = false) const; uint32_t nroutes() const { return routes.reader()->size(); } uint32_t ntracks () const; diff --git a/libs/ardour/import_pt.cc b/libs/ardour/import_pt.cc index 0316b475b8..a0a1dd8f0a 100644 --- a/libs/ardour/import_pt.cc +++ b/libs/ardour/import_pt.cc @@ -284,10 +284,7 @@ Session::import_pt_rest (PTFFormat& ptf) SourceList just_one_src; std::shared_ptr existing_track; - uint16_t i; uint16_t nth = 0; - uint16_t ntr = 0; - uint16_t existing_ntracks = 0; struct ptflookup utr; vector uniquetr; @@ -339,37 +336,31 @@ Session::import_pt_rest (PTFFormat& ptf) goto no_audio_tracks; } - /* Get current number of ardour tracks */ - existing_ntracks = naudiotracks (); - - /* Create all PT tracks */ - ntr = (ptf.tracks ().at (ptf.tracks ().size () - 1)).index + 1; + /* Create all PT tracks if not already present and freeze all playlists of tracks we will touch */ nth = -1; for (vector::const_iterator a = ptf.tracks ().begin (); a != ptf.tracks ().end (); ++a) { if (a->index != nth) { nth++; - DEBUG_TRACE (DEBUG::FileUtils, string_compose ("\tcreate tr(%1) %2\n", nth, a->name.c_str())); - list > at (new_audio_track (1, 2, 0, 1, a->name.c_str(), PresentationInfo::max_order, Normal)); - if (at.empty ()) { - return; + if (!(existing_track = dynamic_pointer_cast (route_by_name (a->name)))) { + /* Create missing track */ + DEBUG_TRACE (DEBUG::FileUtils, string_compose ("\tcreate tr(%1) %2\n", nth, a->name.c_str())); + list > at (new_audio_track (1, 2, 0, 1, a->name.c_str(), PresentationInfo::max_order, Normal)); + if (at.empty ()) { + return; + } + existing_track = at.back(); } + std::shared_ptr playlist = existing_track->playlist(); + + PlaylistState before; + before.playlist = playlist; + before.before = &playlist->get_state(); + playlist->clear_changes (); + playlist->freeze (); + playlists.push_back(before); } } - /* Get all playlists of all tracks just created and Playlist::freeze() them */ - assert (ntr == nth + 1); - for (i = 0; i < ntr; ++i) { - existing_track = get_nth_audio_track (i + existing_ntracks); - std::shared_ptr playlist = existing_track->playlist(); - - PlaylistState before; - before.playlist = playlist; - before.before = &playlist->get_state(); - playlist->clear_changes (); - playlist->freeze (); - playlists.push_back(before); - } - /* Add regions */ for (vector::const_iterator a = ptf.tracks ().begin (); a != ptf.tracks ().end (); ++a) { for (vector::iterator p = ptfregpair.begin (); @@ -381,8 +372,8 @@ Session::import_pt_rest (PTFFormat& ptf) std::shared_ptr r = RegionFactory::region_by_id (p->id); DEBUG_TRACE (DEBUG::FileUtils, string_compose ("\twav(%1) reg(%2) tr(%3)\n", a->reg.wave.filename.c_str (), a->reg.index, a->index)); - /* Use track we created earlier */ - existing_track = get_nth_audio_track (a->index + existing_ntracks); + /* Use audio track we know exists */ + existing_track = dynamic_pointer_cast (route_by_name (a->name)); assert (existing_track); /* Put on existing track */ diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 1a37109af4..8a63e451ae 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -6403,24 +6403,6 @@ Session::route_removed_from_route_group (RouteGroup* rg, std::weak_ptr r) } } -std::shared_ptr -Session::get_nth_audio_track (uint32_t nth) const -{ - RouteList rl (*(routes.reader ())); - rl.sort (Stripable::Sorter()); - - for (auto const& r: rl) { - std::shared_ptr at = std::dynamic_pointer_cast (r); - if (!at) { - continue; - } - if (nth-- == 0) { - return at; - } - } - return std::shared_ptr (); -} - std::shared_ptr Session::get_tracks () const {