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"
31 #include <ardour/route.h>
32 #include <ardour/audio_track.h>
37 using namespace ARDOUR;
42 Editor::handle_new_route (Session::RouteList& routes)
44 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route), routes));
47 AudioTimeAxisView *atv;
48 TreeModel::Row parent;
51 for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
52 boost::shared_ptr<Route> route = (*x);
54 if (route->hidden()) {
58 tv = new AudioTimeAxisView (*this, *session, route, track_canvas);
61 if (route_display_model->children().size() == 0) {
63 /* set up basic entries */
67 row = *(route_display_model->append()); // path = "0"
68 row[route_display_columns.text] = _("Busses");
69 row[route_display_columns.tv] = 0;
70 row = *(route_display_model->append()); // path = "1"
71 row[route_display_columns.text] = _("Tracks");
72 row[route_display_columns.tv] = 0;
76 if (dynamic_cast<AudioTrack*>(route.get()) != 0) {
77 TreeModel::iterator iter = route_display_model->get_iter ("1"); // audio tracks
80 TreeModel::iterator iter = route_display_model->get_iter ("0"); // busses
85 row = *(route_display_model->append (parent.children()));
87 row = *(route_display_model->append ());
90 row[route_display_columns.text] = route->name();
91 row[route_display_columns.visible] = tv->marked_for_display();
92 row[route_display_columns.tv] = tv;
94 track_views.push_back (tv);
96 ignore_route_list_reorder = true;
98 if ((atv = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
99 /* added a new fresh one at the end */
100 if (atv->route()->order_key(N_("editor")) == -1) {
101 atv->route()->set_order_key (N_("editor"), route_display_model->children().size()-1);
105 ignore_route_list_reorder = false;
107 route->gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes));
109 tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv));
112 if (show_editor_mixer_when_tracks_arrive) {
113 show_editor_mixer (true);
116 editor_mixer_button.set_sensitive(true);
120 Editor::handle_gui_changes (const string & what, void *src)
122 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
124 if (what == "track_height") {
125 redisplay_route_list ();
131 Editor::remove_route (TimeAxisView *tv)
133 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
136 TrackViewList::iterator i;
137 TreeModel::Children rows = route_display_model->children();
138 TreeModel::Children::iterator ri;
140 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
141 track_views.erase (i);
144 for (ri = rows.begin(); ri != rows.end(); ++ri) {
145 if ((*ri)[route_display_columns.tv] == tv) {
146 route_display_model->erase (ri);
150 /* since the editor mixer goes away when you remove a route, set the
151 * button to inacttive
153 editor_mixer_button.set_active(false);
155 /* and disable if all tracks and/or routes are gone */
157 if (track_views.size() == 0) {
158 editor_mixer_button.set_sensitive(false);
163 Editor::route_name_changed (TimeAxisView *tv)
165 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
167 TreeModel::Children rows = route_display_model->children();
168 TreeModel::Children::iterator i;
170 for (i = rows.begin(); i != rows.end(); ++i) {
171 if ((*i)[route_display_columns.tv] == tv) {
172 (*i)[route_display_columns.text] = tv->name();
180 Editor::hide_track_in_display (TimeAxisView& tv)
182 TreeModel::Children rows = route_display_model->children();
183 TreeModel::Children::iterator i;
185 for (i = rows.begin(); i != rows.end(); ++i) {
186 if ((*i)[route_display_columns.tv] == &tv) {
187 (*i)[route_display_columns.visible] = false;
192 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
194 if (atv && current_mixer_strip && (atv->route() == current_mixer_strip->route())) {
195 // this will hide the mixer strip
196 set_selected_mixer_strip (tv);
201 Editor::show_track_in_display (TimeAxisView& 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.visible] = true;
209 tv.set_marked_for_display (true);
216 Editor::route_list_reordered (const TreeModel::Path& path,const TreeModel::iterator& iter,int* what)
218 redisplay_route_list ();
222 Editor::redisplay_route_list ()
224 TreeModel::Children rows = route_display_model->children();
225 TreeModel::Children::iterator i;
230 if (no_route_list_redisplay) {
234 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
235 TimeAxisView *tv = (*i)[route_display_columns.tv];
236 AudioTimeAxisView* at;
239 // just a "title" row
243 if (!ignore_route_list_reorder) {
245 /* this reorder is caused by user action, so reassign sort order keys
249 if ((at = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
250 at->route()->set_order_key (N_("editor"), order);
255 bool visible = (*i)[route_display_columns.visible];
258 tv->set_marked_for_display (true);
259 position += tv->show_at (position, n, &edit_controls_vbox);
260 position += track_spacing;
269 full_canvas_height = position;
271 /* make sure the cursors stay on top of every newly added track */
273 cursor_group->raise_to_top ();
275 reset_scrolling_region ();
279 Editor::hide_all_tracks (bool with_select)
281 TreeModel::Children rows = route_display_model->children();
282 TreeModel::Children::iterator i;
284 no_route_list_redisplay = true;
286 for (i = rows.begin(); i != rows.end(); ++i) {
288 TreeModel::Row row = (*i);
289 TimeAxisView *tv = row[route_display_columns.tv];
295 row[route_display_columns.visible] = false;
298 no_route_list_redisplay = false;
299 redisplay_route_list ();
301 /* XXX this seems like a hack and half, but its not clear where to put this
305 reset_scrolling_region ();
309 Editor::build_route_list_menu ()
311 using namespace Menu_Helpers;
314 route_list_menu = new Menu;
316 MenuList& items = route_list_menu->items();
317 route_list_menu->set_name ("ArdourContextMenu");
319 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
320 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
321 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
322 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
323 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
324 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
329 Editor::set_all_tracks_visibility (bool yn)
331 TreeModel::Children rows = route_display_model->children();
332 TreeModel::Children::iterator i;
334 no_route_list_redisplay = true;
336 for (i = rows.begin(); i != rows.end(); ++i) {
338 TreeModel::Row row = (*i);
339 TimeAxisView* tv = row[route_display_columns.tv];
345 (*i)[route_display_columns.visible] = yn;
348 no_route_list_redisplay = false;
349 redisplay_route_list ();
353 Editor::set_all_audio_visibility (int tracks, bool yn)
355 TreeModel::Children rows = route_display_model->children();
356 TreeModel::Children::iterator i;
358 no_route_list_redisplay = true;
360 for (i = rows.begin(); i != rows.end(); ++i) {
361 TreeModel::Row row = (*i);
362 TimeAxisView* tv = row[route_display_columns.tv];
363 AudioTimeAxisView* atv;
369 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
372 (*i)[route_display_columns.visible] = yn;
376 if (atv->is_audio_track()) {
377 (*i)[route_display_columns.visible] = yn;
382 if (!atv->is_audio_track()) {
383 (*i)[route_display_columns.visible] = yn;
390 no_route_list_redisplay = false;
391 redisplay_route_list ();
395 Editor::hide_all_routes ()
397 set_all_tracks_visibility (false);
401 Editor::show_all_routes ()
403 set_all_tracks_visibility (true);
407 Editor::show_all_audiobus ()
409 set_all_audio_visibility (2, true);
412 Editor::hide_all_audiobus ()
414 set_all_audio_visibility (2, false);
418 Editor::show_all_audiotracks()
420 set_all_audio_visibility (1, true);
423 Editor::hide_all_audiotracks ()
425 set_all_audio_visibility (1, false);
429 Editor::route_list_display_button_press (GdkEventButton* ev)
431 if (Keyboard::is_context_menu_event (ev)) {
432 show_route_list_menu ();
437 TreeModel::Path path;
438 TreeViewColumn* column;
442 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
446 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
448 if ((iter = route_display_model->get_iter (path))) {
449 TimeAxisView* tv = (*iter)[route_display_columns.tv];
451 bool visible = (*iter)[route_display_columns.visible];
452 (*iter)[route_display_columns.visible] = !visible;
458 /* allow normal processing to occur */
469 Editor::show_route_list_menu()
471 if (route_list_menu == 0) {
472 build_route_list_menu ();
475 route_list_menu->popup (1, gtk_get_current_event_time());
479 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
484 struct EditorOrderRouteSorter {
485 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
486 /* use of ">" forces the correct sort order */
487 return a->order_key ("editor") < b->order_key ("editor");
492 Editor::initial_route_list_display ()
494 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
495 Session::RouteList r (*routes);
496 EditorOrderRouteSorter sorter;
500 no_route_list_redisplay = true;
502 route_display_model->clear ();
504 handle_new_route (r);
506 no_route_list_redisplay = false;
508 redisplay_route_list ();
512 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
514 session->set_remote_control_ids();
515 redisplay_route_list ();
519 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
521 session->set_remote_control_ids();
522 redisplay_route_list ();