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];
350 /* show or hide the TimeAxisView */
352 tv->set_marked_for_display (true);
353 position += tv->show_at (position, n, &edit_controls_vbox);
354 tv->clip_to_viewport ();
356 tv->set_marked_for_display (false);
364 full_canvas_height = position + canvas_timebars_vsize;
365 vertical_adjustment.set_upper (full_canvas_height);
366 if ((vertical_adjustment.get_value() + canvas_height) > vertical_adjustment.get_upper()) {
368 We're increasing the size of the canvas while the bottom is visible.
369 We scroll down to keep in step with the controls layout.
371 vertical_adjustment.set_value (full_canvas_height - canvas_height);
374 if (!route_redisplay_does_not_reset_order_keys && !route_redisplay_does_not_sync_order_keys) {
375 session->sync_order_keys (_order_key);
380 Editor::hide_all_tracks (bool with_select)
382 TreeModel::Children rows = route_display_model->children();
383 TreeModel::Children::iterator i;
385 no_route_list_redisplay = true;
387 for (i = rows.begin(); i != rows.end(); ++i) {
389 TreeModel::Row row = (*i);
390 TimeAxisView *tv = row[route_display_columns.tv];
396 row[route_display_columns.visible] = false;
399 no_route_list_redisplay = false;
400 redisplay_route_list ();
402 /* XXX this seems like a hack and half, but its not clear where to put this
406 //reset_scrolling_region ();
410 Editor::build_route_list_menu ()
412 using namespace Menu_Helpers;
415 route_list_menu = new Menu;
417 MenuList& items = route_list_menu->items();
418 route_list_menu->set_name ("ArdourContextMenu");
420 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
421 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
422 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
423 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
424 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
425 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
430 Editor::set_all_tracks_visibility (bool yn)
432 TreeModel::Children rows = route_display_model->children();
433 TreeModel::Children::iterator i;
435 no_route_list_redisplay = true;
437 for (i = rows.begin(); i != rows.end(); ++i) {
439 TreeModel::Row row = (*i);
440 TimeAxisView* tv = row[route_display_columns.tv];
446 (*i)[route_display_columns.visible] = yn;
449 no_route_list_redisplay = false;
450 redisplay_route_list ();
454 Editor::set_all_audio_visibility (int tracks, bool yn)
456 TreeModel::Children rows = route_display_model->children();
457 TreeModel::Children::iterator i;
459 no_route_list_redisplay = true;
461 for (i = rows.begin(); i != rows.end(); ++i) {
462 TreeModel::Row row = (*i);
463 TimeAxisView* tv = row[route_display_columns.tv];
464 AudioTimeAxisView* atv;
470 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
473 (*i)[route_display_columns.visible] = yn;
477 if (atv->is_audio_track()) {
478 (*i)[route_display_columns.visible] = yn;
483 if (!atv->is_audio_track()) {
484 (*i)[route_display_columns.visible] = yn;
491 no_route_list_redisplay = false;
492 redisplay_route_list ();
496 Editor::hide_all_routes ()
498 set_all_tracks_visibility (false);
502 Editor::show_all_routes ()
504 set_all_tracks_visibility (true);
508 Editor::show_all_audiobus ()
510 set_all_audio_visibility (2, true);
513 Editor::hide_all_audiobus ()
515 set_all_audio_visibility (2, false);
519 Editor::show_all_audiotracks()
521 set_all_audio_visibility (1, true);
524 Editor::hide_all_audiotracks ()
526 set_all_audio_visibility (1, false);
530 Editor::route_list_display_button_press (GdkEventButton* ev)
532 if (Keyboard::is_context_menu_event (ev)) {
533 show_route_list_menu ();
538 TreeModel::Path path;
539 TreeViewColumn* column;
543 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
547 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
549 if ((iter = route_display_model->get_iter (path))) {
550 TimeAxisView* tv = (*iter)[route_display_columns.tv];
552 bool visible = (*iter)[route_display_columns.visible];
553 (*iter)[route_display_columns.visible] = !visible;
559 /* allow normal processing to occur */
570 Editor::show_route_list_menu()
572 if (route_list_menu == 0) {
573 build_route_list_menu ();
576 route_list_menu->popup (1, gtk_get_current_event_time());
580 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
585 struct EditorOrderRouteSorter {
586 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
587 /* use of ">" forces the correct sort order */
588 return a->order_key (_order_key) < b->order_key (_order_key);
593 Editor::initial_route_list_display ()
595 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
596 Session::RouteList r (*routes);
597 EditorOrderRouteSorter sorter;
601 no_route_list_redisplay = true;
603 route_display_model->clear ();
605 handle_new_route (r);
607 no_route_list_redisplay = false;
609 redisplay_route_list ();
613 Editor::track_list_reorder (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter, int* new_order)
615 route_redisplay_does_not_sync_order_keys = true;
616 session->set_remote_control_ids();
617 redisplay_route_list ();
618 route_redisplay_does_not_sync_order_keys = false;
622 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
624 /* never reset order keys because of a property change */
625 route_redisplay_does_not_reset_order_keys = true;
626 session->set_remote_control_ids();
627 redisplay_route_list ();
628 route_redisplay_does_not_reset_order_keys = false;
632 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
634 /* this could require an order reset & sync */
635 session->set_remote_control_ids();
636 ignore_route_list_reorder = true;
637 redisplay_route_list ();
638 ignore_route_list_reorder = false;
642 Editor::route_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
644 const SelectionData& data,
645 guint info, guint time)
647 if (data.get_target() == "GTK_TREE_MODEL_ROW") {
648 route_list_display.on_drag_data_received (context, x, y, data, info, time);
651 context->drag_finish (true, false, time);
655 Editor::get_route_view_by_id (PBD::ID& id)
657 RouteTimeAxisView* v;
659 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
660 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
661 if(v->route()->id() == id) {
671 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
673 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
679 Editor::move_selected_tracks (bool up)
681 if (selection->tracks.empty()) {
685 typedef std::pair<TimeAxisView*,boost::shared_ptr<Route> > ViewRoute;
686 std::list<ViewRoute> view_routes;
687 std::vector<int> neworder;
688 TreeModel::Children rows = route_display_model->children();
689 TreeModel::Children::iterator ri;
691 for (ri = rows.begin(); ri != rows.end(); ++ri) {
692 TimeAxisView* tv = (*ri)[route_display_columns.tv];
693 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
695 view_routes.push_back (ViewRoute (tv, route));
698 list<ViewRoute>::iterator trailing;
699 list<ViewRoute>::iterator leading;
703 trailing = view_routes.begin();
704 leading = view_routes.begin();
708 while (leading != view_routes.end()) {
709 if (selection->selected (leading->first)) {
710 view_routes.insert (trailing, ViewRoute (leading->first, leading->second));
711 leading = view_routes.erase (leading);
720 /* if we could use reverse_iterator in list::insert, this code
721 would be a beautiful reflection of the code above. but we can't
722 and so it looks like a bit of a mess.
725 trailing = view_routes.end();
726 leading = view_routes.end();
728 --leading; if (leading == view_routes.begin()) { return; }
734 if (selection->selected (leading->first)) {
735 list<ViewRoute>::iterator tmp;
737 /* need to insert *after* trailing, not *before* it,
738 which is what insert (iter, val) normally does.
744 view_routes.insert (tmp, ViewRoute (leading->first, leading->second));
746 /* can't use iter = cont.erase (iter); form here, because
747 we need iter to move backwards.
755 if (leading == view_routes.begin()) {
756 /* the one we've just inserted somewhere else
757 was the first in the list. erase this copy,
758 and then break, because we're done.
763 view_routes.erase (leading);
772 if (leading == view_routes.begin()) {
781 for (leading = view_routes.begin(); leading != view_routes.end(); ++leading) {
782 neworder.push_back (leading->second->order_key (_order_key));
785 route_display_model->reorder (neworder);
787 session->sync_order_keys (_order_key);