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 redisplay_route_list ();
157 Editor::remove_route (TimeAxisView *tv)
159 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
161 TrackViewList::iterator i;
162 TreeModel::Children rows = route_display_model->children();
163 TreeModel::Children::iterator ri;
165 /* Decrement old order keys for tracks `above' the one that is being removed */
166 for (ri = rows.begin(); ri != rows.end(); ++ri) {
167 TimeAxisView* v = (*ri)[route_display_columns.tv];
168 if (v->old_order_key() > tv->old_order_key()) {
169 v->set_old_order_key (v->old_order_key() - 1);
173 for (ri = rows.begin(); ri != rows.end(); ++ri) {
174 if ((*ri)[route_display_columns.tv] == tv) {
175 route_display_model->erase (ri);
180 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
181 track_views.erase (i);
184 /* since the editor mixer goes away when you remove a route, set the
185 * button to inactive and untick the menu option
188 editor_mixer_button.set_active(false);
189 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
191 /* and disable if all tracks and/or routes are gone */
193 if (track_views.size() == 0) {
194 editor_mixer_button.set_sensitive(false);
199 Editor::route_name_changed (TimeAxisView *tv)
201 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
203 TreeModel::Children rows = route_display_model->children();
204 TreeModel::Children::iterator i;
206 for (i = rows.begin(); i != rows.end(); ++i) {
207 if ((*i)[route_display_columns.tv] == tv) {
208 (*i)[route_display_columns.text] = tv->name();
216 Editor::hide_track_in_display (TimeAxisView& tv)
218 TreeModel::Children rows = route_display_model->children();
219 TreeModel::Children::iterator i;
221 for (i = rows.begin(); i != rows.end(); ++i) {
222 if ((*i)[route_display_columns.tv] == &tv) {
223 (*i)[route_display_columns.visible] = false;
228 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
230 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
231 // this will hide the mixer strip
232 set_selected_mixer_strip (tv);
237 Editor::show_track_in_display (TimeAxisView& tv)
239 TreeModel::Children rows = route_display_model->children();
240 TreeModel::Children::iterator i;
242 for (i = rows.begin(); i != rows.end(); ++i) {
243 if ((*i)[route_display_columns.tv] == &tv) {
244 (*i)[route_display_columns.visible] = true;
245 tv.set_marked_for_display (true);
252 Editor::route_list_reordered (const TreeModel::Path& path,const TreeModel::iterator& iter,int* what)
254 redisplay_route_list ();
259 Editor::sync_order_keys ()
261 vector<int> neworder;
262 TreeModel::Children rows = route_display_model->children();
263 TreeModel::Children::iterator ri;
265 if (ignore_route_order_sync || !session || (session->state_of_the_state() & Session::Loading) || rows.empty()) {
269 for (ri = rows.begin(); ri != rows.end(); ++ri) {
270 neworder.push_back (0);
273 for (ri = rows.begin(); ri != rows.end(); ++ri) {
274 TimeAxisView* tv = (*ri)[route_display_columns.tv];
275 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
276 neworder[route->order_key (X_("editor"))] = tv->old_order_key ();
279 ignore_route_list_reorder = true;
280 route_display_model->reorder (neworder);
281 ignore_route_list_reorder = false;
285 Editor::redisplay_route_list ()
287 TreeModel::Children rows = route_display_model->children();
288 TreeModel::Children::iterator i;
293 if (no_route_list_redisplay) {
297 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
298 TimeAxisView *tv = (*i)[route_display_columns.tv];
299 RouteTimeAxisView* rt;
302 // just a "title" row
306 if (!ignore_route_list_reorder) {
308 /* this reorder is caused by user action, so reassign sort order keys
312 if ((rt = dynamic_cast<RouteTimeAxisView*> (tv)) != 0) {
313 rt->route()->set_order_key (N_("editor"), order);
318 bool visible = (*i)[route_display_columns.visible];
321 tv->set_marked_for_display (true);
322 position += tv->show_at (position, n, &edit_controls_vbox);
331 full_canvas_height = position;
333 /* make sure the cursors stay on top of every newly added track */
335 cursor_group->raise_to_top ();
337 reset_scrolling_region ();
339 if (Config->get_sync_all_route_ordering() && !ignore_route_list_reorder) {
340 ignore_route_order_sync = true;
341 Route::SyncOrderKeys (); // EMIT SIGNAL
342 ignore_route_order_sync = false;
348 Editor::hide_all_tracks (bool with_select)
350 TreeModel::Children rows = route_display_model->children();
351 TreeModel::Children::iterator i;
353 no_route_list_redisplay = true;
355 for (i = rows.begin(); i != rows.end(); ++i) {
357 TreeModel::Row row = (*i);
358 TimeAxisView *tv = row[route_display_columns.tv];
364 row[route_display_columns.visible] = false;
367 no_route_list_redisplay = false;
368 redisplay_route_list ();
370 /* XXX this seems like a hack and half, but its not clear where to put this
374 reset_scrolling_region ();
378 Editor::build_route_list_menu ()
380 using namespace Menu_Helpers;
383 route_list_menu = new Menu;
385 MenuList& items = route_list_menu->items();
386 route_list_menu->set_name ("ArdourContextMenu");
388 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
389 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
390 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
391 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
392 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
393 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
398 Editor::set_all_tracks_visibility (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) {
407 TreeModel::Row row = (*i);
408 TimeAxisView* tv = row[route_display_columns.tv];
414 (*i)[route_display_columns.visible] = yn;
417 no_route_list_redisplay = false;
418 redisplay_route_list ();
422 Editor::set_all_audio_visibility (int tracks, bool yn)
424 TreeModel::Children rows = route_display_model->children();
425 TreeModel::Children::iterator i;
427 no_route_list_redisplay = true;
429 for (i = rows.begin(); i != rows.end(); ++i) {
430 TreeModel::Row row = (*i);
431 TimeAxisView* tv = row[route_display_columns.tv];
432 AudioTimeAxisView* atv;
438 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
441 (*i)[route_display_columns.visible] = yn;
445 if (atv->is_audio_track()) {
446 (*i)[route_display_columns.visible] = yn;
451 if (!atv->is_audio_track()) {
452 (*i)[route_display_columns.visible] = yn;
459 no_route_list_redisplay = false;
460 redisplay_route_list ();
464 Editor::hide_all_routes ()
466 set_all_tracks_visibility (false);
470 Editor::show_all_routes ()
472 set_all_tracks_visibility (true);
476 Editor::show_all_audiobus ()
478 set_all_audio_visibility (2, true);
481 Editor::hide_all_audiobus ()
483 set_all_audio_visibility (2, false);
487 Editor::show_all_audiotracks()
489 set_all_audio_visibility (1, true);
492 Editor::hide_all_audiotracks ()
494 set_all_audio_visibility (1, false);
498 Editor::route_list_display_button_press (GdkEventButton* ev)
500 if (Keyboard::is_context_menu_event (ev)) {
501 show_route_list_menu ();
506 TreeModel::Path path;
507 TreeViewColumn* column;
511 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
515 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
517 if ((iter = route_display_model->get_iter (path))) {
518 TimeAxisView* tv = (*iter)[route_display_columns.tv];
520 bool visible = (*iter)[route_display_columns.visible];
521 (*iter)[route_display_columns.visible] = !visible;
527 /* allow normal processing to occur */
538 Editor::show_route_list_menu()
540 if (route_list_menu == 0) {
541 build_route_list_menu ();
544 route_list_menu->popup (1, gtk_get_current_event_time());
548 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
553 struct EditorOrderRouteSorter {
554 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
555 /* use of ">" forces the correct sort order */
556 return a->order_key ("editor") < b->order_key ("editor");
561 Editor::initial_route_list_display ()
563 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
564 Session::RouteList r (*routes);
565 EditorOrderRouteSorter sorter;
569 no_route_list_redisplay = true;
571 route_display_model->clear ();
573 handle_new_route (r);
575 no_route_list_redisplay = false;
577 redisplay_route_list ();
581 Editor::track_list_reorder (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter, int* new_order)
583 session->set_remote_control_ids();
584 redisplay_route_list ();
588 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
590 session->set_remote_control_ids();
591 redisplay_route_list ();
595 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
597 session->set_remote_control_ids();
598 redisplay_route_list ();
603 Editor::route_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
605 const SelectionData& data,
606 guint info, guint time)
608 cerr << "RouteLD::dddr target = " << data.get_target() << endl;
610 if (data.get_target() == "GTK_TREE_MODEL_ROW") {
611 cerr << "Delete drag data drop to treeview\n";
612 route_list_display.on_drag_data_received (context, x, y, data, info, time);
615 cerr << "some other kind of drag\n";
616 context->drag_finish (true, false, time);
621 Editor::get_route_view_by_id (PBD::ID& id)
623 RouteTimeAxisView* v;
625 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
626 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
627 if(v->route()->id() == id) {
637 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
639 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {