fix incorrect accumulation of export video options each time the dialog is used
[ardour.git] / gtk2_ardour / group_tabs.cc
index 8f076fe84efcb8dd6d79a938c5fe4bffda6f9fe4..f1f8c317fdf434067ffadeddc5241b17c3de2e7a 100644 (file)
@@ -212,7 +212,15 @@ GroupTabs::on_button_release_event (GdkEventButton*)
                                run_new_group_dialog (&routes, false);
                        } else {
                                boost::shared_ptr<RouteList> r = _session->get_routes ();
-                               for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+                               /* First add new ones, then remove old ones.
+                                * We cannot allow the group to become temporarily empty, because
+                                * Session::route_removed_from_route_group() will delete empty groups.
+                                */
+                               for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
+                                       /* RouteGroup::add () ignores routes already present in the set */
+                                       _dragging->group->add (*i);
+                               }
+                               for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
 
                                        bool const was_in_tab = find (
                                                _initial_dragging_routes.begin(), _initial_dragging_routes.end(), *i
@@ -222,10 +230,9 @@ GroupTabs::on_button_release_event (GdkEventButton*)
 
                                        if (was_in_tab && !now_in_tab) {
                                                _dragging->group->remove (*i);
-                                       } else if (!was_in_tab && now_in_tab) {
-                                               _dragging->group->add (*i);
                                        }
                                }
+
                        }
                }
 
@@ -442,7 +449,7 @@ GroupTabs::assign_group_to_master (uint32_t which, RouteGroup* group, bool renam
        boost::shared_ptr<VCA> master;
 
        if (which == 0) {
-               if (_session->vca_manager().create_vca (1)) {
+               if (_session->vca_manager().create_vca (1).empty ()) {
                        /* error */
                        return;
                }
@@ -489,19 +496,21 @@ GroupTabs::unassign_group_to_master (uint32_t which, RouteGroup* group) const
 }
 
 void
-GroupTabs::assign_some_to_master (uint32_t which, RouteList rl)
+GroupTabs::assign_some_to_master (uint32_t which, RouteList rl, std::string vcaname)
 {
        if (!_session) {
                return;
        }
 
        boost::shared_ptr<VCA> master;
+       bool set_name = false;
 
        if (which == 0) {
-               if (_session->vca_manager().create_vca (1)) {
+               if (_session->vca_manager().create_vca (1).empty ()) {
                        /* error */
                        return;
                }
+               set_name = true;
 
                /* Get most recently created VCA... */
                which = _session->vca_manager().vcas().back()->number();
@@ -523,7 +532,10 @@ GroupTabs::assign_some_to_master (uint32_t which, RouteList rl)
        }
 
        for (RouteList::iterator r = rl.begin(); r != rl.end(); ++r) {
-               (*r)->assign (master, false);
+               (*r)->assign (master);
+       }
+       if (set_name && !vcaname.empty()) {
+               master->set_name (vcaname);
        }
 }
 
@@ -552,11 +564,10 @@ GroupTabs::get_rec_enabled ()
 RouteList
 GroupTabs::get_soloed ()
 {
-       boost::shared_ptr<RouteList> rl = _session->get_routes ();
-
+       RouteList rl = _session->get_routelist ();
        RouteList soloed;
 
-       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
+       for (RouteList::iterator i = rl.begin(); i != rl.end(); ++i) {
                if (!(*i)->is_master() && (*i)->soloed()) {
                        soloed.push_back (*i);
                }
@@ -568,7 +579,7 @@ GroupTabs::get_soloed ()
 void
 GroupTabs::assign_selection_to_master (uint32_t which)
 {
-       assign_some_to_master (which, selected_routes ());
+       assign_some_to_master (which, selected_routes (), _("Selection"));
 }
 
 void
@@ -679,20 +690,20 @@ void
 GroupTabs::collect (RouteGroup* g)
 {
        boost::shared_ptr<RouteList> group_routes = g->route_list ();
-       group_routes->sort (Stripable::PresentationOrderSorter());
+       group_routes->sort (Stripable::Sorter());
        int const N = group_routes->size ();
 
        RouteList::iterator i = group_routes->begin ();
-       boost::shared_ptr<RouteList> routes = _session->get_routes ();
-       routes->sort (Stripable::PresentationOrderSorter());
-       RouteList::const_iterator j = routes->begin ();
+       RouteList routes = _session->get_routelist ();
+       routes.sort (Stripable::Sorter());
+       RouteList::const_iterator j = routes.begin ();
 
        int diff = 0;
        int coll = -1;
 
        PresentationInfo::ChangeSuspender cs;
 
-       while (i != group_routes->end() && j != routes->end()) {
+       while (i != group_routes->end() && j != routes.end()) {
 
                PresentationInfo::order_t const k = (*j)->presentation_info ().order();