diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index 719b41e6f3..e54ccfd977 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -1452,9 +1452,14 @@ RouteUI::set_color_from_route () void RouteUI::remove_this_route (bool apply_to_selection) { + if (!_session) { + return; + } + + boost::shared_ptr routes_to_remove(new RouteList); if (apply_to_selection) { TrackSelection& track_selection = ARDOUR_UI::instance()->the_editor().get_selection().tracks; - + for (list::iterator i = track_selection.begin(); i != track_selection.end(); ++i) { RouteUI* t = dynamic_cast (*i); if (t) { @@ -1465,7 +1470,7 @@ RouteUI::remove_this_route (bool apply_to_selection) if( audio_track && audio_track->is_master_track() ) continue; - Glib::signal_idle().connect (sigc::bind (sigc::ptr_fun (&RouteUI::idle_remove_this_route), t)); + routes_to_remove->push_back(t->route() ); } } } else { @@ -1476,8 +1481,10 @@ RouteUI::remove_this_route (bool apply_to_selection) if( audio_track && audio_track->is_master_track() ) return; - Glib::signal_idle().connect (sigc::bind (sigc::ptr_fun (&RouteUI::idle_remove_this_route), this)); + routes_to_remove->push_back(this->route() ); } + + Glib::signal_idle().connect (sigc::bind (sigc::ptr_fun (&RouteUI::idle_remove_routes), ARDOUR_UI::instance()->the_session(), routes_to_remove) ); } gint @@ -1487,6 +1494,13 @@ RouteUI::idle_remove_this_route (RouteUI *rui) return false; } +gint +RouteUI::idle_remove_routes (Session* sess, boost::shared_ptr& rlist) +{ + sess->remove_routes (rlist); + return false; +} + /** @return true if this name should be used for the route, otherwise false */ bool RouteUI::verify_new_route_name (const std::string& name) diff --git a/gtk2_ardour/route_ui.h b/gtk2_ardour/route_ui.h index 3ed7cdaacc..6f629c969c 100644 --- a/gtk2_ardour/route_ui.h +++ b/gtk2_ardour/route_ui.h @@ -214,6 +214,7 @@ class RouteUI : public Gtk::EventBox, public WavesUI, public virtual AxisView void remove_this_route (bool apply_to_selection = false); static gint idle_remove_this_route (RouteUI *); + static gint idle_remove_routes (ARDOUR::Session*, boost::shared_ptr &); void route_rename(); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index d66250ebb3..24fc447267 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -3137,22 +3137,6 @@ Session::remove_routes (boost::shared_ptr routes_to_remove) _step_editors--; } } - - /* try to cause everyone to drop their references - * and unregister ports from the backend - */ - for (size_t i = 0; i < (*iter)->input()->ports().num_ports(); ++i) { - _engine.unregister_port((*iter)->input()->ports().port(i)); - PortEngine::PortHandle handle = (*iter)->input()->ports().port(i)->port_handle(); - _engine.current_backend()->unregister_port(handle); - } - - for (size_t i = 0; i < (*iter)->output()->ports().num_ports(); ++i) { - _engine.unregister_port((*iter)->output()->ports().port(i)); - PortEngine::PortHandle handle = (*iter)->output()->ports().port(i)->port_handle(); - _engine.current_backend()->unregister_port(handle); - } - (*iter)->drop_references (); } @@ -3182,6 +3166,25 @@ Session::remove_routes (boost::shared_ptr routes_to_remove) routes.flush (); + /* try to cause everyone to drop their references + * and unregister ports from the backend + */ + for (RouteList::iterator iter = routes_to_remove->begin(); iter != routes_to_remove->end(); ++iter) { + + for (size_t i = 0; i < (*iter)->input()->ports().num_ports(); ++i) { + _engine.unregister_port((*iter)->input()->ports().port(i)); + PortEngine::PortHandle handle = (*iter)->input()->ports().port(i)->port_handle(); + _engine.current_backend()->unregister_port(handle); + } + + for (size_t i = 0; i < (*iter)->output()->ports().num_ports(); ++i) { + _engine.unregister_port((*iter)->output()->ports().port(i)); + PortEngine::PortHandle handle = (*iter)->output()->ports().port(i)->port_handle(); + _engine.current_backend()->unregister_port(handle); + } + (*iter)->drop_references (); + } + Route::RemoteControlIDChange(); /* EMIT SIGNAL */ /* save the new state of the world */