Fix Duplicate Track with Copy Playlist option selected
authorTim Mayberry <mojofunk@gmail.com>
Mon, 28 Nov 2016 02:30:38 +0000 (12:30 +1000)
committerTim Mayberry <mojofunk@gmail.com>
Mon, 28 Nov 2016 02:38:58 +0000 (12:38 +1000)
Previously two new empty playlists were created.

Related to and mentioned in issue #7141

libs/ardour/session.cc

index 127367483b4a402e2eb31951008fb240a80fae7d..06d19672b9199568096a629d58ad22bb722b2cce 100644 (file)
@@ -81,6 +81,7 @@
 #include "ardour/midi_ui.h"
 #include "ardour/operations.h"
 #include "ardour/playlist.h"
+#include "ardour/playlist_factory.h"
 #include "ardour/plugin.h"
 #include "ardour/plugin_insert.h"
 #include "ardour/process_thread.h"
@@ -3240,17 +3241,19 @@ Session::new_route_from_template (uint32_t how_many, PresentationInfo::order_t i
 
                        /* set this name in the XML description that we are about to use */
 
-                       bool rename_playlist;
-                       switch (pd) {
-                       case NewPlaylist:
-                       case CopyPlaylist:
-                               rename_playlist = true;
-                               break;
-                       default:
-                       case SharePlaylist:
-                               rename_playlist = false;
+                       if (pd == CopyPlaylist) {
+                               XMLNode* ds_node = find_named_node (node_copy, "Diskstream");
+                               if (ds_node) {
+                                       const std::string playlist_name = ds_node->property (X_("playlist"))->value ();
+                                       boost::shared_ptr<Playlist> playlist = playlists->by_name (playlist_name);
+                                       // Use same name as Route::set_name_in_state so playlist copy
+                                       // is picked up when creating the Route in XMLRouteFactory below
+                                       PlaylistFactory::create (playlist, string_compose ("%1.1", name));
+                               }
                        }
 
+                       bool rename_playlist = (pd == CopyPlaylist || pd == NewPlaylist);
+
                        Route::set_name_in_state (node_copy, name, rename_playlist);
 
                        /* trim bitslots from listen sends so that new ones are used */
@@ -3328,20 +3331,6 @@ Session::new_route_from_template (uint32_t how_many, PresentationInfo::order_t i
                                route->output()->changed (change, this);
                        }
 
-                       boost::shared_ptr<Track> track;
-
-                       if ((track = boost::dynamic_pointer_cast<Track> (route))) {
-                               switch (pd) {
-                               case NewPlaylist:
-                                       break;
-                               case CopyPlaylist:
-                                       track->use_copy_playlist ();
-                                       break;
-                               case SharePlaylist:
-                                       break;
-                               }
-                       };
-
                        ret.push_back (route);
                }