Skip to content

Commit

Permalink
import_pt: Look up tracks by name instead of by number
Browse files Browse the repository at this point in the history
This allows existing tracks with correct names to be the target for import.
  • Loading branch information
zamaudio committed Apr 22, 2023
1 parent 4dc4d53 commit 4620d13
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 48 deletions.
2 changes: 0 additions & 2 deletions libs/ardour/ardour/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
std::shared_ptr<RouteList> get_routes_with_internal_returns() const;
std::shared_ptr<RouteList> get_routes_with_regions_at (timepos_t const &) const;

std::shared_ptr<AudioTrack> 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;
Expand Down
47 changes: 19 additions & 28 deletions libs/ardour/import_pt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,7 @@ Session::import_pt_rest (PTFFormat& ptf)
SourceList just_one_src;

std::shared_ptr<AudioTrack> existing_track;
uint16_t i;
uint16_t nth = 0;
uint16_t ntr = 0;
uint16_t existing_ntracks = 0;
struct ptflookup utr;
vector<midipair> uniquetr;

Expand Down Expand Up @@ -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<PTFFormat::track_t>::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<std::shared_ptr<AudioTrack> > 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<AudioTrack> (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<std::shared_ptr<AudioTrack> > 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> 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> 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<PTFFormat::track_t>::const_iterator a = ptf.tracks ().begin (); a != ptf.tracks ().end (); ++a) {
for (vector<struct ptflookup>::iterator p = ptfregpair.begin ();
Expand All @@ -381,8 +372,8 @@ Session::import_pt_rest (PTFFormat& ptf)
std::shared_ptr<Region> 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<AudioTrack> (route_by_name (a->name));
assert (existing_track);

/* Put on existing track */
Expand Down
18 changes: 0 additions & 18 deletions libs/ardour/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6403,24 +6403,6 @@ Session::route_removed_from_route_group (RouteGroup* rg, std::weak_ptr<Route> r)
}
}

std::shared_ptr<AudioTrack>
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<AudioTrack> at = std::dynamic_pointer_cast<AudioTrack> (r);
if (!at) {
continue;
}
if (nth-- == 0) {
return at;
}
}
return std::shared_ptr<AudioTrack> ();
}

std::shared_ptr<RouteList>
Session::get_tracks () const
{
Expand Down

0 comments on commit 4620d13

Please sign in to comment.