diff --git a/libs/ardour/import_pt.cc b/libs/ardour/import_pt.cc index 8de4df6129..2744d678ab 100644 --- a/libs/ardour/import_pt.cc +++ b/libs/ardour/import_pt.cc @@ -276,9 +276,27 @@ Session::import_pt_rest (PTFFormat& ptf) SourceList just_one_src; boost::shared_ptr existing_track; + uint16_t i; uint16_t nth = 0; + uint16_t ntr = 0; vector usedtracks; struct ptflookup utr; + vector uniquetr; + + struct PlaylistState { + boost::shared_ptr playlist; + XMLNode* before; + }; + vector playlists; + vector::iterator pl; + + usedtracks.clear(); + just_one_src.clear(); + uniquetr.clear(); + ptfregpair.clear(); + to_import.clear(); + regions.clear(); + playlists.clear(); for (vector::const_iterator a = ptf.regions ().begin (); a != ptf.regions ().end (); ++a) { @@ -314,6 +332,35 @@ Session::import_pt_rest (PTFFormat& ptf) } } + /* Create all tracks */ + ntr = (ptf.tracks ().at (ptf.tracks ().size () - 1)).index + 1; + 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; + } + } + } + + /* Get all playlists of all tracks and Playlist::freeze() all tracks */ + assert (ntr == nth + 1); + for (i = 1; i <= ntr; i++) { + existing_track = get_nth_audio_track (i); + boost::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 (); p != ptfregpair.end (); ++p) { @@ -321,53 +368,23 @@ Session::import_pt_rest (PTFFormat& ptf) if (p->index1 == a->reg.index) { /* Matched a ptf active region to an ardour region */ - utr.index1 = a->index; - utr.index2 = nth; - utr.id = p->id; boost::shared_ptr r = RegionFactory::region_by_id (p->id); - vector::iterator lookuptr = usedtracks.begin (); - vector::iterator found; - if ((found = std::find (lookuptr, usedtracks.end (), utr)) != usedtracks.end ()) { - DEBUG_TRACE (DEBUG::FileUtils, string_compose ("\twav(%1) reg(%2) ptf_tr(%3) ard_tr(%4)\n", a->reg.wave.filename.c_str (), a->reg.index, found->index1, found->index2)); + 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 existing track if possible */ - existing_track = get_nth_audio_track (found->index2 + 1); - if (!existing_track) { - 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 (); - } - /* Put on existing track */ - boost::shared_ptr playlist = existing_track->playlist (); - boost::shared_ptr copy (RegionFactory::create (r, true)); - playlist->clear_changes (); - playlist->add_region (copy, a->reg.startpos); - //add_command (new StatefulDiffCommand (playlist)); - } else { - /* Put on a new track */ - DEBUG_TRACE (DEBUG::FileUtils, string_compose ("\twav(%1) reg(%2) new_tr(%3)\n", a->reg.wave.filename.c_str (), a->reg.index, nth)); - 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 (); - boost::shared_ptr playlist = existing_track->playlist(); - boost::shared_ptr copy (RegionFactory::create (r, true)); - playlist->clear_changes (); - playlist->add_region (copy, a->reg.startpos); - //add_command (new StatefulDiffCommand (playlist)); - nth++; - usedtracks.push_back (utr); - } + /* Use existing playlists */ + boost::shared_ptr playlist = playlists.at (a->index).playlist; + boost::shared_ptr copy (RegionFactory::create (r, true)); + playlist->add_region (copy, a->reg.startpos); } } } - /* MIDI - Find list of unique midi tracks first */ + /* Playlist::thaw() all tracks */ + for (pl = playlists.begin(); pl != playlists.end(); ++pl) { + (*pl).playlist->thaw (); + } - vector uniquetr; + /* MIDI - Find list of unique midi tracks first */ for (vector::const_iterator a = ptf.miditracks ().begin (); a != ptf.miditracks ().end (); ++a) { bool found = false;