From 40b0b216de9df7a23cd2bbc7e257833db40cc877 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 4 Jul 2009 13:44:01 +0000 Subject: [PATCH] Add option to collect a route group, so that its member routes are reordered to be together in the editor. A few cleanups along the way. git-svn-id: svn://localhost/ardour2/branches/3.0@5319 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.cc | 3 +- gtk2_ardour/editor_route_groups.cc | 48 ++++++++++++++++++++++++++++++ gtk2_ardour/editor_route_groups.h | 5 ++-- gtk2_ardour/editor_routes.cc | 28 ++++++++++------- gtk2_ardour/editor_routes.h | 6 ++-- libs/ardour/ardour/route_group.h | 1 - libs/ardour/route.cc | 4 +++ 7 files changed, 78 insertions(+), 17 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 16f0f0ae53..da1385bbe7 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -1175,8 +1175,6 @@ Editor::connect_to_session (Session *t) //tempo_map_changed (Change (0)); session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); - _routes->initial_display (); - for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { (static_cast(*i))->set_samples_per_unit (frames_per_unit); } @@ -1203,6 +1201,7 @@ Editor::connect_to_session (Session *t) _route_groups->connect_to_session (session); _regions->connect_to_session (session); _snapshots->connect_to_session (session); + _routes->connect_to_session (session); start_updating (); } diff --git a/gtk2_ardour/editor_route_groups.cc b/gtk2_ardour/editor_route_groups.cc index a9abf4889d..b459168dcb 100644 --- a/gtk2_ardour/editor_route_groups.cc +++ b/gtk2_ardour/editor_route_groups.cc @@ -187,6 +187,7 @@ EditorRouteGroups::menu (RouteGroup* g) items.push_back (MenuElem (_("Edit..."), bind (mem_fun (*this, &EditorRouteGroups::edit), g))); items.push_back (MenuElem (_("Fit to Window"), bind (mem_fun (*_editor, &Editor::fit_route_group), g))); items.push_back (MenuElem (_("Subgroup"), bind (mem_fun (*this, &EditorRouteGroups::subgroup), g))); + items.push_back (MenuElem (_("Collect"), bind (mem_fun (*this, &EditorRouteGroups::collect), g))); } items.push_back (SeparatorElem()); items.push_back (MenuElem (_("Activate All"), mem_fun(*this, &EditorRouteGroups::activate_all))); @@ -665,4 +666,51 @@ EditorRouteGroups::connect_to_session (Session* s) groups_changed (); } +/** Collect all members of a RouteGroup so that they are together in the Editor. + * @param g Group to collect. + */ +void +EditorRouteGroups::collect (RouteGroup* g) +{ + list routes = g->route_list (); + int const N = routes.size (); + list::iterator i = routes.begin (); + Editor::TrackViewList::const_iterator j = _editor->get_track_views().begin(); + + int diff = 0; + int coll = -1; + while (i != routes.end() && j != _editor->get_track_views().end()) { + + RouteTimeAxisView* rtv = dynamic_cast (*j); + if (rtv) { + + boost::shared_ptr r = rtv->route (); + int const k = r->order_key (N_ ("editor")); + + if (*i == r.get()) { + + if (coll == -1) { + coll = k; + diff = N - 1; + } else { + --diff; + } + + r->set_order_key (N_ ("editor"), coll); + + ++coll; + ++i; + + } else { + + r->set_order_key (N_ ("editor"), k + diff); + + } + } + + ++j; + } + + _editor->_routes->sync_order_keys (N_ ("editor")); +} diff --git a/gtk2_ardour/editor_route_groups.h b/gtk2_ardour/editor_route_groups.h index 02d5bac59c..d87c8f5c83 100644 --- a/gtk2_ardour/editor_route_groups.h +++ b/gtk2_ardour/editor_route_groups.h @@ -65,8 +65,9 @@ private: void activate_all (); void disable_all (); - void subgroup (ARDOUR::RouteGroup*); - void unsubgroup (ARDOUR::RouteGroup*); + void subgroup (ARDOUR::RouteGroup *); + void unsubgroup (ARDOUR::RouteGroup *); + void collect (ARDOUR::RouteGroup *); void row_change (const Gtk::TreeModel::Path&,const Gtk::TreeModel::iterator&); void name_edit (const Glib::ustring&, const Glib::ustring&); diff --git a/gtk2_ardour/editor_routes.cc b/gtk2_ardour/editor_routes.cc index 161d8c61fb..46fd4548b3 100644 --- a/gtk2_ardour/editor_routes.cc +++ b/gtk2_ardour/editor_routes.cc @@ -108,6 +108,14 @@ EditorRoutes::EditorRoutes (Editor* e) Route::SyncOrderKeys.connect (mem_fun (*this, &EditorRoutes::sync_order_keys)); } +void +EditorRoutes::connect_to_session (Session* s) +{ + EditorComponent::connect_to_session (s); + + initial_display (); +} + void EditorRoutes::on_tv_rec_enable_toggled (Glib::ustring const & path_string) { @@ -216,7 +224,7 @@ EditorRoutes::redisplay () } if (!_redisplay_does_not_reset_order_keys && !_redisplay_does_not_sync_order_keys) { - _editor->current_session()->sync_order_keys (N_ ("editor")); + _session->sync_order_keys (N_ ("editor")); } } @@ -224,7 +232,7 @@ void EditorRoutes::route_deleted (Gtk::TreeModel::Path const & path) { /* this could require an order reset & sync */ - _editor->current_session()->set_remote_control_ids(); + _session->set_remote_control_ids(); _ignore_reorder = true; redisplay (); _ignore_reorder = false; @@ -236,7 +244,7 @@ EditorRoutes::changed (Gtk::TreeModel::Path const & path, Gtk::TreeModel::iterat { /* never reset order keys because of a property change */ _redisplay_does_not_reset_order_keys = true; - _editor->current_session()->set_remote_control_ids(); + _session->set_remote_control_ids(); redisplay (); _redisplay_does_not_reset_order_keys = false; } @@ -398,7 +406,9 @@ EditorRoutes::reordered (TreeModel::Path const & path, TreeModel::iterator const redisplay (); } - +/** If src == "editor", take editor order keys from each route and use them to rearrange the + * route list so that the visual arrangement of routes matches the order keys from the routes. + */ void EditorRoutes::sync_order_keys (string const & src) { @@ -406,9 +416,7 @@ EditorRoutes::sync_order_keys (string const & src) TreeModel::Children rows = _model->children(); TreeModel::Children::iterator ri; - ARDOUR::Session* s = _editor->current_session (); - - if (src != N_ ("editor") || !s || (s->state_of_the_state() & Session::Loading) || rows.empty()) { + if (src != N_ ("editor") || !_session || (_session->state_of_the_state() & Session::Loading) || rows.empty()) { return; } @@ -627,7 +635,7 @@ struct EditorOrderRouteSorter { void EditorRoutes::initial_display () { - boost::shared_ptr routes = _editor->current_session()->get_routes(); + boost::shared_ptr routes = _session->get_routes(); RouteList r (*routes); EditorOrderRouteSorter sorter; @@ -669,7 +677,7 @@ void EditorRoutes::track_list_reorder (Gtk::TreeModel::Path const & path, Gtk::TreeModel::iterator const & iter, int* new_order) { _redisplay_does_not_sync_order_keys = true; - _editor->current_session()->set_remote_control_ids(); + _session->set_remote_control_ids(); redisplay (); _redisplay_does_not_sync_order_keys = false; } @@ -797,7 +805,7 @@ EditorRoutes::move_selected_tracks (bool up) _model->reorder (neworder); - _editor->current_session()->sync_order_keys (N_ ("editor")); + _session->sync_order_keys (N_ ("editor")); } void diff --git a/gtk2_ardour/editor_routes.h b/gtk2_ardour/editor_routes.h index f416f8f195..a075902dee 100644 --- a/gtk2_ardour/editor_routes.h +++ b/gtk2_ardour/editor_routes.h @@ -22,12 +22,13 @@ class EditorRoutes : public EditorComponent public: EditorRoutes (Editor *); + void connect_to_session (ARDOUR::Session *); + Gtk::Widget& widget () { return _scroller; } void move_selected_tracks (bool); - void initial_display (); void show_track_in_display (TimeAxisView &); void suspend_redisplay () { _no_redisplay = true; @@ -43,9 +44,11 @@ public: std::list views () const; void hide_all_tracks (bool); void clear (); + void sync_order_keys (std::string const &); private: + void initial_display (); void on_tv_rec_enable_toggled (Glib::ustring const &); void build_menu (); void show_menu (); @@ -54,7 +57,6 @@ private: void reordered (Gtk::TreeModel::Path const &, Gtk::TreeModel::iterator const &, int *); bool button_press (GdkEventButton *); void route_name_changed (boost::weak_ptr); - void sync_order_keys (std::string const &); void route_removed (TimeAxisView *); void handle_gui_changes (std::string const &, void *); void update_rec_display (); diff --git a/libs/ardour/ardour/route_group.h b/libs/ardour/ardour/route_group.h index 7b7166decd..75f5af790e 100644 --- a/libs/ardour/ardour/route_group.h +++ b/libs/ardour/ardour/route_group.h @@ -66,7 +66,6 @@ public: gain_t get_min_factor(gain_t factor); int size() { return routes.size();} - ARDOUR::Route * first () const { return *routes.begin();} void set_active (bool yn, void *src); void set_relative (bool yn, void *src); diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index af1a7217d0..61f975689c 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -204,6 +204,10 @@ Route::set_order_key (std::string const & name, long n) _session.set_dirty (); } +/** Set all order keys to be the same as that for `base', if such a key + * exists in this route. + * @param base Base key. + */ void Route::sync_order_keys (std::string const & base) {