From b6925e274f3cdec66040cbef50740be221efd0b4 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 13 Nov 2015 16:14:09 -0500 Subject: [PATCH] substantial part of infrastructure required for track/bus duplication This includes removing the removal of ID values in XML, and its replacement with thread-local forcing of ID resets, implemented in a previous commit --- libs/ardour/ardour/route.h | 2 +- libs/ardour/ardour/session.h | 3 ++- libs/ardour/ardour/types.h | 6 +++++ libs/ardour/diskstream.cc | 1 - libs/ardour/route.cc | 6 +++-- libs/ardour/session.cc | 48 +++++++++++++++++++++++++----------- 6 files changed, 47 insertions(+), 19 deletions(-) diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h index 7e428ed6e2..31c8b09cec 100644 --- a/libs/ardour/ardour/route.h +++ b/libs/ardour/ardour/route.h @@ -101,7 +101,7 @@ class LIBARDOUR_API Route : public SessionObject, public Automatable, public Rou void set_comment (std::string str, void *src); bool set_name (const std::string& str); - static void set_name_in_state (XMLNode &, const std::string &); + static void set_name_in_state (XMLNode &, const std::string &, bool rename_playlist = true); uint32_t order_key () const; bool has_order_key () const; diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 0a2cb786ce..ada8d1ab9c 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -218,7 +218,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop std::string new_audio_source_path_for_embedded (const std::string& existing_path); std::string new_audio_source_path (const std::string&, uint32_t nchans, uint32_t chan, bool destructive, bool take_required); std::string new_midi_source_path (const std::string&); - RouteList new_route_from_template (uint32_t how_many, const std::string& template_path, const std::string& name); + RouteList new_route_from_template (uint32_t how_many, const std::string& template_path, const std::string& name, PlaylistDisposition pd = NewPlaylist); + RouteList new_route_from_template (uint32_t how_many, XMLNode&, const std::string& name, PlaylistDisposition pd = NewPlaylist); std::vector get_paths_for_new_sources (bool allow_replacing, const std::string& import_file_path, uint32_t channels); int bring_all_sources_into_session (boost::function callback); diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index 4ad1391abe..1a17c01f86 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -647,6 +647,12 @@ namespace ARDOUR { RegionSelectionStart = 0x8, }; + enum PlaylistDisposition { + CopyPlaylist, + NewPlaylist, + SharePlaylist + }; + } // namespace ARDOUR diff --git a/libs/ardour/diskstream.cc b/libs/ardour/diskstream.cc index fda55c29e9..7f4214037d 100644 --- a/libs/ardour/diskstream.cc +++ b/libs/ardour/diskstream.cc @@ -864,4 +864,3 @@ Diskstream::get_buffering_presets (BufferingPreset bp, return true; } - diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 65f4531ac8..babec9ea74 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -4172,7 +4172,7 @@ Route::set_name (const string& str) * @param name New name. */ void -Route::set_name_in_state (XMLNode& node, string const & name) +Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist) { node.add_property (X_("name"), name); @@ -4192,7 +4192,9 @@ Route::set_name_in_state (XMLNode& node, string const & name) } else if ((*i)->name() == X_("Diskstream")) { - (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str()); + if (rename_playlist) { + (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str()); + } (*i)->add_property (X_("name"), name); } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index f57731b245..36e05e2f3e 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -180,7 +180,7 @@ Session::Session (AudioEngine &eng, , current_block_size (0) , _worst_output_latency (0) , _worst_input_latency (0) - , _worst_track_latency (0) + , _worst_track_latency (0) , _have_captured (false) , _non_soloed_outs_muted (false) , _listen_cnt (0) @@ -3032,30 +3032,39 @@ Session::new_audio_route (int input_channels, int output_channels, RouteGroup* r } RouteList -Session::new_route_from_template (uint32_t how_many, const std::string& template_path, const std::string& name_base) +Session::new_route_from_template (uint32_t how_many, const std::string& template_path, const std::string& name_base, PlaylistDisposition pd) +{ + XMLTree tree; + + if (!tree.read (template_path.c_str())) { + return RouteList(); + } + + return new_route_from_template (how_many, *tree.root(), name_base, pd); +} + +RouteList +Session::new_route_from_template (uint32_t how_many, XMLNode& node, const std::string& name_base, PlaylistDisposition pd) { RouteList ret; uint32_t control_id; - XMLTree tree; uint32_t number = 0; const uint32_t being_added = how_many; - - if (!tree.read (template_path.c_str())) { - return ret; - } - - XMLNode* node = tree.root(); - + /* This will prevent the use of any existing XML-provided PBD::ID + values by Stateful. + */ + Stateful::ForceIDRegeneration force_ids; IO::disable_connecting (); control_id = next_control_id (); while (how_many) { - XMLNode node_copy (*node); + /* We're going to modify the node contents a bit so take a + * copy. The node may be re-used when duplicating more than once. + */ - /* Remove IDs of everything so that new ones are used */ - node_copy.remove_property_recursively (X_("id")); + XMLNode node_copy (node); try { string name; @@ -3084,7 +3093,18 @@ Session::new_route_from_template (uint32_t how_many, const std::string& template } /* set this name in the XML description that we are about to use */ - Route::set_name_in_state (node_copy, name); + + bool rename_playlist; + switch (pd) { + case NewPlaylist: + case CopyPlaylist: + rename_playlist = true; + break; + case SharePlaylist: + rename_playlist = false; + } + + Route::set_name_in_state (node_copy, name, rename_playlist); /* trim bitslots from listen sends so that new ones are used */ XMLNodeList children = node_copy.children ();