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;
44 Editor::handle_new_route (Session::RouteList& routes)
46 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route), routes));
49 AudioTimeAxisView *atv;
50 TreeModel::Row parent;
53 ignore_route_list_reorder = true;
54 ignore_route_order_sync = true;
55 no_route_list_redisplay = true;
57 for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
58 boost::shared_ptr<Route> route = (*x);
60 if (route->hidden()) {
64 tv = new AudioTimeAxisView (*this, *session, route, *track_canvas);
65 //cerr << "Editor::handle_new_route() called on " << route->name() << endl;//DEBUG
66 row = *(route_display_model->append ());
68 row[route_display_columns.route] = route;
69 row[route_display_columns.text] = route->name();
70 row[route_display_columns.visible] = tv->marked_for_display();
71 row[route_display_columns.tv] = tv;
73 track_views.push_back (tv);
75 if ((atv = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
76 /* added a new fresh one at the end */
77 if (atv->route()->order_key(N_("editor")) == -1) {
78 atv->route()->set_order_key (N_("editor"), route_display_model->children().size()-1);
80 atv->effective_gain_display ();
83 tv->set_old_order_key (route_display_model->children().size() - 1);
84 route->gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes));
85 tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv));
88 ignore_route_list_reorder = false;
89 ignore_route_order_sync = false;
90 no_route_list_redisplay = false;
92 redisplay_route_list ();
94 if (show_editor_mixer_when_tracks_arrive) {
95 show_editor_mixer (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 /* Optional :make tracks change height while it happens, instead
108 //track_canvas->update_now ();
109 redisplay_route_list ();
112 if (what == "visible_tracks") {
113 redisplay_route_list ();
118 Editor::remove_route (TimeAxisView *tv)
120 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
122 TrackViewList::iterator i;
123 TreeModel::Children rows = route_display_model->children();
124 TreeModel::Children::iterator ri;
126 if (tv == entered_track) {
130 /* Decrement old order keys for tracks `above' the one that is being removed */
131 for (ri = rows.begin(); ri != rows.end(); ++ri) {
132 TimeAxisView* v = (*ri)[route_display_columns.tv];
133 if (v->old_order_key() > tv->old_order_key()) {
134 v->set_old_order_key (v->old_order_key() - 1);
138 for (ri = rows.begin(); ri != rows.end(); ++ri) {
139 if ((*ri)[route_display_columns.tv] == tv) {
140 route_display_model->erase (ri);
145 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
146 track_views.erase (i);
149 /* since the editor mixer goes away when you remove a route, set the
150 * button to inactive and untick the menu option
153 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
157 Editor::route_name_changed (TimeAxisView *tv)
159 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
161 TreeModel::Children rows = route_display_model->children();
162 TreeModel::Children::iterator i;
164 for (i = rows.begin(); i != rows.end(); ++i) {
165 if ((*i)[route_display_columns.tv] == tv) {
166 (*i)[route_display_columns.text] = tv->name();
173 Editor::update_route_visibility ()
175 TreeModel::Children rows = route_display_model->children();
176 TreeModel::Children::iterator i;
178 no_route_list_redisplay = true;
180 for (i = rows.begin(); i != rows.end(); ++i) {
181 TimeAxisView *tv = (*i)[route_display_columns.tv];
182 (*i)[route_display_columns.visible] = tv->marked_for_display ();
185 no_route_list_redisplay = false;
186 redisplay_route_list ();
190 Editor::hide_track_in_display (TimeAxisView& tv, bool temponly)
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] = false;
199 tv.set_marked_for_display (false);
205 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
207 if (atv && current_mixer_strip && (atv->route() == current_mixer_strip->route())) {
208 // this will hide the mixer strip
209 set_selected_mixer_strip (tv);
214 Editor::show_track_in_display (TimeAxisView& tv)
216 TreeModel::Children rows = route_display_model->children();
217 TreeModel::Children::iterator i;
219 for (i = rows.begin(); i != rows.end(); ++i) {
220 if ((*i)[route_display_columns.tv] == &tv) {
221 (*i)[route_display_columns.visible] = true;
222 tv.set_marked_for_display (true);
229 Editor::sync_order_keys ()
231 vector<int> neworder;
232 TreeModel::Children rows = route_display_model->children();
233 TreeModel::Children::iterator ri;
235 if (ignore_route_order_sync || !session || (session->state_of_the_state() & Session::Loading) || rows.empty()) {
239 for (ri = rows.begin(); ri != rows.end(); ++ri) {
240 neworder.push_back (0);
243 for (ri = rows.begin(); ri != rows.end(); ++ri) {
244 TimeAxisView* tv = (*ri)[route_display_columns.tv];
245 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
246 neworder[route->order_key (X_("editor"))] = tv->old_order_key ();
249 ignore_route_list_reorder = true;
250 route_display_model->reorder (neworder);
251 ignore_route_list_reorder = false;
255 Editor::redisplay_route_list ()
257 TreeModel::Children rows = route_display_model->children();
258 TreeModel::Children::iterator i;
263 if (no_route_list_redisplay) {
267 if (session && (rows.size() > session->nroutes())) {
268 /* temporary condition during a drag-n-drop */
272 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
273 TimeAxisView *tv = (*i)[route_display_columns.tv];
274 boost::shared_ptr<Route> route = (*i)[route_display_columns.route];
277 // just a "title" row
281 if (!ignore_route_list_reorder) {
283 /* this reorder is caused by user action, so reassign sort order keys
287 route->set_order_key (N_("editor"), order);
290 tv->set_old_order_key (order);
292 bool visible = (*i)[route_display_columns.visible];
295 tv->set_marked_for_display (true);
296 position += tv->show_at (position, n, &edit_controls_vbox);
305 full_canvas_height = position;
307 vertical_adjustment.set_upper (position + canvas_timebars_vsize);
308 if ((vertical_adjustment.get_value() + canvas_height) > vertical_adjustment.get_upper()) {
310 We're increasing the size of the canvas while the bottom is visible.
311 We scroll down to keep in step with the controls layout.
313 vertical_adjustment.set_value (position + canvas_timebars_vsize - canvas_height);
316 if (Config->get_sync_all_route_ordering() && !ignore_route_list_reorder) {
317 ignore_route_order_sync = true;
318 Route::SyncOrderKeys (); // EMIT SIGNAL
319 ignore_route_order_sync = false;
324 Editor::hide_all_tracks (bool with_select)
326 TreeModel::Children rows = route_display_model->children();
327 TreeModel::Children::iterator i;
329 no_route_list_redisplay = true;
331 for (i = rows.begin(); i != rows.end(); ++i) {
333 TreeModel::Row row = (*i);
334 TimeAxisView *tv = row[route_display_columns.tv];
340 row[route_display_columns.visible] = false;
343 no_route_list_redisplay = false;
344 redisplay_route_list ();
346 /* XXX this seems like a hack and half, but its not clear where to put this
350 //reset_scrolling_region ();
354 Editor::build_route_list_menu ()
356 using namespace Menu_Helpers;
359 route_list_menu = new Menu;
361 MenuList& items = route_list_menu->items();
362 route_list_menu->set_name ("ArdourContextMenu");
364 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
365 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
366 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
367 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
368 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
369 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
374 Editor::set_all_tracks_visibility (bool yn)
376 TreeModel::Children rows = route_display_model->children();
377 TreeModel::Children::iterator i;
379 no_route_list_redisplay = true;
381 for (i = rows.begin(); i != rows.end(); ++i) {
383 TreeModel::Row row = (*i);
384 TimeAxisView* tv = row[route_display_columns.tv];
390 (*i)[route_display_columns.visible] = yn;
393 no_route_list_redisplay = false;
394 redisplay_route_list ();
398 Editor::set_all_audio_visibility (int tracks, bool yn)
400 TreeModel::Children rows = route_display_model->children();
401 TreeModel::Children::iterator i;
403 no_route_list_redisplay = true;
405 for (i = rows.begin(); i != rows.end(); ++i) {
406 TreeModel::Row row = (*i);
407 TimeAxisView* tv = row[route_display_columns.tv];
408 AudioTimeAxisView* atv;
414 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
417 (*i)[route_display_columns.visible] = yn;
421 if (atv->is_audio_track()) {
422 (*i)[route_display_columns.visible] = yn;
427 if (!atv->is_audio_track()) {
428 (*i)[route_display_columns.visible] = yn;
435 no_route_list_redisplay = false;
436 redisplay_route_list ();
440 Editor::hide_all_routes ()
442 set_all_tracks_visibility (false);
446 Editor::show_all_routes ()
448 set_all_tracks_visibility (true);
452 Editor::show_all_audiobus ()
454 set_all_audio_visibility (2, true);
457 Editor::hide_all_audiobus ()
459 set_all_audio_visibility (2, false);
463 Editor::show_all_audiotracks()
465 set_all_audio_visibility (1, true);
468 Editor::hide_all_audiotracks ()
470 set_all_audio_visibility (1, false);
474 Editor::route_list_display_button_press (GdkEventButton* ev)
476 if (Keyboard::is_context_menu_event (ev)) {
477 show_route_list_menu ();
482 TreeModel::Path path;
483 TreeViewColumn* column;
487 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
491 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
493 if ((iter = route_display_model->get_iter (path))) {
494 TimeAxisView* tv = (*iter)[route_display_columns.tv];
496 bool visible = (*iter)[route_display_columns.visible];
497 (*iter)[route_display_columns.visible] = !visible;
503 /* allow normal processing to occur */
514 Editor::show_route_list_menu()
516 if (route_list_menu == 0) {
517 build_route_list_menu ();
520 route_list_menu->popup (1, gtk_get_current_event_time());
524 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
529 struct EditorOrderRouteSorter {
530 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
531 /* use of ">" forces the correct sort order */
532 return a->order_key ("editor") < b->order_key ("editor");
537 Editor::initial_route_list_display ()
539 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
540 Session::RouteList r (*routes);
541 EditorOrderRouteSorter sorter;
545 no_route_list_redisplay = true;
547 route_display_model->clear ();
549 handle_new_route (r);
551 no_route_list_redisplay = false;
553 redisplay_route_list ();
557 Editor::track_list_reorder (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter, int* new_order)
559 session->set_remote_control_ids();
560 redisplay_route_list ();
564 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
566 session->set_remote_control_ids();
567 redisplay_route_list ();
571 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
573 session->set_remote_control_ids();
574 ignore_route_list_reorder = true;
575 redisplay_route_list ();
576 ignore_route_list_reorder = false;
580 Editor::route_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
582 const SelectionData& data,
583 guint info, guint time)
585 cerr << "RouteLD::dddr target = " << data.get_target() << endl;
587 if (data.get_target() == "GTK_TREE_MODEL_ROW") {
588 cerr << "Delete drag data drop to treeview\n";
589 route_list_display.on_drag_data_received (context, x, y, data, info, time);
592 cerr << "some other kind of drag\n";
593 context->drag_finish (true, false, time);
597 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
599 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {