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.
27 #include "ardour_ui.h"
28 #include "audio_time_axis.h"
29 #include "midi_time_axis.h"
30 #include "mixer_strip.h"
31 #include "gui_thread.h"
34 #include <pbd/unknown_type.h>
36 #include <ardour/route.h>
41 using namespace ARDOUR;
48 Editor::handle_new_route (Session::RouteList& routes)
50 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route), routes));
53 RouteTimeAxisView *rtv;
54 TreeModel::Row parent;
57 ignore_route_list_reorder = true;
58 ignore_route_order_sync = true;
59 no_route_list_redisplay = true;
61 for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
62 boost::shared_ptr<Route> route = (*x);
64 if (route->is_hidden()) {
68 if (route->default_type() == ARDOUR::DataType::AUDIO)
69 tv = new AudioTimeAxisView (*this, *session, route, *track_canvas);
70 else if (route->default_type() == ARDOUR::DataType::MIDI)
71 tv = new MidiTimeAxisView (*this, *session, route, *track_canvas);
75 //cerr << "Editor::handle_new_route() called on " << route->name() << endl;//DEBUG
77 if (route_display_model->children().size() == 0) {
79 /* set up basic entries */
83 row = *(route_display_model->append()); // path = "0"
84 row[route_display_columns.text] = _("Busses");
85 row[route_display_columns.tv] = 0;
86 row = *(route_display_model->append()); // path = "1"
87 row[route_display_columns.text] = _("Tracks");
88 row[route_display_columns.tv] = 0;
92 if (dynamic_cast<AudioTrack*>(route.get()) != 0) {
93 TreeModel::iterator iter = route_display_model->get_iter ("1"); // audio tracks
96 TreeModel::iterator iter = route_display_model->get_iter ("0"); // busses
101 row = *(route_display_model->append (parent.children()));
103 row = *(route_display_model->append ());
106 row[route_display_columns.text] = route->name();
107 row[route_display_columns.visible] = tv->marked_for_display();
108 row[route_display_columns.tv] = tv;
109 row[route_display_columns.route] = route;
111 track_views.push_back (tv);
113 ignore_route_list_reorder = true;
115 if ((rtv = dynamic_cast<RouteTimeAxisView*> (tv)) != 0) {
116 /* added a new fresh one at the end */
117 if (rtv->route()->order_key(N_("editor")) == -1) {
118 rtv->route()->set_order_key (N_("editor"), route_display_model->children().size()-1);
120 rtv->effective_gain_display ();
123 ignore_route_list_reorder = false;
125 tv->set_old_order_key (route_display_model->children().size() - 1);
126 route->gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes));
128 tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv));
131 ignore_route_list_reorder = false;
132 ignore_route_order_sync = false;
133 no_route_list_redisplay = false;
135 redisplay_route_list ();
137 if (show_editor_mixer_when_tracks_arrive) {
138 show_editor_mixer (true);
141 editor_mixer_button.set_sensitive(true);
142 editor_list_button.set_sensitive(true);
146 Editor::handle_gui_changes (const string & what, void *src)
148 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
150 if (what == "track_height") {
151 /* make tracks change height while it happens, instead
154 track_canvas->update_now ();
155 redisplay_route_list ();
158 if (what == "visible_tracks") {
159 redisplay_route_list ();
164 Editor::remove_route (TimeAxisView *tv)
166 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
168 TrackViewList::iterator i;
169 TreeModel::Children rows = route_display_model->children();
170 TreeModel::Children::iterator ri;
172 if (tv == entered_track) {
176 /* Decrement old order keys for tracks `above' the one that is being removed */
177 for (ri = rows.begin(); ri != rows.end(); ++ri) {
178 TimeAxisView* v = (*ri)[route_display_columns.tv];
179 if (v->old_order_key() > tv->old_order_key()) {
180 v->set_old_order_key (v->old_order_key() - 1);
184 for (ri = rows.begin(); ri != rows.end(); ++ri) {
185 if ((*ri)[route_display_columns.tv] == tv) {
186 route_display_model->erase (ri);
191 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
192 track_views.erase (i);
195 /* since the editor mixer goes away when you remove a route, set the
196 * button to inactive and untick the menu option
199 editor_mixer_button.set_active(false);
200 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
202 /* and disable if all tracks and/or routes are gone */
204 if (track_views.size() == 0) {
205 editor_mixer_button.set_sensitive(false);
210 Editor::route_name_changed (TimeAxisView *tv)
212 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
214 TreeModel::Children rows = route_display_model->children();
215 TreeModel::Children::iterator i;
217 for (i = rows.begin(); i != rows.end(); ++i) {
218 if ((*i)[route_display_columns.tv] == tv) {
219 (*i)[route_display_columns.text] = tv->name();
226 Editor::update_route_visibility ()
228 TreeModel::Children rows = route_display_model->children();
229 TreeModel::Children::iterator i;
231 no_route_list_redisplay = true;
233 for (i = rows.begin(); i != rows.end(); ++i) {
234 TimeAxisView *tv = (*i)[route_display_columns.tv];
235 (*i)[route_display_columns.visible] = tv->marked_for_display ();
238 no_route_list_redisplay = false;
239 redisplay_route_list ();
243 Editor::hide_track_in_display (TimeAxisView& tv, bool temponly)
245 TreeModel::Children rows = route_display_model->children();
246 TreeModel::Children::iterator i;
248 for (i = rows.begin(); i != rows.end(); ++i) {
249 if ((*i)[route_display_columns.tv] == &tv) {
250 (*i)[route_display_columns.visible] = false;
252 tv.set_marked_for_display (false);
258 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
260 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
261 // this will hide the mixer strip
262 set_selected_mixer_strip (tv);
267 Editor::show_track_in_display (TimeAxisView& tv)
269 TreeModel::Children rows = route_display_model->children();
270 TreeModel::Children::iterator i;
272 for (i = rows.begin(); i != rows.end(); ++i) {
273 if ((*i)[route_display_columns.tv] == &tv) {
274 (*i)[route_display_columns.visible] = true;
275 tv.set_marked_for_display (true);
282 Editor::route_list_reordered (const TreeModel::Path& path,const TreeModel::iterator& iter,int* what)
284 redisplay_route_list ();
289 Editor::sync_order_keys ()
291 vector<int> neworder;
292 TreeModel::Children rows = route_display_model->children();
293 TreeModel::Children::iterator ri;
295 if (ignore_route_order_sync || !session || (session->state_of_the_state() & Session::Loading) || rows.empty()) {
299 for (ri = rows.begin(); ri != rows.end(); ++ri) {
300 neworder.push_back (0);
303 for (ri = rows.begin(); ri != rows.end(); ++ri) {
304 TimeAxisView* tv = (*ri)[route_display_columns.tv];
305 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
306 neworder[route->order_key (X_("editor"))] = tv->old_order_key ();
309 ignore_route_list_reorder = true;
310 route_display_model->reorder (neworder);
311 ignore_route_list_reorder = false;
315 Editor::redisplay_route_list ()
317 TreeModel::Children rows = route_display_model->children();
318 TreeModel::Children::iterator i;
323 if (no_route_list_redisplay) {
327 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
328 TimeAxisView *tv = (*i)[route_display_columns.tv];
329 RouteTimeAxisView* rt;
332 // just a "title" row
336 if (!ignore_route_list_reorder) {
338 /* this reorder is caused by user action, so reassign sort order keys
342 if ((rt = dynamic_cast<RouteTimeAxisView*> (tv)) != 0) {
343 rt->route()->set_order_key (N_("editor"), order);
348 bool visible = (*i)[route_display_columns.visible];
351 tv->set_marked_for_display (true);
352 position += tv->show_at (position, n, &edit_controls_vbox);
361 full_canvas_height = position;
363 /* make sure the cursors stay on top of every newly added track */
365 cursor_group->raise_to_top ();
367 //reset_scrolling_region ();
369 if (Config->get_sync_all_route_ordering() && !ignore_route_list_reorder) {
370 ignore_route_order_sync = true;
371 Route::SyncOrderKeys (); // EMIT SIGNAL
372 ignore_route_order_sync = false;
378 Editor::hide_all_tracks (bool with_select)
380 TreeModel::Children rows = route_display_model->children();
381 TreeModel::Children::iterator i;
383 no_route_list_redisplay = true;
385 for (i = rows.begin(); i != rows.end(); ++i) {
387 TreeModel::Row row = (*i);
388 TimeAxisView *tv = row[route_display_columns.tv];
394 row[route_display_columns.visible] = false;
397 no_route_list_redisplay = false;
398 redisplay_route_list ();
400 /* XXX this seems like a hack and half, but its not clear where to put this
404 //reset_scrolling_region ();
408 Editor::build_route_list_menu ()
410 using namespace Menu_Helpers;
413 route_list_menu = new Menu;
415 MenuList& items = route_list_menu->items();
416 route_list_menu->set_name ("ArdourContextMenu");
418 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
419 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
420 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
421 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
422 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
423 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
428 Editor::set_all_tracks_visibility (bool yn)
430 TreeModel::Children rows = route_display_model->children();
431 TreeModel::Children::iterator i;
433 no_route_list_redisplay = true;
435 for (i = rows.begin(); i != rows.end(); ++i) {
437 TreeModel::Row row = (*i);
438 TimeAxisView* tv = row[route_display_columns.tv];
444 (*i)[route_display_columns.visible] = yn;
447 no_route_list_redisplay = false;
448 redisplay_route_list ();
452 Editor::set_all_audio_visibility (int tracks, bool yn)
454 TreeModel::Children rows = route_display_model->children();
455 TreeModel::Children::iterator i;
457 no_route_list_redisplay = true;
459 for (i = rows.begin(); i != rows.end(); ++i) {
460 TreeModel::Row row = (*i);
461 TimeAxisView* tv = row[route_display_columns.tv];
462 AudioTimeAxisView* atv;
468 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
471 (*i)[route_display_columns.visible] = yn;
475 if (atv->is_audio_track()) {
476 (*i)[route_display_columns.visible] = yn;
481 if (!atv->is_audio_track()) {
482 (*i)[route_display_columns.visible] = yn;
489 no_route_list_redisplay = false;
490 redisplay_route_list ();
494 Editor::hide_all_routes ()
496 set_all_tracks_visibility (false);
500 Editor::show_all_routes ()
502 set_all_tracks_visibility (true);
506 Editor::show_all_audiobus ()
508 set_all_audio_visibility (2, true);
511 Editor::hide_all_audiobus ()
513 set_all_audio_visibility (2, false);
517 Editor::show_all_audiotracks()
519 set_all_audio_visibility (1, true);
522 Editor::hide_all_audiotracks ()
524 set_all_audio_visibility (1, false);
528 Editor::route_list_display_button_press (GdkEventButton* ev)
530 if (Keyboard::is_context_menu_event (ev)) {
531 show_route_list_menu ();
536 TreeModel::Path path;
537 TreeViewColumn* column;
541 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
545 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
547 if ((iter = route_display_model->get_iter (path))) {
548 TimeAxisView* tv = (*iter)[route_display_columns.tv];
550 bool visible = (*iter)[route_display_columns.visible];
551 (*iter)[route_display_columns.visible] = !visible;
557 /* allow normal processing to occur */
568 Editor::show_route_list_menu()
570 if (route_list_menu == 0) {
571 build_route_list_menu ();
574 route_list_menu->popup (1, gtk_get_current_event_time());
578 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
583 struct EditorOrderRouteSorter {
584 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
585 /* use of ">" forces the correct sort order */
586 return a->order_key ("editor") < b->order_key ("editor");
591 Editor::initial_route_list_display ()
593 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
594 Session::RouteList r (*routes);
595 EditorOrderRouteSorter sorter;
599 no_route_list_redisplay = true;
601 route_display_model->clear ();
603 handle_new_route (r);
605 no_route_list_redisplay = false;
607 redisplay_route_list ();
611 Editor::track_list_reorder (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter, int* new_order)
613 session->set_remote_control_ids();
614 redisplay_route_list ();
618 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
620 session->set_remote_control_ids();
621 redisplay_route_list ();
625 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
627 session->set_remote_control_ids();
628 ignore_route_list_reorder = true;
629 redisplay_route_list ();
630 ignore_route_list_reorder = false;
634 Editor::route_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
636 const SelectionData& data,
637 guint info, guint time)
639 cerr << "RouteLD::dddr target = " << data.get_target() << endl;
641 if (data.get_target() == "GTK_TREE_MODEL_ROW") {
642 cerr << "Delete drag data drop to treeview\n";
643 route_list_display.on_drag_data_received (context, x, y, data, info, time);
646 cerr << "some other kind of drag\n";
647 context->drag_finish (true, false, time);
651 Editor::get_route_view_by_id (PBD::ID& id)
653 RouteTimeAxisView* v;
655 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
656 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
657 if(v->route()->id() == id) {
667 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
669 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {