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);
98 editor_mixer_button.set_sensitive(true);
102 Editor::handle_gui_changes (const string & what, void *src)
104 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
106 if (what == "track_height") {
107 redisplay_route_list ();
112 Editor::remove_route (TimeAxisView *tv)
114 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
116 TrackViewList::iterator i;
117 TreeModel::Children rows = route_display_model->children();
118 TreeModel::Children::iterator ri;
120 /* Decrement old order keys for tracks `above' the one that is being removed */
121 for (ri = rows.begin(); ri != rows.end(); ++ri) {
122 TimeAxisView* v = (*ri)[route_display_columns.tv];
123 if (v->old_order_key() > tv->old_order_key()) {
124 v->set_old_order_key (v->old_order_key() - 1);
128 for (ri = rows.begin(); ri != rows.end(); ++ri) {
129 if ((*ri)[route_display_columns.tv] == tv) {
130 route_display_model->erase (ri);
135 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
136 track_views.erase (i);
139 /* since the editor mixer goes away when you remove a route, set the
140 * button to inactive and untick the menu option
143 editor_mixer_button.set_active(false);
144 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
146 /* and disable if all tracks and/or routes are gone */
148 if (track_views.size() == 0) {
149 editor_mixer_button.set_sensitive(false);
154 Editor::route_name_changed (TimeAxisView *tv)
156 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
158 TreeModel::Children rows = route_display_model->children();
159 TreeModel::Children::iterator i;
161 for (i = rows.begin(); i != rows.end(); ++i) {
162 if ((*i)[route_display_columns.tv] == tv) {
163 (*i)[route_display_columns.text] = tv->name();
171 Editor::hide_track_in_display (TimeAxisView& tv)
173 TreeModel::Children rows = route_display_model->children();
174 TreeModel::Children::iterator i;
176 for (i = rows.begin(); i != rows.end(); ++i) {
177 if ((*i)[route_display_columns.tv] == &tv) {
178 (*i)[route_display_columns.visible] = false;
183 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
185 if (atv && current_mixer_strip && (atv->route() == current_mixer_strip->route())) {
186 // this will hide the mixer strip
187 set_selected_mixer_strip (tv);
192 Editor::show_track_in_display (TimeAxisView& tv)
194 TreeModel::Children rows = route_display_model->children();
195 TreeModel::Children::iterator i;
197 for (i = rows.begin(); i != rows.end(); ++i) {
198 if ((*i)[route_display_columns.tv] == &tv) {
199 (*i)[route_display_columns.visible] = true;
200 tv.set_marked_for_display (true);
207 Editor::sync_order_keys ()
209 vector<int> neworder;
210 TreeModel::Children rows = route_display_model->children();
211 TreeModel::Children::iterator ri;
213 if (ignore_route_order_sync || !session || (session->state_of_the_state() & Session::Loading) || rows.empty()) {
217 for (ri = rows.begin(); ri != rows.end(); ++ri) {
218 neworder.push_back (0);
221 for (ri = rows.begin(); ri != rows.end(); ++ri) {
222 TimeAxisView* tv = (*ri)[route_display_columns.tv];
223 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
224 neworder[route->order_key (X_("editor"))] = tv->old_order_key ();
227 ignore_route_list_reorder = true;
228 route_display_model->reorder (neworder);
229 ignore_route_list_reorder = false;
233 Editor::redisplay_route_list ()
235 TreeModel::Children rows = route_display_model->children();
236 TreeModel::Children::iterator i;
241 if (no_route_list_redisplay) {
245 if (session && (rows.size() > session->nroutes())) {
246 /* temporary condition during a drag-n-drop */
250 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
251 TimeAxisView *tv = (*i)[route_display_columns.tv];
252 boost::shared_ptr<Route> route = (*i)[route_display_columns.route];
255 // just a "title" row
259 if (!ignore_route_list_reorder) {
261 /* this reorder is caused by user action, so reassign sort order keys
265 route->set_order_key (N_("editor"), order);
268 tv->set_old_order_key (order);
270 bool visible = (*i)[route_display_columns.visible];
273 tv->set_marked_for_display (true);
274 position += tv->show_at (position, n, &edit_controls_vbox);
283 full_canvas_height = position;
285 /* make sure the cursors stay on top of every newly added track */
287 cursor_group->raise_to_top ();
289 reset_scrolling_region ();
291 if (Config->get_sync_all_route_ordering() && !ignore_route_list_reorder) {
292 ignore_route_order_sync = true;
293 Route::SyncOrderKeys (); // EMIT SIGNAL
294 ignore_route_order_sync = false;
299 Editor::hide_all_tracks (bool with_select)
301 TreeModel::Children rows = route_display_model->children();
302 TreeModel::Children::iterator i;
304 no_route_list_redisplay = true;
306 for (i = rows.begin(); i != rows.end(); ++i) {
308 TreeModel::Row row = (*i);
309 TimeAxisView *tv = row[route_display_columns.tv];
315 row[route_display_columns.visible] = false;
318 no_route_list_redisplay = false;
319 redisplay_route_list ();
321 /* XXX this seems like a hack and half, but its not clear where to put this
325 reset_scrolling_region ();
329 Editor::build_route_list_menu ()
331 using namespace Menu_Helpers;
334 route_list_menu = new Menu;
336 MenuList& items = route_list_menu->items();
337 route_list_menu->set_name ("ArdourContextMenu");
339 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
340 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
341 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
342 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
343 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
344 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
349 Editor::set_all_tracks_visibility (bool yn)
351 TreeModel::Children rows = route_display_model->children();
352 TreeModel::Children::iterator i;
354 no_route_list_redisplay = true;
356 for (i = rows.begin(); i != rows.end(); ++i) {
358 TreeModel::Row row = (*i);
359 TimeAxisView* tv = row[route_display_columns.tv];
365 (*i)[route_display_columns.visible] = yn;
368 no_route_list_redisplay = false;
369 redisplay_route_list ();
373 Editor::set_all_audio_visibility (int tracks, bool yn)
375 TreeModel::Children rows = route_display_model->children();
376 TreeModel::Children::iterator i;
378 no_route_list_redisplay = true;
380 for (i = rows.begin(); i != rows.end(); ++i) {
381 TreeModel::Row row = (*i);
382 TimeAxisView* tv = row[route_display_columns.tv];
383 AudioTimeAxisView* atv;
389 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
392 (*i)[route_display_columns.visible] = yn;
396 if (atv->is_audio_track()) {
397 (*i)[route_display_columns.visible] = yn;
402 if (!atv->is_audio_track()) {
403 (*i)[route_display_columns.visible] = yn;
410 no_route_list_redisplay = false;
411 redisplay_route_list ();
415 Editor::hide_all_routes ()
417 set_all_tracks_visibility (false);
421 Editor::show_all_routes ()
423 set_all_tracks_visibility (true);
427 Editor::show_all_audiobus ()
429 set_all_audio_visibility (2, true);
432 Editor::hide_all_audiobus ()
434 set_all_audio_visibility (2, false);
438 Editor::show_all_audiotracks()
440 set_all_audio_visibility (1, true);
443 Editor::hide_all_audiotracks ()
445 set_all_audio_visibility (1, false);
449 Editor::route_list_display_button_press (GdkEventButton* ev)
451 if (Keyboard::is_context_menu_event (ev)) {
452 show_route_list_menu ();
457 TreeModel::Path path;
458 TreeViewColumn* column;
462 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
466 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
468 if ((iter = route_display_model->get_iter (path))) {
469 TimeAxisView* tv = (*iter)[route_display_columns.tv];
471 bool visible = (*iter)[route_display_columns.visible];
472 (*iter)[route_display_columns.visible] = !visible;
478 /* allow normal processing to occur */
489 Editor::show_route_list_menu()
491 if (route_list_menu == 0) {
492 build_route_list_menu ();
495 route_list_menu->popup (1, gtk_get_current_event_time());
499 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
504 struct EditorOrderRouteSorter {
505 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
506 /* use of ">" forces the correct sort order */
507 return a->order_key ("editor") < b->order_key ("editor");
512 Editor::initial_route_list_display ()
514 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
515 Session::RouteList r (*routes);
516 EditorOrderRouteSorter sorter;
520 no_route_list_redisplay = true;
522 route_display_model->clear ();
524 handle_new_route (r);
526 no_route_list_redisplay = false;
528 redisplay_route_list ();
532 Editor::track_list_reorder (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter, int* new_order)
534 session->set_remote_control_ids();
535 redisplay_route_list ();
539 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
541 session->set_remote_control_ids();
542 redisplay_route_list ();
546 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
548 session->set_remote_control_ids();
549 redisplay_route_list ();
554 Editor::route_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
556 const SelectionData& data,
557 guint info, guint time)
559 cerr << "RouteLD::dddr target = " << data.get_target() << endl;
561 if (data.get_target() == "GTK_TREE_MODEL_ROW") {
562 cerr << "Delete drag data drop to treeview\n";
563 route_list_display.on_drag_data_received (context, x, y, data, info, time);
566 cerr << "some other kind of drag\n";
567 context->drag_finish (true, false, time);
571 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
573 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {