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;
41 Editor::handle_new_route_p (Route* route)
43 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route_p), route));
44 handle_new_route (*route);
48 Editor::handle_new_route (Route& route)
51 AudioTimeAxisView *atv;
52 TreeModel::Row parent;
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) != 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));
112 editor_mixer_button.set_sensitive(true);
116 Editor::handle_gui_changes (const string & what, void *src)
118 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
120 if (what == "track_height") {
121 redisplay_route_list ();
127 Editor::remove_route (TimeAxisView *tv)
129 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
132 TrackViewList::iterator i;
133 TreeModel::Children rows = route_display_model->children();
134 TreeModel::Children::iterator ri;
136 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
137 track_views.erase (i);
140 for (ri = rows.begin(); ri != rows.end(); ++ri) {
141 if ((*ri)[route_display_columns.tv] == tv) {
142 route_display_model->erase (ri);
146 /* since the editor mixer goes away when you remove a route, set the
147 * button to inacttive
149 editor_mixer_button.set_active(false);
151 /* and disable if all tracks and/or routes are gone */
153 if (track_views.size() == 0) {
154 editor_mixer_button.set_sensitive(false);
159 Editor::route_name_changed (TimeAxisView *tv)
161 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
163 TreeModel::Children rows = route_display_model->children();
164 TreeModel::Children::iterator i;
166 for (i = rows.begin(); i != rows.end(); ++i) {
167 if ((*i)[route_display_columns.tv] == tv) {
168 (*i)[route_display_columns.text] = tv->name();
176 Editor::hide_track_in_display (TimeAxisView& tv)
178 TreeModel::Children rows = route_display_model->children();
179 TreeModel::Children::iterator i;
180 Glib::RefPtr<TreeSelection> selection = route_list_display.get_selection();
182 for (i = rows.begin(); i != rows.end(); ++i) {
183 if ((*i)[route_display_columns.tv] == &tv) {
184 (*i)[route_display_columns.visible] = false;
189 AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
191 if (atv && current_mixer_strip && &(atv->route()) == &(current_mixer_strip->route())) {
192 // this will hide the mixer strip
193 set_selected_mixer_strip (tv);
198 Editor::show_track_in_display (TimeAxisView& tv)
200 TreeModel::Children rows = route_display_model->children();
201 TreeModel::Children::iterator i;
202 Glib::RefPtr<TreeSelection> selection = route_list_display.get_selection();
204 for (i = rows.begin(); i != rows.end(); ++i) {
205 if ((*i)[route_display_columns.tv] == &tv) {
206 (*i)[route_display_columns.visible] = true;
207 tv.set_marked_for_display (true);
214 Editor::route_list_reordered (const TreeModel::Path& path,const TreeModel::iterator& iter,int* what)
216 redisplay_route_list ();
220 Editor::redisplay_route_list ()
222 TreeModel::Children rows = route_display_model->children();
223 TreeModel::Children::iterator i;
228 if (no_route_list_redisplay) {
232 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
233 TimeAxisView *tv = (*i)[route_display_columns.tv];
234 AudioTimeAxisView* at;
237 // just a "title" row
241 if (!ignore_route_list_reorder) {
243 /* this reorder is caused by user action, so reassign sort order keys
247 if ((at = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
248 at->route().set_order_key (N_("editor"), order);
253 bool visible = (*i)[route_display_columns.visible];
256 tv->set_marked_for_display (true);
257 position += tv->show_at (position, n, &edit_controls_vbox);
258 position += track_spacing;
267 reset_scrolling_region ();
271 Editor::hide_all_tracks (bool with_select)
273 TreeModel::Children rows = route_display_model->children();
274 TreeModel::Children::iterator i;
276 no_route_list_redisplay = true;
278 for (i = rows.begin(); i != rows.end(); ++i) {
280 TreeModel::Row row = (*i);
281 TimeAxisView *tv = row[route_display_columns.tv];
287 row[route_display_columns.visible] = false;
290 no_route_list_redisplay = false;
291 redisplay_route_list ();
293 /* XXX this seems like a hack and half, but its not clear where to put this
297 reset_scrolling_region ();
301 Editor::build_route_list_menu ()
303 using namespace Menu_Helpers;
306 route_list_menu = new Menu;
308 MenuList& items = route_list_menu->items();
309 route_list_menu->set_name ("ArdourContextMenu");
311 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
312 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
313 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
314 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
315 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
316 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
321 Editor::set_all_tracks_visibility (bool yn)
323 TreeModel::Children rows = route_display_model->children();
324 TreeModel::Children::iterator i;
326 no_route_list_redisplay = true;
328 for (i = rows.begin(); i != rows.end(); ++i) {
330 TreeModel::Row row = (*i);
331 TimeAxisView* tv = row[route_display_columns.tv];
337 (*i)[route_display_columns.visible] = yn;
340 no_route_list_redisplay = false;
341 redisplay_route_list ();
345 Editor::set_all_audio_visibility (int tracks, bool yn)
347 TreeModel::Children rows = route_display_model->children();
348 TreeModel::Children::iterator i;
350 no_route_list_redisplay = true;
352 for (i = rows.begin(); i != rows.end(); ++i) {
353 TreeModel::Row row = (*i);
354 TimeAxisView* tv = row[route_display_columns.tv];
355 AudioTimeAxisView* atv;
361 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
364 (*i)[route_display_columns.visible] = yn;
368 if (atv->is_audio_track()) {
369 (*i)[route_display_columns.visible] = yn;
374 if (!atv->is_audio_track()) {
375 (*i)[route_display_columns.visible] = yn;
382 no_route_list_redisplay = false;
383 redisplay_route_list ();
387 Editor::hide_all_routes ()
389 set_all_tracks_visibility (false);
393 Editor::show_all_routes ()
395 set_all_tracks_visibility (true);
399 Editor::show_all_audiobus ()
401 set_all_audio_visibility (2, true);
404 Editor::hide_all_audiobus ()
406 set_all_audio_visibility (2, false);
410 Editor::show_all_audiotracks()
412 set_all_audio_visibility (1, true);
415 Editor::hide_all_audiotracks ()
417 set_all_audio_visibility (1, false);
421 Editor::route_list_display_button_press (GdkEventButton* ev)
423 if (Keyboard::is_context_menu_event (ev)) {
424 show_route_list_menu ();
429 TreeModel::Path path;
430 TreeViewColumn* column;
434 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
438 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
440 if ((iter = route_display_model->get_iter (path))) {
441 TimeAxisView* tv = (*iter)[route_display_columns.tv];
443 bool visible = (*iter)[route_display_columns.visible];
444 (*iter)[route_display_columns.visible] = !visible;
450 /* allow normal processing to occur */
461 Editor::show_route_list_menu()
463 if (route_list_menu == 0) {
464 build_route_list_menu ();
467 route_list_menu->popup (1, 0);
471 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
476 struct EditorOrderRouteSorter {
477 bool operator() (Route* a, Route* b) {
478 /* use of ">" forces the correct sort order */
479 return a->order_key ("editor") < b->order_key ("editor");
484 Editor::initial_route_list_display ()
486 Session::RouteList routes = session->get_routes();
487 EditorOrderRouteSorter sorter;
489 routes.sort (sorter);
491 no_route_list_redisplay = true;
493 route_display_model->clear ();
495 for (Session::RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
496 handle_new_route (**i);
499 no_route_list_redisplay = false;
501 redisplay_route_list ();
505 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
507 redisplay_route_list ();
511 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
513 redisplay_route_list ();