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 // cerr << route->name() << " marked for display ? " << tv->marked_for_display() << endl;
108 row[route_display_columns.text] = route->name();
109 row[route_display_columns.visible] = tv->marked_for_display();
110 row[route_display_columns.tv] = tv;
111 row[route_display_columns.route] = route;
113 track_views.push_back (tv);
115 ignore_route_list_reorder = true;
117 if ((rtv = dynamic_cast<RouteTimeAxisView*> (tv)) != 0) {
118 /* added a new fresh one at the end */
119 if (rtv->route()->order_key(N_("editor")) == -1) {
120 rtv->route()->set_order_key (N_("editor"), route_display_model->children().size()-1);
122 rtv->effective_gain_display ();
125 ignore_route_list_reorder = false;
127 tv->set_old_order_key (route_display_model->children().size() - 1);
128 route->gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes));
130 tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv));
133 ignore_route_list_reorder = false;
134 ignore_route_order_sync = false;
135 no_route_list_redisplay = false;
137 redisplay_route_list ();
139 if (show_editor_mixer_when_tracks_arrive) {
140 show_editor_mixer (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 /* Optional :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 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
203 Editor::route_name_changed (TimeAxisView *tv)
205 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
207 TreeModel::Children rows = route_display_model->children();
208 TreeModel::Children::iterator i;
210 for (i = rows.begin(); i != rows.end(); ++i) {
211 if ((*i)[route_display_columns.tv] == tv) {
212 (*i)[route_display_columns.text] = tv->name();
219 Editor::update_route_visibility ()
221 TreeModel::Children rows = route_display_model->children();
222 TreeModel::Children::iterator i;
224 no_route_list_redisplay = true;
226 for (i = rows.begin(); i != rows.end(); ++i) {
227 TimeAxisView *tv = (*i)[route_display_columns.tv];
228 (*i)[route_display_columns.visible] = tv->marked_for_display ();
229 cerr << "marked " << tv->name() << " for display = " << tv->marked_for_display() << endl;
232 no_route_list_redisplay = false;
233 redisplay_route_list ();
237 Editor::hide_track_in_display (TimeAxisView& tv, bool temponly)
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] = false;
246 tv.set_marked_for_display (false);
252 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&tv);
254 if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
255 // this will hide the mixer strip
256 set_selected_mixer_strip (tv);
261 Editor::show_track_in_display (TimeAxisView& tv)
263 TreeModel::Children rows = route_display_model->children();
264 TreeModel::Children::iterator i;
266 for (i = rows.begin(); i != rows.end(); ++i) {
267 if ((*i)[route_display_columns.tv] == &tv) {
268 (*i)[route_display_columns.visible] = true;
269 tv.set_marked_for_display (true);
276 Editor::route_list_reordered (const TreeModel::Path& path,const TreeModel::iterator& iter,int* what)
278 redisplay_route_list ();
283 Editor::sync_order_keys ()
285 vector<int> neworder;
286 TreeModel::Children rows = route_display_model->children();
287 TreeModel::Children::iterator ri;
289 if (ignore_route_order_sync || !session || (session->state_of_the_state() & Session::Loading) || rows.empty()) {
293 for (ri = rows.begin(); ri != rows.end(); ++ri) {
294 neworder.push_back (0);
297 for (ri = rows.begin(); ri != rows.end(); ++ri) {
298 TimeAxisView* tv = (*ri)[route_display_columns.tv];
299 boost::shared_ptr<Route> route = (*ri)[route_display_columns.route];
300 neworder[route->order_key (X_("editor"))] = tv->old_order_key ();
303 ignore_route_list_reorder = true;
304 route_display_model->reorder (neworder);
305 ignore_route_list_reorder = false;
309 Editor::redisplay_route_list ()
311 TreeModel::Children rows = route_display_model->children();
312 TreeModel::Children::iterator i;
317 if (no_route_list_redisplay) {
321 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
322 TimeAxisView *tv = (*i)[route_display_columns.tv];
323 RouteTimeAxisView* rt;
326 // just a "title" row
330 if (!ignore_route_list_reorder) {
332 /* this reorder is caused by user action, so reassign sort order keys
336 if ((rt = dynamic_cast<RouteTimeAxisView*> (tv)) != 0) {
337 rt->route()->set_order_key (N_("editor"), order);
342 bool visible = (*i)[route_display_columns.visible];
345 tv->set_marked_for_display (true);
346 position += tv->show_at (position, n, &edit_controls_vbox);
347 tv->clip_to_viewport ();
349 tv->set_marked_for_display (false);
357 full_canvas_height = position + canvas_timebars_vsize;
358 vertical_adjustment.set_upper (full_canvas_height);
359 if ((vertical_adjustment.get_value() + canvas_height) > vertical_adjustment.get_upper()) {
361 We're increasing the size of the canvas while the bottom is visible.
362 We scroll down to keep in step with the controls layout.
364 vertical_adjustment.set_value (full_canvas_height - canvas_height);
367 if (Config->get_sync_all_route_ordering() && !ignore_route_list_reorder) {
368 ignore_route_order_sync = true;
369 Route::SyncOrderKeys (); // EMIT SIGNAL
370 ignore_route_order_sync = false;
376 Editor::hide_all_tracks (bool with_select)
378 TreeModel::Children rows = route_display_model->children();
379 TreeModel::Children::iterator i;
381 no_route_list_redisplay = true;
383 for (i = rows.begin(); i != rows.end(); ++i) {
385 TreeModel::Row row = (*i);
386 TimeAxisView *tv = row[route_display_columns.tv];
392 row[route_display_columns.visible] = false;
395 no_route_list_redisplay = false;
396 redisplay_route_list ();
398 /* XXX this seems like a hack and half, but its not clear where to put this
402 //reset_scrolling_region ();
406 Editor::build_route_list_menu ()
408 using namespace Menu_Helpers;
411 route_list_menu = new Menu;
413 MenuList& items = route_list_menu->items();
414 route_list_menu->set_name ("ArdourContextMenu");
416 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
417 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
418 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
419 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
420 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
421 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
426 Editor::set_all_tracks_visibility (bool yn)
428 TreeModel::Children rows = route_display_model->children();
429 TreeModel::Children::iterator i;
431 no_route_list_redisplay = true;
433 for (i = rows.begin(); i != rows.end(); ++i) {
435 TreeModel::Row row = (*i);
436 TimeAxisView* tv = row[route_display_columns.tv];
442 (*i)[route_display_columns.visible] = yn;
445 no_route_list_redisplay = false;
446 redisplay_route_list ();
450 Editor::set_all_audio_visibility (int tracks, bool yn)
452 TreeModel::Children rows = route_display_model->children();
453 TreeModel::Children::iterator i;
455 no_route_list_redisplay = true;
457 for (i = rows.begin(); i != rows.end(); ++i) {
458 TreeModel::Row row = (*i);
459 TimeAxisView* tv = row[route_display_columns.tv];
460 AudioTimeAxisView* atv;
466 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
469 (*i)[route_display_columns.visible] = yn;
473 if (atv->is_audio_track()) {
474 (*i)[route_display_columns.visible] = yn;
479 if (!atv->is_audio_track()) {
480 (*i)[route_display_columns.visible] = yn;
487 no_route_list_redisplay = false;
488 redisplay_route_list ();
492 Editor::hide_all_routes ()
494 set_all_tracks_visibility (false);
498 Editor::show_all_routes ()
500 set_all_tracks_visibility (true);
504 Editor::show_all_audiobus ()
506 set_all_audio_visibility (2, true);
509 Editor::hide_all_audiobus ()
511 set_all_audio_visibility (2, false);
515 Editor::show_all_audiotracks()
517 set_all_audio_visibility (1, true);
520 Editor::hide_all_audiotracks ()
522 set_all_audio_visibility (1, false);
526 Editor::route_list_display_button_press (GdkEventButton* ev)
528 if (Keyboard::is_context_menu_event (ev)) {
529 show_route_list_menu ();
534 TreeModel::Path path;
535 TreeViewColumn* column;
539 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
543 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
545 if ((iter = route_display_model->get_iter (path))) {
546 TimeAxisView* tv = (*iter)[route_display_columns.tv];
548 bool visible = (*iter)[route_display_columns.visible];
549 (*iter)[route_display_columns.visible] = !visible;
555 /* allow normal processing to occur */
566 Editor::show_route_list_menu()
568 if (route_list_menu == 0) {
569 build_route_list_menu ();
572 route_list_menu->popup (1, gtk_get_current_event_time());
576 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
581 struct EditorOrderRouteSorter {
582 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
583 /* use of ">" forces the correct sort order */
584 return a->order_key ("editor") < b->order_key ("editor");
589 Editor::initial_route_list_display ()
591 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
592 Session::RouteList r (*routes);
593 EditorOrderRouteSorter sorter;
597 no_route_list_redisplay = true;
599 route_display_model->clear ();
601 handle_new_route (r);
603 no_route_list_redisplay = false;
605 redisplay_route_list ();
609 Editor::track_list_reorder (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter, int* new_order)
611 session->set_remote_control_ids();
612 redisplay_route_list ();
616 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
618 session->set_remote_control_ids();
619 redisplay_route_list ();
623 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
625 session->set_remote_control_ids();
626 ignore_route_list_reorder = true;
627 redisplay_route_list ();
628 ignore_route_list_reorder = false;
632 Editor::route_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
634 const SelectionData& data,
635 guint info, guint time)
637 cerr << "RouteLD::dddr target = " << data.get_target() << endl;
639 if (data.get_target() == "GTK_TREE_MODEL_ROW") {
640 cerr << "Delete drag data drop to treeview\n";
641 route_list_display.on_drag_data_received (context, x, y, data, info, time);
644 cerr << "some other kind of drag\n";
645 context->drag_finish (true, false, time);
649 Editor::get_route_view_by_id (PBD::ID& id)
651 RouteTimeAxisView* v;
653 for(TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
654 if((v = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
655 if(v->route()->id() == id) {
665 Editor::foreach_time_axis_view (sigc::slot<void,TimeAxisView&> theslot)
667 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {