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.
29 #include "ardour_ui.h"
30 #include "audio_time_axis.h"
31 #include "midi_time_axis.h"
32 #include "mixer_strip.h"
33 #include "gui_thread.h"
36 #include <pbd/unknown_type.h>
38 #include <ardour/route.h>
43 using namespace ARDOUR;
48 const char* _order_key = N_("editor");
51 Editor::handle_new_route (Session::RouteList& routes)
53 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route), routes));
56 RouteTimeAxisView *rtv;
57 TreeModel::Row parent;
60 route_redisplay_does_not_sync_order_keys = true;
61 no_route_list_redisplay = true;
63 for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
64 boost::shared_ptr<Route> route = (*x);
66 if (route->is_hidden()) {
70 if (route->default_type() == ARDOUR::DataType::AUDIO)
71 tv = new AudioTimeAxisView (*this, *session, route, *track_canvas);
72 else if (route->default_type() == ARDOUR::DataType::MIDI)
73 tv = new MidiTimeAxisView (*this, *session, route, *track_canvas);
77 //cerr << "Editor::handle_new_route() called on " << route->name() << endl;//DEBUG
79 if (route_display_model->children().size() == 0) {
81 /* set up basic entries */
85 row = *(route_display_model->append()); // path = "0"
86 row[route_display_columns.text] = _("Busses");
87 row[route_display_columns.tv] = 0;
88 row = *(route_display_model->append()); // path = "1"
89 row[route_display_columns.text] = _("Tracks");
90 row[route_display_columns.tv] = 0;
94 if (dynamic_cast<AudioTrack*>(route.get()) != 0) {
95 TreeModel::iterator iter = route_display_model->get_iter ("1"); // audio tracks
98 TreeModel::iterator iter = route_display_model->get_iter ("0"); // busses
103 row = *(route_display_model->append (parent.children()));
105 row = *(route_display_model->append ());
108 // cerr << route->name() << " marked for display ? " << tv->marked_for_display() << endl;
110 row[route_display_columns.text] = route->name();
111 row[route_display_columns.visible] = tv->marked_for_display();
112 row[route_display_columns.tv] = tv;
113 row[route_display_columns.route] = route;
115 track_views.push_back (tv);
117 ignore_route_list_reorder = true;
119 if ((rtv = dynamic_cast<RouteTimeAxisView*> (tv)) != 0) {
120 /* added a new fresh one at the end */
121 if (rtv->route()->order_key(_order_key) == -1) {
122 rtv->route()->set_order_key (_order_key, route_display_model->children().size()-1);
124 rtv->effective_gain_display ();
127 ignore_route_list_reorder = false;
129 route->gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes));
131 tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv));
134 no_route_list_redisplay = false;
136 redisplay_route_list ();
138 if (show_editor_mixer_when_tracks_arrive) {
139 show_editor_mixer (true);
142 editor_list_button.set_sensitive(true);
143 route_redisplay_does_not_sync_order_keys = false;
147 Editor::handle_gui_changes (const string & what, void *src)
149 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
151 if (what == "track_height") {
152 /* Optional :make tracks change height while it happens, instead
155 //track_canvas->update_now ();
156 redisplay_route_list ();
159 if (what == "visible_tracks") {
160 redisplay_route_list ();
165 Editor::remove_route (TimeAxisView *tv)
167 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
169 TrackViewList::iterator i;
170 TreeModel::Children rows = route_display_model->children();
171 TreeModel::Children::iterator ri;
173 if (tv == entered_track) {
177 /* the core model has changed, there is no need to sync
181 route_redisplay_does_not_sync_order_keys = true;
183 for (ri = rows.begin(); ri != rows.end(); ++ri) {
184 if ((*ri)[route_display_columns.tv] == tv) {
185 route_display_model->erase (ri);
190 route_redisplay_does_not_sync_order_keys = false;
192 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
193 track_views.erase (i);
196 /* since the editor mixer goes away when you remove a route, set the
197 * button to inactive and untick the menu option
200 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
204 Editor::route_name_changed (TimeAxisView *tv)
206 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
208 TreeModel::Children rows = route_display_model->children();
209 TreeModel::Children::iterator i;
211 for (i = rows.begin(); i != rows.end(); ++i) {
212 if ((*i)[route_display_columns.tv] == tv) {
213 (*i)[route_display_columns.text] = tv->name();
220 Editor::update_route_visibility ()
222 TreeModel::Children rows = route_display_model->children();
223 TreeModel::Children::iterator i;
225 no_route_list_redisplay = true;
227 for (i = rows.begin(); i != rows.end(); ++i) {
228 TimeAxisView *tv = (*i)[route_display_columns.tv];
229 (*i)[route_display_columns.visible] = tv->marked_for_display ();
230 cerr << "marked " << tv->name() << " for display = " << tv->marked_for_display() << endl;
233 no_route_list_redisplay = false;
234 redisplay_route_list ();
238 Editor::hide_track_in_display (TimeAxisView& tv, bool temponly)
240 TreeModel::Children rows = route_display_model->children();
241 TreeModel::Children::iterator i;
243 for (i = rows.begin(); i != rows.end(); ++i) {
244 if ((*i)[route_display_columns.tv] == &tv) {
245 (*i)[route_display_columns.visible] = false;
250 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
252 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
253 // this will hide the mixer strip
254 set_selected_mixer_strip (tv);
259 Editor::show_track_in_display (TimeAxisView& tv)
261 TreeModel::Children rows = route_display_model->children();
262 TreeModel::Children::iterator i;
264 for (i = rows.begin(); i != rows.end(); ++i) {
265 if ((*i)[route_display_columns.tv] == &tv) {
266 (*i)[route_display_columns.visible] = true;
273 Editor::route_list_reordered (const TreeModel::Path& path,const TreeModel::iterator& iter,int* what)
275 redisplay_route_list ();
280 Editor::sync_order_keys (const char *src)
282 vector<int> neworder;
283 TreeModel::Children rows = route_display_model->children();
284 TreeModel::Children::iterator ri;
286 if ((strcmp (src, _order_key) == 0) || !session || (session->state_of_the_state() & Session::Loading) || rows.empty()) {
290 for (ri = rows.begin(); ri != rows.end(); ++ri) {
291 neworder.push_back (0);
294 bool changed = false;
297 for (order = 0, ri = rows.begin(); ri != rows.end(); ++ri, ++order) {
298 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
301 int new_key = route->order_key (_order_key);
303 neworder[new_key] = old_key;
305 if (new_key != old_key) {
311 route_redisplay_does_not_reset_order_keys = true;
312 route_display_model->reorder (neworder);
313 route_redisplay_does_not_reset_order_keys = false;
318 Editor::redisplay_route_list ()
320 TreeModel::Children rows = route_display_model->children();
321 TreeModel::Children::iterator i;
326 if (no_route_list_redisplay) {
330 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
331 TimeAxisView *tv = (*i)[route_display_columns.tv];
332 boost::shared_ptr<Route> route = (*i)[route_display_columns.route];
335 // just a "title" row
339 if (!route_redisplay_does_not_reset_order_keys) {
341 /* this reorder is caused by user action, so reassign sort order keys
345 route->set_order_key (_order_key, 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);
353 tv->clip_to_viewport ();
355 tv->set_marked_for_display (false);
363 full_canvas_height = position + canvas_timebars_vsize;
364 vertical_adjustment.set_upper (full_canvas_height);
365 if ((vertical_adjustment.get_value() + canvas_height) > vertical_adjustment.get_upper()) {
367 We're increasing the size of the canvas while the bottom is visible.
368 We scroll down to keep in step with the controls layout.
370 vertical_adjustment.set_value (full_canvas_height - canvas_height);
373 if (!route_redisplay_does_not_reset_order_keys && !route_redisplay_does_not_sync_order_keys) {
374 session->sync_order_keys (_order_key);
379 Editor::hide_all_tracks (bool with_select)
381 TreeModel::Children rows = route_display_model->children();
382 TreeModel::Children::iterator i;
384 no_route_list_redisplay = true;
386 for (i = rows.begin(); i != rows.end(); ++i) {
388 TreeModel::Row row = (*i);
389 TimeAxisView *tv = row[route_display_columns.tv];
395 row[route_display_columns.visible] = false;
398 no_route_list_redisplay = false;
399 redisplay_route_list ();
401 /* XXX this seems like a hack and half, but its not clear where to put this
405 //reset_scrolling_region ();
409 Editor::build_route_list_menu ()
411 using namespace Menu_Helpers;
414 route_list_menu = new Menu;
416 MenuList& items = route_list_menu->items();
417 route_list_menu->set_name ("ArdourContextMenu");
419 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
420 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
421 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
422 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
423 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
424 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
429 Editor::set_all_tracks_visibility (bool yn)
431 TreeModel::Children rows = route_display_model->children();
432 TreeModel::Children::iterator i;
434 no_route_list_redisplay = true;
436 for (i = rows.begin(); i != rows.end(); ++i) {
438 TreeModel::Row row = (*i);
439 TimeAxisView* tv = row[route_display_columns.tv];
445 (*i)[route_display_columns.visible] = yn;
448 no_route_list_redisplay = false;
449 redisplay_route_list ();
453 Editor::set_all_audio_visibility (int tracks, bool yn)
455 TreeModel::Children rows = route_display_model->children();
456 TreeModel::Children::iterator i;
458 no_route_list_redisplay = true;
460 for (i = rows.begin(); i != rows.end(); ++i) {
461 TreeModel::Row row = (*i);
462 TimeAxisView* tv = row[route_display_columns.tv];
463 AudioTimeAxisView* atv;
469 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
472 (*i)[route_display_columns.visible] = yn;
476 if (atv->is_audio_track()) {
477 (*i)[route_display_columns.visible] = yn;
482 if (!atv->is_audio_track()) {
483 (*i)[route_display_columns.visible] = yn;
490 no_route_list_redisplay = false;
491 redisplay_route_list ();
495 Editor::hide_all_routes ()
497 set_all_tracks_visibility (false);
501 Editor::show_all_routes ()
503 set_all_tracks_visibility (true);
507 Editor::show_all_audiobus ()
509 set_all_audio_visibility (2, true);
512 Editor::hide_all_audiobus ()
514 set_all_audio_visibility (2, false);
518 Editor::show_all_audiotracks()
520 set_all_audio_visibility (1, true);
523 Editor::hide_all_audiotracks ()
525 set_all_audio_visibility (1, false);
529 Editor::route_list_display_button_press (GdkEventButton* ev)
531 if (Keyboard::is_context_menu_event (ev)) {
532 show_route_list_menu ();
537 TreeModel::Path path;
538 TreeViewColumn* column;
542 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
546 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
548 if ((iter = route_display_model->get_iter (path))) {
549 TimeAxisView* tv = (*iter)[route_display_columns.tv];
551 bool visible = (*iter)[route_display_columns.visible];
552 (*iter)[route_display_columns.visible] = !visible;
558 /* allow normal processing to occur */
569 Editor::show_route_list_menu()
571 if (route_list_menu == 0) {
572 build_route_list_menu ();
575 route_list_menu->popup (1, gtk_get_current_event_time());
579 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
584 struct EditorOrderRouteSorter {
585 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
586 /* use of ">" forces the correct sort order */
587 return a->order_key (_order_key) < b->order_key (_order_key);
592 Editor::initial_route_list_display ()
594 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
595 Session::RouteList r (*routes);
596 EditorOrderRouteSorter sorter;
600 no_route_list_redisplay = true;
602 route_display_model->clear ();
604 handle_new_route (r);
606 no_route_list_redisplay = false;
608 redisplay_route_list ();
612 Editor::track_list_reorder (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter, int* new_order)
614 route_redisplay_does_not_sync_order_keys = true;
615 session->set_remote_control_ids();
616 redisplay_route_list ();
617 route_redisplay_does_not_sync_order_keys = false;
621 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
623 /* never reset order keys because of a property change */
624 route_redisplay_does_not_reset_order_keys = true;
625 session->set_remote_control_ids();
626 redisplay_route_list ();
627 route_redisplay_does_not_reset_order_keys = false;
631 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
633 /* this could require an order reset & sync */
634 session->set_remote_control_ids();
635 ignore_route_list_reorder = true;
636 redisplay_route_list ();
637 ignore_route_list_reorder = false;
641 Editor::route_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
643 const SelectionData& data,
644 guint info, guint time)
646 cerr << "RouteLD::dddr target = " << data.get_target() << endl;
648 if (data.get_target() == "GTK_TREE_MODEL_ROW") {
649 cerr << "Delete drag data drop to treeview\n";
650 route_list_display.on_drag_data_received (context, x, y, data, info, time);
653 cerr << "some other kind of drag\n";
654 context->drag_finish (true, false, time);
658 Editor::get_route_view_by_id (PBD::ID& id)
660 RouteTimeAxisView* v;
662 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
663 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
664 if(v->route()->id() == id) {
674 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
676 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
682 Editor::move_selected_tracks (bool up)
684 if (selection->tracks.empty()) {
688 typedef std::pair<TimeAxisView*,boost::shared_ptr<Route> > ViewRoute;
689 std::list<ViewRoute> view_routes;
690 std::vector<int> neworder;
691 TreeModel::Children rows = route_display_model->children();
692 TreeModel::Children::iterator ri;
694 for (ri = rows.begin(); ri != rows.end(); ++ri) {
695 TimeAxisView* tv = (*ri)[route_display_columns.tv];
696 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
698 view_routes.push_back (ViewRoute (tv, route));
701 list<ViewRoute>::iterator trailing;
702 list<ViewRoute>::iterator leading;
706 trailing = view_routes.begin();
707 leading = view_routes.begin();
711 while (leading != view_routes.end()) {
712 if (selection->selected (leading->first)) {
713 view_routes.insert (trailing, ViewRoute (leading->first, leading->second));
714 leading = view_routes.erase (leading);
723 /* if we could use reverse_iterator in list::insert, this code
724 would be a beautiful reflection of the code above. but we can't
725 and so it looks like a bit of a mess.
728 trailing = view_routes.end();
729 leading = view_routes.end();
731 --leading; if (leading == view_routes.begin()) { return; }
737 if (selection->selected (leading->first)) {
738 list<ViewRoute>::iterator tmp;
740 /* need to insert *after* trailing, not *before* it,
741 which is what insert (iter, val) normally does.
747 view_routes.insert (tmp, ViewRoute (leading->first, leading->second));
749 /* can't use iter = cont.erase (iter); form here, because
750 we need iter to move backwards.
758 if (leading == view_routes.begin()) {
759 /* the one we've just inserted somewhere else
760 was the first in the list. erase this copy,
761 and then break, because we're done.
766 view_routes.erase (leading);
775 if (leading == view_routes.begin()) {
784 for (leading = view_routes.begin(); leading != view_routes.end(); ++leading) {
785 neworder.push_back (leading->second->order_key (_order_key));
788 route_display_model->reorder (neworder);
792 vector<boost::shared_ptr<Route> > selected_block;
793 boost::shared_ptr<Route> target_unselected_route;
794 bool last_track_was_selected = false;
795 vector<int> neworder;
796 TreeModel::Children rows = route_display_model->children();
797 TreeModel::Children::iterator ri;
802 /* preload "neworder" with the current order */
804 for (n = 0, ri = rows.begin(); ri != rows.end(); ++ri, ++n) {
805 neworder.push_back (n);
808 for (ri = rows.begin(); ri != rows.end(); ++ri) {
810 TimeAxisView* tv = (*ri)[route_display_columns.tv];
811 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
813 if (selection->selected (tv)) {
815 selected_block.push_back (route);
816 cerr << "--SAVE as SELECTED " << route->name() << endl;
817 last_track_was_selected = true;
822 if (!last_track_was_selected) {
823 /* keep moving through unselected tracks, but save this
824 one in case we need it later as the one that will
825 move *down* as the selected block moves up.
827 target_unselected_route = route;
828 cerr << "--pre-SAVE as UNSELECTED " << route->name() << endl;
832 last_track_was_selected = false;
835 /* this is the track immediately after a selected block,
836 and this is the one that will move *up* as
837 the selected block moves down.
840 target_unselected_route = route;
841 cerr << "--post-SAVE as UNSELECTED " << route->name() << endl;
843 cerr << "--(up) plan to use existing unselected target\n";
847 cerr << "TRANSITION: sel = " << selected_block.size() << " unsel = " << target_unselected_route << endl;
849 /* transitioned between selected/not-selected */
853 for (vector<boost::shared_ptr<Route> >::iterator x = selected_block.begin(); x != selected_block.end(); ++x) {
854 old_key = (*x)->order_key (_order_key);
855 new_key = compute_new_key (old_key, up, 1, rows.size());
856 neworder[new_key] = old_key;
857 cerr << "--SELECTED, reorder from " << old_key << " => " << new_key << endl;
860 /* now move the unselected tracks in the opposite direction */
862 if (!selected_block.empty() && target_unselected_route) {
863 distance = selected_block.size();
864 old_key = target_unselected_route->order_key (_order_key);
865 new_key = compute_new_key (old_key, !up, distance, rows.size());
866 neworder[new_key] = old_key;
867 cerr << "--UNSELECTED, reorder from " << old_key << " => " << new_key << endl;
870 selected_block.clear ();
871 target_unselected_route.reset ();
874 cerr << "when done ... sel = " << selected_block.size() << " unsel = " << target_unselected_route << endl;
876 if (!selected_block.empty() || target_unselected_route) {
878 /* left over blocks */
882 for (vector<boost::shared_ptr<Route> >::iterator x = selected_block.begin(); x != selected_block.end(); ++x) {
883 old_key = (*x)->order_key (_order_key);
884 new_key = compute_new_key (old_key, up, 1, rows.size());
885 neworder[new_key] = old_key;
886 cerr << "--SELECTED, reorder from " << old_key << " => " << new_key << endl;
889 if (!selected_block.empty() && target_unselected_route) {
890 distance = selected_block.size();
891 old_key = target_unselected_route->order_key (_order_key);
892 new_key = compute_new_key (old_key, !up, distance, rows.size());
893 neworder[new_key] = old_key;
894 cerr << "--UNSELECTED, reorder from " << old_key << " => " << new_key << endl;
898 route_display_model->reorder (neworder);