fix for most (all? we can dream ...) issues involved in #4399 (editing multiply-appli...
authorPaul Davis <paul@linuxaudiosystems.com>
Sat, 10 Dec 2011 19:20:15 +0000 (19:20 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Sat, 10 Dec 2011 19:20:15 +0000 (19:20 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@10968 d708f5d6-7413-0410-9779-e7cbd77b26cf

19 files changed:
gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_mixer.cc
gtk2_ardour/editor_ops.cc
gtk2_ardour/editor_selection.cc
gtk2_ardour/playlist_selector.cc
gtk2_ardour/time_axis_view.cc
gtk2_ardour/track_view_list.h
libs/ardour/ardour/playlist.h
libs/ardour/ardour/session.h
libs/ardour/ardour/track.h
libs/ardour/audio_diskstream.cc
libs/ardour/audio_track.cc
libs/ardour/diskstream.cc
libs/ardour/midi_diskstream.cc
libs/ardour/playlist.cc
libs/ardour/session.cc
libs/ardour/session_playlists.cc
libs/ardour/track.cc

index e98a63b6a038d39c2f2fe87d66a594f0a22d27e9..28659d077d3c1283f9295f4123bacc07925aff4f 100644 (file)
@@ -4349,15 +4349,10 @@ struct EditorOrderTimeAxisSorter {
 };
 
 void
-Editor::sort_track_selection (TrackViewList* sel)
+Editor::sort_track_selection (TrackViewList& sel)
 {
        EditorOrderTimeAxisSorter cmp;
-
-       if (sel) {
-               sel->sort (cmp);
-       } else {
-               selection->tracks.sort (cmp);
-       }
+       sel.sort (cmp);
 }
 
 framepos_t
index c8d4efd4e8774d9a6b67bb58263c295bc791b3c2..9fa45ba85dac5e5c98d6b6251654a751ac3ab07c 100644 (file)
@@ -632,11 +632,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        CrossfadeView*     clicked_crossfadeview;
        ControlPoint*      clicked_control_point;
 
-       void sort_track_selection (TrackViewList* sel = 0);
+       void sort_track_selection (TrackViewList&);
 
        void get_equivalent_regions (RegionView* rv, std::vector<RegionView*> &, PBD::PropertyID) const;
        RegionSelection get_equivalent_regions (RegionSelection &, PBD::PropertyID) const;
        void mapover_tracks (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
+       void mapover_tracks_with_unique_playlists (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
 
        /* functions to be passed to mapover_tracks(), possibly with sigc::bind()-supplied arguments */
 
index 69f60ad3cf03b23b9bf92c08e9792a1210c210db..12b5ff3f305b7c2a1e02d2fb9993e2d7a635c5f9 100644 (file)
@@ -99,7 +99,7 @@ Editor::show_editor_mixer (bool yn)
                        }
 
                } else {
-                       sort_track_selection ();
+                       sort_track_selection (selection->tracks);
 
                        for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
                                RouteTimeAxisView* atv;
index c598af2453c4fcad2e2f98ee58432a384d8ecff6..738737f46d193f8ebff8a0e428c9d196aab455ed 100644 (file)
@@ -560,11 +560,11 @@ Editor::build_region_boundary_cache ()
 
        TimeAxisView *ontrack = 0;
        TrackViewList tlist;
-
+       
        if (!selection->tracks.empty()) {
-               tlist = selection->tracks;
+               tlist = selection->tracks.filter_to_unique_playlists ();
        } else {
-               tlist = track_views;
+               tlist = track_views.filter_to_unique_playlists ();
        }
 
        while (pos < _session->current_end_frame() && !at_end) {
@@ -2339,9 +2339,10 @@ Editor::create_region_from_selection (vector<boost::shared_ptr<Region> >& new_re
        framepos_t start = selection->time[clicked_selection].start;
        framepos_t end = selection->time[clicked_selection].end;
 
-       sort_track_selection ();
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+       sort_track_selection (ts);
 
-       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+       for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) {
                boost::shared_ptr<Region> current;
                boost::shared_ptr<Playlist> playlist;
                framepos_t internal_start;
@@ -2437,7 +2438,7 @@ Editor::get_tracks_for_range_action () const
                t = selection->tracks;
        }
 
-       return t;
+       return t.filter_to_unique_playlists();
 }
 
 void
@@ -2448,7 +2449,7 @@ Editor::separate_regions_between (const TimeSelection& ts)
        RegionSelection new_selection;
 
        TrackViewList tmptracks = get_tracks_for_range_action ();
-       sort_track_selection (&tmptracks);
+       sort_track_selection (tmptracks);
 
        for (TrackSelection::iterator i = tmptracks.begin(); i != tmptracks.end(); ++i) {
 
@@ -2691,16 +2692,17 @@ Editor::crop_region_to (framepos_t start, framepos_t end)
 {
        vector<boost::shared_ptr<Playlist> > playlists;
        boost::shared_ptr<Playlist> playlist;
-       TrackViewList* ts;
+       TrackViewList ts;
 
        if (selection->tracks.empty()) {
-               ts = &track_views;
+               ts = track_views.filter_to_unique_playlists();
        } else {
-               sort_track_selection ();
-               ts = &selection->tracks;
+               ts = selection->tracks.filter_to_unique_playlists ();
        }
 
-       for (TrackSelection::iterator i = ts->begin(); i != ts->end(); ++i) {
+       sort_track_selection (ts);
+
+       for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) {
 
                RouteTimeAxisView* rtv;
 
@@ -2825,7 +2827,9 @@ Editor::region_fill_selection ()
 
        begin_reversible_command (Operations::fill_selection);
 
-       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+       for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
 
                if ((playlist = (*i)->playlist()) == 0) {
                        continue;
@@ -3513,12 +3517,9 @@ Editor::cut_copy (CutCopyOp op)
 
                /* we only want to cut regions if some are selected */
 
-               if (!selection->regions.empty()) {
-                       rs = selection->regions;
-               }
-
                switch (current_mouse_mode()) {
                case MouseObject:
+                       rs = get_regions_from_selection ();
                        if (!rs.empty() || !selection->points.empty()) {
 
                                begin_reversible_command (opname + _(" objects"));
@@ -3676,23 +3677,15 @@ Editor::remove_selected_regions ()
                        continue;
                }
 
-               vector<boost::shared_ptr<Playlist> >::iterator i;
-
-               //only prep history if this is a new playlist.
-               for (i = playlists.begin(); i != playlists.end(); ++i) {
-                       if ((*i) == playlist) {
-                               break;
-                       }
-               }
-
-               if (i == playlists.end()) {
-
-                       playlist->clear_changes ();
-                       playlist->freeze ();
+               /* get_regions_from_selection_and_entered() guarantees that
+                  the playlists involved are unique, so there is no need
+                  to check here.
+               */
 
-                       playlists.push_back (playlist);
-               }
+               playlists.push_back (playlist);
 
+               playlist->clear_changes ();
+               playlist->freeze ();
                playlist->remove_region (*rl);
        }
 
@@ -3868,27 +3861,24 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs)
 void
 Editor::cut_copy_ranges (CutCopyOp op)
 {
-       TrackViewList* ts;
-       TrackViewList entered;
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
 
        /* Sort the track selection now, so that it if is used, the playlists
           selected by the calls below to cut_copy_clear are in the order that
           their tracks appear in the editor.  This makes things like paste
           of ranges work properly.
        */
-       sort_track_selection (&selection->tracks);
 
-       if (selection->tracks.empty()) {
+       sort_track_selection (ts);
+
+       if (ts.empty()) {
                if (!entered_track) {
                        return;
                }
-               entered.push_back (entered_track);
-               ts = &entered;
-       } else {
-               ts = &selection->tracks;
-       }
+               ts.push_back (entered_track);
+       } 
 
-       for (TrackSelection::iterator i = ts->begin(); i != ts->end(); ++i) {
+       for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
                (*i)->cut_copy_clear (*selection, op);
        }
 }
@@ -3942,8 +3932,8 @@ Editor::paste_internal (framepos_t position, float times)
 
        if (!selection->tracks.empty()) {
                /* there are some selected tracks, so paste to them */
-               sort_track_selection ();
-               ts = selection->tracks;
+               ts = selection->tracks.filter_to_unique_playlists ();
+               sort_track_selection (ts);
        } else if (_last_cut_copy_source_track) {
                /* otherwise paste to the track that the cut/copy came from;
                   see discussion in mantis #3333.
@@ -4048,7 +4038,9 @@ Editor::duplicate_selection (float times)
 
        ri = new_regions.begin();
 
-       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+       for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
                if ((playlist = (*i)->playlist()) == 0) {
                        continue;
                }
@@ -4127,7 +4119,9 @@ Editor::nudge_track (bool use_edit, bool forwards)
 
        begin_reversible_command (_("nudge track"));
 
-       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+       for (TrackViewList::iterator i = ts.begin(); i != ts.end(); ++i) {
 
                if ((playlist = (*i)->playlist()) == 0) {
                        continue;
@@ -5935,7 +5929,12 @@ Editor::tab_to_transient (bool forward)
 
        if (!selection->tracks.empty()) {
 
-               for (TrackSelection::iterator t = selection->tracks.begin(); t != selection->tracks.end(); ++t) {
+               /* don't waste time searching for transients in duplicate playlists.
+                */
+
+               TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+               for (TrackViewList::iterator t = ts.begin(); t != ts.end(); ++t) {
 
                        RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*t);
 
@@ -6212,23 +6211,34 @@ Editor::insert_time (
 
        begin_reversible_command (_("insert time"));
 
-       for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) {
+       TrackViewList ts = selection->tracks.filter_to_unique_playlists ();
+
+       for (TrackViewList::iterator x = ts.begin(); x != ts.end(); ++x) {
 
                /* regions */
 
-               vector<boost::shared_ptr<Playlist> > pl;
+               /* don't operate on any playlist more than once, which could
+                * happen if "all playlists" is enabled, but there is more
+                * than 1 track using playlists "from" a given track.
+                */
+
+               set<boost::shared_ptr<Playlist> > pl;
+
                if (all_playlists) {
                        RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*x);
                        if (rtav) {
-                               pl = _session->playlists->playlists_for_track (rtav->track ());
+                               vector<boost::shared_ptr<Playlist> > all = _session->playlists->playlists_for_track (rtav->track ());
+                               for (vector<boost::shared_ptr<Playlist> >::iterator p = all.begin(); p != all.end(); ++p) {
+                                       pl.insert (*p);
+                               }
                        }
                } else {
                        if ((*x)->playlist ()) {
-                               pl.push_back ((*x)->playlist ());
+                               pl.insert ((*x)->playlist ());
                        }
                }
-
-               for (vector<boost::shared_ptr<Playlist> >::iterator i = pl.begin(); i != pl.end(); ++i) {
+               
+               for (set<boost::shared_ptr<Playlist> >::iterator i = pl.begin(); i != pl.end(); ++i) {
 
                        (*i)->clear_changes ();
                        (*i)->clear_owned_changes ();
index 57db35ccf3ec211acea4283d1c891f6cebac308a..142204f9b4864992404e73146cd8a6db68cd4d85 100644 (file)
@@ -401,6 +401,63 @@ Editor::mapover_tracks (sigc::slot<void, RouteTimeAxisView&, uint32_t> sl, TimeA
        }
 }
 
+/** Call a slot for a given `basis' track and also for any track that is in the same
+ *  active route group with a particular set of properties.
+ *
+ *  @param sl Slot to call.
+ *  @param basis Basis track.
+ *  @param prop Properties that active edit groups must share to be included in the map.
+ */
+
+void
+Editor::mapover_tracks_with_unique_playlists (sigc::slot<void, RouteTimeAxisView&, uint32_t> sl, TimeAxisView* basis, PBD::PropertyID prop) const
+{
+       RouteTimeAxisView* route_basis = dynamic_cast<RouteTimeAxisView*> (basis);
+       set<boost::shared_ptr<Playlist> > playlists;
+
+       if (route_basis == 0) {
+               return;
+       }
+
+       set<RouteTimeAxisView*> tracks;
+       tracks.insert (route_basis);
+
+       RouteGroup* group = route_basis->route()->route_group(); // could be null, not a problem
+
+       if (group && group->enabled_property(prop) && group->enabled_property (Properties::active.property_id) ) {
+
+               /* the basis is a member of an active route group, with the appropriate
+                  properties; find other members */
+
+               for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) {
+                       RouteTimeAxisView* v = dynamic_cast<RouteTimeAxisView*> (*i);
+
+                       if (v && v->route()->route_group() == group) {
+                               
+                               boost::shared_ptr<Track> t = v->track();
+                               if (t) {
+                                       if (playlists.insert (t->playlist()).second) {
+                                               /* haven't seen this playlist yet */
+                                               tracks.insert (v);
+                                       }
+                               } else {
+                                       /* not actually a "Track", but a timeaxis view that
+                                          we should mapover anyway.
+                                       */
+                                       tracks.insert (v);
+                               }
+                       }
+               }
+       }
+
+       /* call the slots */
+       uint32_t const sz = tracks.size ();
+
+       for (set<RouteTimeAxisView*>::iterator i = tracks.begin(); i != tracks.end(); ++i) {
+               sl (**i, sz);
+       }
+}
+
 void
 Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t, RegionView * basis, vector<RegionView*>* all_equivs) const
 {
@@ -433,7 +490,7 @@ Editor::mapped_get_equivalent_regions (RouteTimeAxisView& tv, uint32_t, RegionVi
 void
 Editor::get_equivalent_regions (RegionView* basis, vector<RegionView*>& equivalent_regions, PBD::PropertyID property) const
 {
-       mapover_tracks (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions), &basis->get_time_axis_view(), property);
+       mapover_tracks_with_unique_playlists (sigc::bind (sigc::mem_fun (*this, &Editor::mapped_get_equivalent_regions), basis, &equivalent_regions), &basis->get_time_axis_view(), property);
 
        /* add clicked regionview since we skipped all other regions in the same track as the one it was in */
 
@@ -449,7 +506,7 @@ Editor::get_equivalent_regions (RegionSelection & basis, PBD::PropertyID prop) c
 
                vector<RegionView*> eq;
 
-               mapover_tracks (
+               mapover_tracks_with_unique_playlists (
                        sigc::bind (sigc::mem_fun (*this, &Editor::mapped_get_equivalent_regions), *i, &eq),
                        &(*i)->get_time_axis_view(), prop);
 
index e0c51082a1eeadaa5a19a1859e6893d2f3edec54..f81e199d625b69a7c60c588a67e7bcef845f1007 100644 (file)
@@ -121,6 +121,14 @@ PlaylistSelector::show_for (RouteUI* ruix)
        for (TrackPlaylistMap::iterator x = trpl_map.begin(); x != trpl_map.end(); ++x) {
 
                boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (_session->route_by_id (x->first));
+               
+               /* legacy sessions stored the diskstream ID as the original
+                * playlist owner. so try there instead.
+                */
+
+               if (tr == 0) {
+                       tr = _session->track_by_diskstream_id (x->first);
+               }
 
                if (tr == 0) {
                        continue;
@@ -222,8 +230,8 @@ PlaylistSelector::add_playlist_to_map (boost::shared_ptr<Playlist> pl)
 
        TrackPlaylistMap::iterator x;
 
-       if ((x = trpl_map.find (apl->get_orig_diskstream_id())) == trpl_map.end()) {
-               x = trpl_map.insert (trpl_map.end(), make_pair (apl->get_orig_diskstream_id(), new list<boost::shared_ptr<Playlist> >));
+       if ((x = trpl_map.find (apl->get_orig_track_id())) == trpl_map.end()) {
+               x = trpl_map.insert (trpl_map.end(), make_pair (apl->get_orig_track_id(), new list<boost::shared_ptr<Playlist> >));
        }
 
        x->second->push_back (pl);
index 56dd2b746dc029ba4bb28e4123a4cf980b89dd41..e71bbe4778b5968d1cf60e4b33352e10a1faf1ba 100644 (file)
@@ -1304,3 +1304,30 @@ TimeAxisView::reset_visual_state ()
                set_height (preset_height (HeightNormal));
        }
 }
+
+TrackViewList
+TrackViewList::filter_to_unique_playlists ()
+{
+       std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists;
+       TrackViewList ts;
+
+       for (iterator i = begin(); i != end(); ++i) {
+               RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*i);
+               if (!rtav) {
+                       /* not a route: include it anyway */
+                       ts.push_back (*i);
+               } else {
+                       boost::shared_ptr<ARDOUR::Track> t = rtav->track();
+                       if (t) {
+                               if (playlists.insert (t->playlist()).second) {
+                                       /* playlist not seen yet */
+                                       ts.push_back (*i);
+                               }
+                       } else {
+                               /* not a track: include it anyway */
+                               ts.push_back (*i);
+                       }
+               }
+       }
+       return ts;
+}
index d7b5433edc634e5cbe177b4f50683184ea798a35..24f26465ef3c334676a5f8fc454ba56f23618099 100755 (executable)
@@ -21,6 +21,7 @@
 #define __ardour_gtk_track_view_list_h__
 
 #include <list>
+#include <set>
 
 class TimeAxisView;
 
@@ -34,6 +35,8 @@ public:
 
        virtual TrackViewList add (TrackViewList const &);
        bool contains (TimeAxisView const *) const;
+
+       TrackViewList filter_to_unique_playlists ();
 };
 
 #endif
index 9e15b9cf5d10795f2d283d93eb866a3d12e296ea..529ec25d149b89b376c2cf2340b3de5939951a60 100644 (file)
@@ -201,9 +201,8 @@ public:
        void raise_region_to_top (boost::shared_ptr<Region>);
        void lower_region_to_bottom (boost::shared_ptr<Region>);
 
-       /* XXX: use of diskstream here is a little unfortunate */
-       const PBD::ID& get_orig_diskstream_id () const { return _orig_diskstream_id; }
-       void set_orig_diskstream_id (const PBD::ID& did) { _orig_diskstream_id = did; }
+       const PBD::ID& get_orig_track_id () const { return _orig_track_id; }
+       void set_orig_track_id (const PBD::ID& did) { _orig_track_id = did; }
 
        /* destructive editing */
 
@@ -290,7 +289,7 @@ public:
        bool             in_partition;
        bool            _frozen;
        uint32_t         subcnt;
-       PBD::ID         _orig_diskstream_id;
+       PBD::ID         _orig_track_id;
        uint64_t         layer_op_counter;
        framecnt_t       freeze_length;
        bool             auto_partition;
index 3c1c9b564b4f3f6ae1c2e127af3fab1debdb328a..19935c5440f88849132b8fbfd3a54d91c7e2941e 100644 (file)
@@ -243,6 +243,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        boost::shared_ptr<Route> route_by_name (std::string);
        boost::shared_ptr<Route> route_by_id (PBD::ID);
        boost::shared_ptr<Route> route_by_remote_id (uint32_t id);
+       boost::shared_ptr<Track> track_by_diskstream_id (PBD::ID);
        void routes_using_input_from (const std::string& str, RouteList& rl);
 
        bool route_name_unique (std::string) const;
index 79e968c8ed105411aa3da00d796dc61c685c2296..496b1e195bd3e2fe1cd40772fcbd186a66f02cf0 100644 (file)
@@ -98,8 +98,7 @@ class Track : public Route, public PublicDiskstream
        bool record_enabled() const;
        void set_record_enabled (bool yn, void *src);
 
-       /* XXX: unfortunate that this is exposed */
-       PBD::ID const & diskstream_id () const;
+       bool using_diskstream_id (PBD::ID) const;
 
        void set_block_size (pframes_t);
 
index 51a3b72bf6fc3dc17632ee447aaac4ee1d1f856c..2ab7d9ec6521965f5042f91954b2d5adad8f845d 100644 (file)
@@ -281,7 +281,6 @@ AudioDiskstream::use_new_playlist ()
 
        if ((playlist = boost::dynamic_pointer_cast<AudioPlaylist> (PlaylistFactory::create (DataType::AUDIO, _session, newname, hidden()))) != 0) {
 
-               playlist->set_orig_diskstream_id (id());
                return use_playlist (playlist);
 
        } else {
@@ -309,7 +308,6 @@ AudioDiskstream::use_copy_playlist ()
        newname = Playlist::bump_name (_playlist->name(), _session);
 
        if ((playlist = boost::dynamic_pointer_cast<AudioPlaylist>(PlaylistFactory::create (audio_playlist(), newname))) != 0) {
-               playlist->set_orig_diskstream_id (id());
                return use_playlist (playlist);
        } else {
                return -1;
index c15fcd9e9c8ff73cf5a848a692aea96df489fa06..a8f43c475802846b9e8fd06fbb1b5ad2680b4b82 100644 (file)
@@ -643,7 +643,7 @@ AudioTrack::freeze_me (InterThreadInfo& itt)
 
        boost::shared_ptr<Region> region (RegionFactory::create (srcs, plist, false));
 
-       new_playlist->set_orig_diskstream_id (_diskstream->id());
+       new_playlist->set_orig_track_id (id());
        new_playlist->add_region (region, _session.current_start_frame());
        new_playlist->set_frozen (true);
        region->set_locked (true);
index d5ecd3713bdd63e9d0cb4b78785959e8a59afa29..1cf4048c69e3503c4a2aed250497469f7d20503e 100644 (file)
@@ -504,16 +504,8 @@ Diskstream::set_state (const XMLNode& node, int /*version*/)
                return -1;
        }
 
-       {
-               bool had_playlist = (_playlist != 0);
-
-               if (find_and_use_playlist (prop->value())) {
-                       return -1;
-               }
-
-               if (!had_playlist) {
-                       _playlist->set_orig_diskstream_id (id());
-               }
+       if (find_and_use_playlist (prop->value())) {
+               return -1;
        }
 
        if ((prop = node.property ("speed")) != 0) {
index 4f7778e09e535b693e388ac9f37030ba0732c799..64fcf609258224ad25e3573afc7649c0af0c22ca 100644 (file)
@@ -252,7 +252,6 @@ MidiDiskstream::use_new_playlist ()
        if ((playlist = boost::dynamic_pointer_cast<MidiPlaylist> (PlaylistFactory::create (
                        DataType::MIDI, _session, newname, hidden()))) != 0) {
 
-               playlist->set_orig_diskstream_id (id());
                return use_playlist (playlist);
 
        } else {
@@ -280,7 +279,6 @@ MidiDiskstream::use_copy_playlist ()
        newname = Playlist::bump_name (_playlist->name(), _session);
 
        if ((playlist  = boost::dynamic_pointer_cast<MidiPlaylist>(PlaylistFactory::create (midi_playlist(), newname))) != 0) {
-               playlist->set_orig_diskstream_id (id());
                return use_playlist (playlist);
        } else {
                return -1;
index 3bc5f57577d7349d0647880245adf7d05dfd67d9..4aae95ea761e1e81772379efbd4a8db4a294e516 100644 (file)
@@ -161,7 +161,7 @@ Playlist::Playlist (boost::shared_ptr<const Playlist> other, string namestr, boo
        : SessionObject(other->_session, namestr)
        , regions (*this)
        , _type(other->_type)
-       , _orig_diskstream_id (other->_orig_diskstream_id)
+       , _orig_track_id (other->_orig_track_id)
 {
        init (hide);
 
@@ -195,7 +195,7 @@ Playlist::Playlist (boost::shared_ptr<const Playlist> other, framepos_t start, f
        : SessionObject(other->_session, str)
        , regions (*this)
        , _type(other->_type)
-       , _orig_diskstream_id (other->_orig_diskstream_id)
+       , _orig_track_id (other->_orig_track_id)
 {
        RegionLock rlock2 (const_cast<Playlist*> (other.get()));
 
@@ -2221,7 +2221,10 @@ Playlist::flush_notifications (bool from_undo)
                         _name = prop->value();
                         _set_sort_id ();
                 } else if (prop->name() == X_("orig-diskstream-id")) {
-                        _orig_diskstream_id = prop->value ();
+                        /* XXX legacy session: fix up later */
+                        _orig_track_id = prop->value ();
+                } else if (prop->name() == X_("orig-track-id")) {
+                        _orig_track_id = prop->value ();
                 } else if (prop->name() == X_("frozen")) {
                         _frozen = string_is_affirmative (prop->value());
                 } else if (prop->name() == X_("combine-ops")) {
@@ -2318,8 +2321,8 @@ Playlist::state (bool full_state)
        node->add_property (X_("name"), _name);
        node->add_property (X_("type"), _type.to_string());
 
-       _orig_diskstream_id.print (buf, sizeof (buf));
-       node->add_property (X_("orig-diskstream-id"), buf);
+       _orig_track_id.print (buf, sizeof (buf));
+       node->add_property (X_("orig-track-id"), buf);
        node->add_property (X_("frozen"), _frozen ? "yes" : "no");
 
        if (full_state) {
index 4f5e8093bb3a732d92e3a9a0d1ec073ed6913c6d..f2e224fee55887edabd1180406d8ce9d82d82556 100644 (file)
@@ -2603,6 +2603,21 @@ Session::route_by_id (PBD::ID id)
        return boost::shared_ptr<Route> ((Route*) 0);
 }
 
+boost::shared_ptr<Track>
+Session::track_by_diskstream_id (PBD::ID id)
+{
+       boost::shared_ptr<RouteList> r = routes.reader ();
+
+       for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+               boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track> (*i);
+               if (t && t->using_diskstream_id (id)) {
+                       return t;
+               }
+       }
+
+       return boost::shared_ptr<Track> ();
+}
+
 boost::shared_ptr<Route>
 Session::route_by_remote_id (uint32_t id)
 {
index 1e31801271ee8955a8046272fee6e67c4bfb4bf9..8e25cbfd9d737866bdaeeefdaee804c25fa97ddc 100644 (file)
@@ -207,13 +207,13 @@ SessionPlaylists::unassigned (std::list<boost::shared_ptr<Playlist> > & list)
        Glib::Mutex::Lock lm (lock);
 
        for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) {
-               if (!(*i)->get_orig_diskstream_id().to_s().compare ("0")) {
+               if (!(*i)->get_orig_track_id().to_s().compare ("0")) {
                        list.push_back (*i);
                }
        }
 
        for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) {
-               if (!(*i)->get_orig_diskstream_id().to_s().compare ("0")) {
+               if (!(*i)->get_orig_track_id().to_s().compare ("0")) {
                        list.push_back (*i);
                }
        }
@@ -462,7 +462,7 @@ SessionPlaylists::playlists_for_track (boost::shared_ptr<Track> tr) const
        vector<boost::shared_ptr<Playlist> > pl_tr;
 
        for (vector<boost::shared_ptr<Playlist> >::iterator i = pl.begin(); i != pl.end(); ++i) {
-               if (((*i)->get_orig_diskstream_id() == tr->diskstream_id()) || (tr->playlist()->id() == (*i)->id())) {
+               if (((*i)->get_orig_track_id() == tr->id()) || (tr->playlist()->id() == (*i)->id())) {
                        pl_tr.push_back (*i);
                }
        }
index 9d6b82e4c0679400e3cfbd6c2d5e5c2c4bc4377e..8a4931d33601275af8c44bea492f55ae0297a311 100644 (file)
@@ -115,6 +115,8 @@ Track::set_state (const XMLNode& node, int version)
                }
        }
 
+       _diskstream->playlist()->set_orig_track_id (id());
+
        /* set rec-enable control *AFTER* setting up diskstream, because it may
           want to operate on the diskstream as it sets its own state
        */
@@ -694,13 +696,25 @@ Track::use_playlist (boost::shared_ptr<Playlist> p)
 int
 Track::use_copy_playlist ()
 {
-       return _diskstream->use_copy_playlist ();
+       int ret =  _diskstream->use_copy_playlist ();
+
+       if (ret == 0) {
+               _diskstream->playlist()->set_orig_track_id (id());
+       }
+
+       return ret;
 }
 
 int
 Track::use_new_playlist ()
 {
-       return _diskstream->use_new_playlist ();
+       int ret = _diskstream->use_new_playlist ();
+
+       if (ret == 0) {
+               _diskstream->playlist()->set_orig_track_id (id());
+       }
+
+       return ret;
 }
 
 void
@@ -715,10 +729,10 @@ Track::set_align_choice (AlignChoice s, bool force)
        _diskstream->set_align_choice (s, force);
 }
 
-PBD::ID const &
-Track::diskstream_id () const
+bool
+Track::using_diskstream_id (PBD::ID id) const
 {
-       return _diskstream->id ();
+       return (id == _diskstream->id ());
 }
 
 void