2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "ardour_ui.h"
27 #include "audio_time_axis.h"
28 #include "mixer_strip.h"
29 #include "gui_thread.h"
32 #include <ardour/route.h>
33 #include <ardour/audio_track.h>
38 using namespace ARDOUR;
43 Editor::handle_new_route (Session::RouteList& routes)
45 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route), routes));
48 AudioTimeAxisView *atv;
49 TreeModel::Row parent;
52 ignore_route_list_reorder = true;
53 ignore_route_order_sync = true;
54 no_route_list_redisplay = true;
56 for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
57 boost::shared_ptr<Route> route = (*x);
59 if (route->hidden()) {
63 tv = new AudioTimeAxisView (*this, *session, route, track_canvas);
64 cerr << "Editor::handle_new_route() called on " << route->name() << endl;//DEBUG
65 row = *(route_display_model->append ());
67 row[route_display_columns.route] = route;
68 row[route_display_columns.text] = route->name();
69 row[route_display_columns.visible] = tv->marked_for_display();
70 row[route_display_columns.tv] = tv;
72 track_views.push_back (tv);
74 if ((atv = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
75 /* added a new fresh one at the end */
76 if (atv->route()->order_key(N_("editor")) == -1) {
77 atv->route()->set_order_key (N_("editor"), route_display_model->children().size()-1);
81 tv->set_old_order_key (route_display_model->children().size() - 1);
82 route->gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes));
83 tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv));
86 ignore_route_list_reorder = false;
87 ignore_route_order_sync = false;
88 no_route_list_redisplay = false;
90 redisplay_route_list ();
92 if (show_editor_mixer_when_tracks_arrive) {
93 show_editor_mixer (true);
96 editor_mixer_button.set_sensitive(true);
100 Editor::handle_gui_changes (const string & what, void *src)
102 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
104 if (what == "track_height") {
105 redisplay_route_list ();
110 Editor::remove_route (TimeAxisView *tv)
112 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
114 TrackViewList::iterator i;
115 TreeModel::Children rows = route_display_model->children();
116 TreeModel::Children::iterator ri;
118 /* Decrement old order keys for tracks `above' the one that is being removed */
119 for (ri = rows.begin(); ri != rows.end(); ++ri) {
120 TimeAxisView* v = (*ri)[route_display_columns.tv];
121 if (v->old_order_key() > tv->old_order_key()) {
122 v->set_old_order_key (v->old_order_key() - 1);
126 for (ri = rows.begin(); ri != rows.end(); ++ri) {
127 if ((*ri)[route_display_columns.tv] == tv) {
128 route_display_model->erase (ri);
133 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
134 track_views.erase (i);
137 /* since the editor mixer goes away when you remove a route, set the
138 * button to inactive and untick the menu option
141 editor_mixer_button.set_active(false);
142 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
144 /* and disable if all tracks and/or routes are gone */
146 if (track_views.size() == 0) {
147 editor_mixer_button.set_sensitive(false);
152 Editor::route_name_changed (TimeAxisView *tv)
154 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
156 TreeModel::Children rows = route_display_model->children();
157 TreeModel::Children::iterator i;
159 for (i = rows.begin(); i != rows.end(); ++i) {
160 if ((*i)[route_display_columns.tv] == tv) {
161 (*i)[route_display_columns.text] = tv->name();
169 Editor::hide_track_in_display (TimeAxisView& tv)
171 TreeModel::Children rows = route_display_model->children();
172 TreeModel::Children::iterator i;
174 for (i = rows.begin(); i != rows.end(); ++i) {
175 if ((*i)[route_display_columns.tv] == &tv) {
176 (*i)[route_display_columns.visible] = false;
181 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
183 if (atv && current_mixer_strip && (atv->route() == current_mixer_strip->route())) {
184 // this will hide the mixer strip
185 set_selected_mixer_strip (tv);
190 Editor::show_track_in_display (TimeAxisView& tv)
192 TreeModel::Children rows = route_display_model->children();
193 TreeModel::Children::iterator i;
195 for (i = rows.begin(); i != rows.end(); ++i) {
196 if ((*i)[route_display_columns.tv] == &tv) {
197 (*i)[route_display_columns.visible] = true;
198 tv.set_marked_for_display (true);
205 Editor::sync_order_keys ()
207 vector<int> neworder;
208 TreeModel::Children rows = route_display_model->children();
209 TreeModel::Children::iterator ri;
211 if (ignore_route_order_sync || !session || (session->state_of_the_state() & Session::Loading) || rows.empty()) {
215 for (ri = rows.begin(); ri != rows.end(); ++ri) {
216 neworder.push_back (0);
219 for (ri = rows.begin(); ri != rows.end(); ++ri) {
220 TimeAxisView* tv = (*ri)[route_display_columns.tv];
221 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
222 neworder[route->order_key (X_("editor"))] = tv->old_order_key ();
225 ignore_route_list_reorder = true;
226 route_display_model->reorder (neworder);
227 ignore_route_list_reorder = false;
231 Editor::redisplay_route_list ()
233 TreeModel::Children rows = route_display_model->children();
234 TreeModel::Children::iterator i;
239 if (no_route_list_redisplay) {
243 if (session && (rows.size() > session->nroutes())) {
244 /* temporary condition during a drag-n-drop */
248 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
249 TimeAxisView *tv = (*i)[route_display_columns.tv];
250 boost::shared_ptr<Route> route = (*i)[route_display_columns.route];
253 // just a "title" row
257 if (!ignore_route_list_reorder) {
259 /* this reorder is caused by user action, so reassign sort order keys
263 route->set_order_key (N_("editor"), order);
266 tv->set_old_order_key (order);
268 bool visible = (*i)[route_display_columns.visible];
271 tv->set_marked_for_display (true);
272 position += tv->show_at (position, n, &edit_controls_vbox);
281 full_canvas_height = position;
283 /* make sure the cursors stay on top of every newly added track */
285 cursor_group->raise_to_top ();
287 reset_scrolling_region ();
289 if (Config->get_sync_all_route_ordering() && !ignore_route_list_reorder) {
290 ignore_route_order_sync = true;
291 Route::SyncOrderKeys (); // EMIT SIGNAL
292 ignore_route_order_sync = false;
297 Editor::hide_all_tracks (bool with_select)
299 TreeModel::Children rows = route_display_model->children();
300 TreeModel::Children::iterator i;
302 no_route_list_redisplay = true;
304 for (i = rows.begin(); i != rows.end(); ++i) {
306 TreeModel::Row row = (*i);
307 TimeAxisView *tv = row[route_display_columns.tv];
313 row[route_display_columns.visible] = false;
316 no_route_list_redisplay = false;
317 redisplay_route_list ();
319 /* XXX this seems like a hack and half, but its not clear where to put this
323 reset_scrolling_region ();
327 Editor::build_route_list_menu ()
329 using namespace Menu_Helpers;
332 route_list_menu = new Menu;
334 MenuList& items = route_list_menu->items();
335 route_list_menu->set_name ("ArdourContextMenu");
337 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
338 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
339 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
340 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
341 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
342 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
347 Editor::set_all_tracks_visibility (bool yn)
349 TreeModel::Children rows = route_display_model->children();
350 TreeModel::Children::iterator i;
352 no_route_list_redisplay = true;
354 for (i = rows.begin(); i != rows.end(); ++i) {
356 TreeModel::Row row = (*i);
357 TimeAxisView* tv = row[route_display_columns.tv];
363 (*i)[route_display_columns.visible] = yn;
366 no_route_list_redisplay = false;
367 redisplay_route_list ();
371 Editor::set_all_audio_visibility (int tracks, bool yn)
373 TreeModel::Children rows = route_display_model->children();
374 TreeModel::Children::iterator i;
376 no_route_list_redisplay = true;
378 for (i = rows.begin(); i != rows.end(); ++i) {
379 TreeModel::Row row = (*i);
380 TimeAxisView* tv = row[route_display_columns.tv];
381 AudioTimeAxisView* atv;
387 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
390 (*i)[route_display_columns.visible] = yn;
394 if (atv->is_audio_track()) {
395 (*i)[route_display_columns.visible] = yn;
400 if (!atv->is_audio_track()) {
401 (*i)[route_display_columns.visible] = yn;
408 no_route_list_redisplay = false;
409 redisplay_route_list ();
413 Editor::hide_all_routes ()
415 set_all_tracks_visibility (false);
419 Editor::show_all_routes ()
421 set_all_tracks_visibility (true);
425 Editor::show_all_audiobus ()
427 set_all_audio_visibility (2, true);
430 Editor::hide_all_audiobus ()
432 set_all_audio_visibility (2, false);
436 Editor::show_all_audiotracks()
438 set_all_audio_visibility (1, true);
441 Editor::hide_all_audiotracks ()
443 set_all_audio_visibility (1, false);
447 Editor::route_list_display_button_press (GdkEventButton* ev)
449 if (Keyboard::is_context_menu_event (ev)) {
450 show_route_list_menu ();
455 TreeModel::Path path;
456 TreeViewColumn* column;
460 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
464 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
466 if ((iter = route_display_model->get_iter (path))) {
467 TimeAxisView* tv = (*iter)[route_display_columns.tv];
469 bool visible = (*iter)[route_display_columns.visible];
470 (*iter)[route_display_columns.visible] = !visible;
476 /* allow normal processing to occur */
487 Editor::show_route_list_menu()
489 if (route_list_menu == 0) {
490 build_route_list_menu ();
493 route_list_menu->popup (1, gtk_get_current_event_time());
497 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
502 struct EditorOrderRouteSorter {
503 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
504 /* use of ">" forces the correct sort order */
505 return a->order_key ("editor") < b->order_key ("editor");
510 Editor::initial_route_list_display ()
512 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
513 Session::RouteList r (*routes);
514 EditorOrderRouteSorter sorter;
518 no_route_list_redisplay = true;
520 route_display_model->clear ();
522 handle_new_route (r);
524 no_route_list_redisplay = false;
526 redisplay_route_list ();
530 Editor::track_list_reorder (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter, int* new_order)
532 session->set_remote_control_ids();
533 redisplay_route_list ();
537 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
539 session->set_remote_control_ids();
540 redisplay_route_list ();
544 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
546 session->set_remote_control_ids();
547 redisplay_route_list ();