import_pt: Look up tracks by name instead of by number
This allows existing tracks with correct names to be the target for import.
This commit is contained in:
parent
4dc4d53004
commit
4620d138ee
|
@ -346,8 +346,6 @@ public:
|
||||||
std::shared_ptr<RouteList> get_routes_with_internal_returns() const;
|
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<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 nstripables (bool with_monitor = false) const;
|
||||||
uint32_t nroutes() const { return routes.reader()->size(); }
|
uint32_t nroutes() const { return routes.reader()->size(); }
|
||||||
uint32_t ntracks () const;
|
uint32_t ntracks () const;
|
||||||
|
|
|
@ -284,10 +284,7 @@ Session::import_pt_rest (PTFFormat& ptf)
|
||||||
SourceList just_one_src;
|
SourceList just_one_src;
|
||||||
|
|
||||||
std::shared_ptr<AudioTrack> existing_track;
|
std::shared_ptr<AudioTrack> existing_track;
|
||||||
uint16_t i;
|
|
||||||
uint16_t nth = 0;
|
uint16_t nth = 0;
|
||||||
uint16_t ntr = 0;
|
|
||||||
uint16_t existing_ntracks = 0;
|
|
||||||
struct ptflookup utr;
|
struct ptflookup utr;
|
||||||
vector<midipair> uniquetr;
|
vector<midipair> uniquetr;
|
||||||
|
|
||||||
|
@ -339,37 +336,31 @@ Session::import_pt_rest (PTFFormat& ptf)
|
||||||
goto no_audio_tracks;
|
goto no_audio_tracks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get current number of ardour tracks */
|
/* Create all PT tracks if not already present and freeze all playlists of tracks we will touch */
|
||||||
existing_ntracks = naudiotracks ();
|
|
||||||
|
|
||||||
/* Create all PT tracks */
|
|
||||||
ntr = (ptf.tracks ().at (ptf.tracks ().size () - 1)).index + 1;
|
|
||||||
nth = -1;
|
nth = -1;
|
||||||
for (vector<PTFFormat::track_t>::const_iterator a = ptf.tracks ().begin (); a != ptf.tracks ().end (); ++a) {
|
for (vector<PTFFormat::track_t>::const_iterator a = ptf.tracks ().begin (); a != ptf.tracks ().end (); ++a) {
|
||||||
if (a->index != nth) {
|
if (a->index != nth) {
|
||||||
nth++;
|
nth++;
|
||||||
DEBUG_TRACE (DEBUG::FileUtils, string_compose ("\tcreate tr(%1) %2\n", nth, a->name.c_str()));
|
if (!(existing_track = dynamic_pointer_cast<AudioTrack> (route_by_name (a->name)))) {
|
||||||
list<std::shared_ptr<AudioTrack> > at (new_audio_track (1, 2, 0, 1, a->name.c_str(), PresentationInfo::max_order, Normal));
|
/* Create missing track */
|
||||||
if (at.empty ()) {
|
DEBUG_TRACE (DEBUG::FileUtils, string_compose ("\tcreate tr(%1) %2\n", nth, a->name.c_str()));
|
||||||
return;
|
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 */
|
/* Add regions */
|
||||||
for (vector<PTFFormat::track_t>::const_iterator a = ptf.tracks ().begin (); a != ptf.tracks ().end (); ++a) {
|
for (vector<PTFFormat::track_t>::const_iterator a = ptf.tracks ().begin (); a != ptf.tracks ().end (); ++a) {
|
||||||
for (vector<struct ptflookup>::iterator p = ptfregpair.begin ();
|
for (vector<struct ptflookup>::iterator p = ptfregpair.begin ();
|
||||||
|
@ -381,8 +372,8 @@ Session::import_pt_rest (PTFFormat& ptf)
|
||||||
std::shared_ptr<Region> r = RegionFactory::region_by_id (p->id);
|
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));
|
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 */
|
/* Use audio track we know exists */
|
||||||
existing_track = get_nth_audio_track (a->index + existing_ntracks);
|
existing_track = dynamic_pointer_cast<AudioTrack> (route_by_name (a->name));
|
||||||
assert (existing_track);
|
assert (existing_track);
|
||||||
|
|
||||||
/* Put on existing track */
|
/* Put on existing track */
|
||||||
|
|
|
@ -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>
|
std::shared_ptr<RouteList>
|
||||||
Session::get_tracks () const
|
Session::get_tracks () const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue