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.
26 #include "ardour_ui.h"
27 #include "audio_time_axis.h"
28 #include "mixer_strip.h"
29 #include "gui_thread.h"
32 #include <ardour/route.h>
33 #include <ardour/audio_track.h>
38 using namespace ARDOUR;
43 Editor::handle_new_route (Session::RouteList& routes)
45 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route), routes));
48 AudioTimeAxisView *atv;
49 TreeModel::Row parent;
52 for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
53 boost::shared_ptr<Route> route = (*x);
55 if (route->hidden()) {
59 tv = new AudioTimeAxisView (*this, *session, route, track_canvas);
62 if (route_display_model->children().size() == 0) {
64 /* set up basic entries */
68 row = *(route_display_model->append()); // path = "0"
69 row[route_display_columns.text] = _("Busses");
70 row[route_display_columns.tv] = 0;
71 row = *(route_display_model->append()); // path = "1"
72 row[route_display_columns.text] = _("Tracks");
73 row[route_display_columns.tv] = 0;
77 if (dynamic_cast<AudioTrack*>(route.get()) != 0) {
78 TreeModel::iterator iter = route_display_model->get_iter ("1"); // audio tracks
81 TreeModel::iterator iter = route_display_model->get_iter ("0"); // busses
86 row = *(route_display_model->append (parent.children()));
88 row = *(route_display_model->append ());
91 row[route_display_columns.text] = route->name();
92 row[route_display_columns.visible] = tv->marked_for_display();
93 row[route_display_columns.tv] = tv;
95 track_views.push_back (tv);
97 ignore_route_list_reorder = true;
99 if ((atv = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
100 /* added a new fresh one at the end */
101 if (atv->route()->order_key(N_("editor")) == -1) {
102 atv->route()->set_order_key (N_("editor"), route_display_model->children().size()-1);
106 ignore_route_list_reorder = false;
108 route->gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes));
110 tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv));
113 if (show_editor_mixer_when_tracks_arrive) {
114 show_editor_mixer (true);
117 editor_mixer_button.set_sensitive(true);
121 Editor::handle_gui_changes (const string & what, void *src)
123 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
125 if (what == "track_height") {
126 redisplay_route_list ();
132 Editor::remove_route (TimeAxisView *tv)
134 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
137 TrackViewList::iterator i;
138 TreeModel::Children rows = route_display_model->children();
139 TreeModel::Children::iterator ri;
141 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
142 track_views.erase (i);
145 for (ri = rows.begin(); ri != rows.end(); ++ri) {
146 if ((*ri)[route_display_columns.tv] == tv) {
147 route_display_model->erase (ri);
151 /* since the editor mixer goes away when you remove a route, set the
152 * button to inactive and untick the menu option
154 editor_mixer_button.set_active(false);
155 ActionManager::uncheck_toggleaction ("<Actions>/Editor/show-editor-mixer");
157 /* and disable if all tracks and/or routes are gone */
159 if (track_views.size() == 0) {
160 editor_mixer_button.set_sensitive(false);
165 Editor::route_name_changed (TimeAxisView *tv)
167 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
169 TreeModel::Children rows = route_display_model->children();
170 TreeModel::Children::iterator i;
172 for (i = rows.begin(); i != rows.end(); ++i) {
173 if ((*i)[route_display_columns.tv] == tv) {
174 (*i)[route_display_columns.text] = tv->name();
182 Editor::hide_track_in_display (TimeAxisView& tv)
184 TreeModel::Children rows = route_display_model->children();
185 TreeModel::Children::iterator i;
187 for (i = rows.begin(); i != rows.end(); ++i) {
188 if ((*i)[route_display_columns.tv] == &tv) {
189 (*i)[route_display_columns.visible] = false;
194 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
196 if (atv && current_mixer_strip && (atv->route() == current_mixer_strip->route())) {
197 // this will hide the mixer strip
198 set_selected_mixer_strip (tv);
203 Editor::show_track_in_display (TimeAxisView& tv)
205 TreeModel::Children rows = route_display_model->children();
206 TreeModel::Children::iterator i;
208 for (i = rows.begin(); i != rows.end(); ++i) {
209 if ((*i)[route_display_columns.tv] == &tv) {
210 (*i)[route_display_columns.visible] = true;
211 tv.set_marked_for_display (true);
218 Editor::route_list_reordered (const TreeModel::Path& path,const TreeModel::iterator& iter,int* what)
220 redisplay_route_list ();
224 Editor::redisplay_route_list ()
226 TreeModel::Children rows = route_display_model->children();
227 TreeModel::Children::iterator i;
232 if (no_route_list_redisplay) {
236 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
237 TimeAxisView *tv = (*i)[route_display_columns.tv];
238 AudioTimeAxisView* at;
241 // just a "title" row
245 if (!ignore_route_list_reorder) {
247 /* this reorder is caused by user action, so reassign sort order keys
251 if ((at = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
252 at->route()->set_order_key (N_("editor"), order);
257 bool visible = (*i)[route_display_columns.visible];
260 tv->set_marked_for_display (true);
261 position += tv->show_at (position, n, &edit_controls_vbox);
262 position += track_spacing;
271 full_canvas_height = position;
273 /* make sure the cursors stay on top of every newly added track */
275 cursor_group->raise_to_top ();
277 reset_scrolling_region ();
281 Editor::hide_all_tracks (bool with_select)
283 TreeModel::Children rows = route_display_model->children();
284 TreeModel::Children::iterator i;
286 no_route_list_redisplay = true;
288 for (i = rows.begin(); i != rows.end(); ++i) {
290 TreeModel::Row row = (*i);
291 TimeAxisView *tv = row[route_display_columns.tv];
297 row[route_display_columns.visible] = false;
300 no_route_list_redisplay = false;
301 redisplay_route_list ();
303 /* XXX this seems like a hack and half, but its not clear where to put this
307 reset_scrolling_region ();
311 Editor::build_route_list_menu ()
313 using namespace Menu_Helpers;
316 route_list_menu = new Menu;
318 MenuList& items = route_list_menu->items();
319 route_list_menu->set_name ("ArdourContextMenu");
321 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
322 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
323 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
324 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
325 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
326 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
331 Editor::set_all_tracks_visibility (bool yn)
333 TreeModel::Children rows = route_display_model->children();
334 TreeModel::Children::iterator i;
336 no_route_list_redisplay = true;
338 for (i = rows.begin(); i != rows.end(); ++i) {
340 TreeModel::Row row = (*i);
341 TimeAxisView* tv = row[route_display_columns.tv];
347 (*i)[route_display_columns.visible] = yn;
350 no_route_list_redisplay = false;
351 redisplay_route_list ();
355 Editor::set_all_audio_visibility (int tracks, bool yn)
357 TreeModel::Children rows = route_display_model->children();
358 TreeModel::Children::iterator i;
360 no_route_list_redisplay = true;
362 for (i = rows.begin(); i != rows.end(); ++i) {
363 TreeModel::Row row = (*i);
364 TimeAxisView* tv = row[route_display_columns.tv];
365 AudioTimeAxisView* atv;
371 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
374 (*i)[route_display_columns.visible] = yn;
378 if (atv->is_audio_track()) {
379 (*i)[route_display_columns.visible] = yn;
384 if (!atv->is_audio_track()) {
385 (*i)[route_display_columns.visible] = yn;
392 no_route_list_redisplay = false;
393 redisplay_route_list ();
397 Editor::hide_all_routes ()
399 set_all_tracks_visibility (false);
403 Editor::show_all_routes ()
405 set_all_tracks_visibility (true);
409 Editor::show_all_audiobus ()
411 set_all_audio_visibility (2, true);
414 Editor::hide_all_audiobus ()
416 set_all_audio_visibility (2, false);
420 Editor::show_all_audiotracks()
422 set_all_audio_visibility (1, true);
425 Editor::hide_all_audiotracks ()
427 set_all_audio_visibility (1, false);
431 Editor::route_list_display_button_press (GdkEventButton* ev)
433 if (Keyboard::is_context_menu_event (ev)) {
434 show_route_list_menu ();
439 TreeModel::Path path;
440 TreeViewColumn* column;
444 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
448 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
450 if ((iter = route_display_model->get_iter (path))) {
451 TimeAxisView* tv = (*iter)[route_display_columns.tv];
453 bool visible = (*iter)[route_display_columns.visible];
454 (*iter)[route_display_columns.visible] = !visible;
460 /* allow normal processing to occur */
471 Editor::show_route_list_menu()
473 if (route_list_menu == 0) {
474 build_route_list_menu ();
477 route_list_menu->popup (1, gtk_get_current_event_time());
481 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
486 struct EditorOrderRouteSorter {
487 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
488 /* use of ">" forces the correct sort order */
489 return a->order_key ("editor") < b->order_key ("editor");
494 Editor::initial_route_list_display ()
496 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
497 Session::RouteList r (*routes);
498 EditorOrderRouteSorter sorter;
502 no_route_list_redisplay = true;
504 route_display_model->clear ();
506 handle_new_route (r);
508 no_route_list_redisplay = false;
510 redisplay_route_list ();
514 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
516 session->set_remote_control_ids();
517 redisplay_route_list ();
521 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
523 session->set_remote_control_ids();
524 redisplay_route_list ();