fix #5424: routes created from templates do not get names based on the user-supplied...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 2 Apr 2013 00:45:57 +0000 (20:45 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 2 Apr 2013 00:45:57 +0000 (20:45 -0400)
gtk2_ardour/add_route_dialog.cc
gtk2_ardour/add_route_dialog.h
gtk2_ardour/ardour_ui.cc
libs/ardour/ardour/session.h
libs/ardour/session.cc

index 487d65a19c42329af2f301ba09742fbd382d0e9d..f5f4c62dac0b5ed413caa19b7bed677e2b0ce24a 100644 (file)
@@ -288,11 +288,26 @@ AddRouteDialog::track_type_chosen ()
 
 
 string
-AddRouteDialog::name_template ()
+AddRouteDialog::name_template () const
 {
        return name_template_entry.get_text ();
 }
 
+bool
+AddRouteDialog::name_template_is_default() const
+{
+       string n = name_template();
+
+       if (n == _("Audio") ||
+           n == _("MIDI") ||
+           n == _("Audio+MIDI") ||
+           n == _("Bus")) {
+               return true;
+       }
+
+       return false;
+}
+
 int
 AddRouteDialog::count ()
 {
index f2e2168f14ef2e72fc7fa08bbc1d883b5004fd0d..6fe726645238da0ffe19a9076be0127519dd1d7c 100644 (file)
@@ -59,7 +59,8 @@ class AddRouteDialog : public ArdourDialog
         ARDOUR::ChanCount channels ();
        int count ();
 
-       std::string name_template ();
+        std::string name_template () const;
+        bool name_template_is_default () const;
        std::string track_template ();
        ARDOUR::PluginInfoPtr requested_instrument ();
        
index bba740ae25a009bcafea3d6f78d1f9a8a713211a..f21817c29d269ca1dc28faa4d5c4291a7dbc410b 100644 (file)
@@ -3297,7 +3297,11 @@ ARDOUR_UI::add_route (Gtk::Window* float_window)
        string template_path = add_route_dialog->track_template();
 
        if (!template_path.empty()) {
-               _session->new_route_from_template (count, template_path);
+               if (add_route_dialog->name_template_is_default())  {
+                       _session->new_route_from_template (count, template_path, string());
+               } else {
+                       _session->new_route_from_template (count, template_path, add_route_dialog->name_template());
+               }
                return;
        }
 
index f0a2fd118921c29a1ee1b38a89eef4ba4c612428..525faa4e133176d51f79f56d6ec7d15c67f2e93d 100644 (file)
@@ -195,7 +195,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        std::string new_audio_source_name (const std::string&, uint32_t nchans, uint32_t chan, bool destructive);
        std::string new_midi_source_name (const std::string&);
        std::string new_source_path_from_name (DataType type, const std::string&);
-       RouteList new_route_from_template (uint32_t how_many, const std::string& template_path);
+        RouteList new_route_from_template (uint32_t how_many, const std::string& template_path, const std::string& name);
 
        void process (pframes_t nframes);
 
index 0e03efa9458d7bae99dfae688edbb9b1d1d59685..da1f9e9115e6665b44220a467d78bcd9d40b8fa5 100644 (file)
@@ -1598,7 +1598,7 @@ Session::find_route_name (string const & base, uint32_t& id, char* name, size_t
                }
 
                ++id;
-
+               
        } while (id < (UINT_MAX-1));
 
        return false;
@@ -2037,12 +2037,13 @@ 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)
+Session::new_route_from_template (uint32_t how_many, const std::string& template_path, const std::string& name_base)
 {
        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;
@@ -2062,13 +2063,29 @@ Session::new_route_from_template (uint32_t how_many, const std::string& template
                node_copy.remove_property_recursively (X_("id"));
 
                try {
-                       string const route_name = node_copy.property(X_("name"))->value ();
-                       
-                       /* generate a new name by adding a number to the end of the template name */
                        char name[32];
-                       if (!find_route_name (route_name.c_str(), ++number, name, sizeof(name), true)) {
-                               fatal << _("Session: UINT_MAX routes? impossible!") << endmsg;
-                               /*NOTREACHED*/
+
+                       if (!name_base.empty()) {
+
+                               /* if we're adding more than one routes, force
+                                * all the names of the new routes to be
+                                * numbered, via the final parameter.
+                                */
+
+                               if (!find_route_name (name_base.c_str(), ++number, name, sizeof(name), (being_added > 1))) {
+                                       fatal << _("Session: UINT_MAX routes? impossible!") << endmsg;
+                                       /*NOTREACHDE*/
+                               }
+
+                       } else {
+
+                               string const route_name  = node_copy.property(X_("name"))->value ();
+                       
+                               /* generate a new name by adding a number to the end of the template name */
+                               if (!find_route_name (route_name.c_str(), ++number, name, sizeof(name), true)) {
+                                       fatal << _("Session: UINT_MAX routes? impossible!") << endmsg;
+                                       /*NOTREACHED*/
+                               }
                        }
 
                        /* set this name in the XML description that we are about to use */