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_p (Route* route)
44 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route_p), route));
45 handle_new_route (*route);
49 Editor::handle_new_route (Route& route)
52 AudioTimeAxisView *atv;
53 TreeModel::Row parent;
60 tv = new AudioTimeAxisView (*this, *session, route, track_canvas);
63 if (route_display_model->children().size() == 0) {
65 /* set up basic entries */
69 row = *(route_display_model->append()); // path = "0"
70 row[route_display_columns.text] = _("Busses");
71 row[route_display_columns.tv] = 0;
72 row = *(route_display_model->append()); // path = "1"
73 row[route_display_columns.text] = _("Tracks");
74 row[route_display_columns.tv] = 0;
78 if (dynamic_cast<AudioTrack*>(&route) != 0) {
79 TreeModel::iterator iter = route_display_model->get_iter ("1"); // audio tracks
82 TreeModel::iterator iter = route_display_model->get_iter ("0"); // busses
87 row = *(route_display_model->append (parent.children()));
89 row = *(route_display_model->append ());
92 row[route_display_columns.text] = route.name();
93 row[route_display_columns.visible] = tv->marked_for_display();
94 row[route_display_columns.tv] = tv;
96 track_views.push_back (tv);
98 ignore_route_list_reorder = true;
100 if ((atv = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
101 /* added a new fresh one at the end */
102 if (atv->route().order_key(N_("editor")) == -1) {
103 atv->route().set_order_key (N_("editor"), route_display_model->children().size()-1);
107 ignore_route_list_reorder = false;
109 route.gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes));
111 tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv));
113 editor_mixer_button.set_sensitive(true);
117 Editor::handle_gui_changes (const string & what, void *src)
119 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
121 if (what == "track_height") {
122 redisplay_route_list ();
128 Editor::remove_route (TimeAxisView *tv)
130 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
133 TrackViewList::iterator i;
134 TreeModel::Children rows = route_display_model->children();
135 TreeModel::Children::iterator ri;
137 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
138 track_views.erase (i);
141 for (ri = rows.begin(); ri != rows.end(); ++ri) {
142 if ((*ri)[route_display_columns.tv] == tv) {
143 route_display_model->erase (ri);
147 /* since the editor mixer goes away when you remove a route, set the
148 * button to inacttive
150 editor_mixer_button.set_active(false);
152 /* and disable if all tracks and/or routes are gone */
154 if (track_views.size() == 0) {
155 editor_mixer_button.set_sensitive(false);
160 Editor::route_name_changed (TimeAxisView *tv)
162 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
164 TreeModel::Children rows = route_display_model->children();
165 TreeModel::Children::iterator i;
167 for (i = rows.begin(); i != rows.end(); ++i) {
168 if ((*i)[route_display_columns.tv] == tv) {
169 (*i)[route_display_columns.text] = tv->name();
177 Editor::hide_track_in_display (TimeAxisView& tv)
179 TreeModel::Children rows = route_display_model->children();
180 TreeModel::Children::iterator i;
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;
203 for (i = rows.begin(); i != rows.end(); ++i) {
204 if ((*i)[route_display_columns.tv] == &tv) {
205 (*i)[route_display_columns.visible] = true;
206 tv.set_marked_for_display (true);
213 Editor::route_list_reordered (const TreeModel::Path& path,const TreeModel::iterator& iter,int* what)
215 redisplay_route_list ();
219 Editor::redisplay_route_list ()
221 TreeModel::Children rows = route_display_model->children();
222 TreeModel::Children::iterator i;
227 if (no_route_list_redisplay) {
231 for (n = 0, order = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
232 TimeAxisView *tv = (*i)[route_display_columns.tv];
233 AudioTimeAxisView* at;
236 // just a "title" row
240 if (!ignore_route_list_reorder) {
242 /* this reorder is caused by user action, so reassign sort order keys
246 if ((at = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
247 at->route().set_order_key (N_("editor"), order);
252 bool visible = (*i)[route_display_columns.visible];
255 tv->set_marked_for_display (true);
256 position += tv->show_at (position, n, &edit_controls_vbox);
257 position += track_spacing;
266 /* make sure the cursors stay on top of every newly added track */
268 cursor_group->raise_to_top ();
270 reset_scrolling_region ();
274 Editor::hide_all_tracks (bool with_select)
276 TreeModel::Children rows = route_display_model->children();
277 TreeModel::Children::iterator i;
279 no_route_list_redisplay = true;
281 for (i = rows.begin(); i != rows.end(); ++i) {
283 TreeModel::Row row = (*i);
284 TimeAxisView *tv = row[route_display_columns.tv];
290 row[route_display_columns.visible] = false;
293 no_route_list_redisplay = false;
294 redisplay_route_list ();
296 /* XXX this seems like a hack and half, but its not clear where to put this
300 reset_scrolling_region ();
304 Editor::build_route_list_menu ()
306 using namespace Menu_Helpers;
309 route_list_menu = new Menu;
311 MenuList& items = route_list_menu->items();
312 route_list_menu->set_name ("ArdourContextMenu");
314 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_routes)));
315 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_routes)));
316 items.push_back (MenuElem (_("Show All Audio Tracks"), mem_fun(*this, &Editor::show_all_audiotracks)));
317 items.push_back (MenuElem (_("Hide All Audio Tracks"), mem_fun(*this, &Editor::hide_all_audiotracks)));
318 items.push_back (MenuElem (_("Show All Audio Busses"), mem_fun(*this, &Editor::show_all_audiobus)));
319 items.push_back (MenuElem (_("Hide All Audio Busses"), mem_fun(*this, &Editor::hide_all_audiobus)));
324 Editor::set_all_tracks_visibility (bool yn)
326 TreeModel::Children rows = route_display_model->children();
327 TreeModel::Children::iterator i;
329 no_route_list_redisplay = true;
331 for (i = rows.begin(); i != rows.end(); ++i) {
333 TreeModel::Row row = (*i);
334 TimeAxisView* tv = row[route_display_columns.tv];
340 (*i)[route_display_columns.visible] = yn;
343 no_route_list_redisplay = false;
344 redisplay_route_list ();
348 Editor::set_all_audio_visibility (int tracks, bool yn)
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) {
356 TreeModel::Row row = (*i);
357 TimeAxisView* tv = row[route_display_columns.tv];
358 AudioTimeAxisView* atv;
364 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
367 (*i)[route_display_columns.visible] = yn;
371 if (atv->is_audio_track()) {
372 (*i)[route_display_columns.visible] = yn;
377 if (!atv->is_audio_track()) {
378 (*i)[route_display_columns.visible] = yn;
385 no_route_list_redisplay = false;
386 redisplay_route_list ();
390 Editor::hide_all_routes ()
392 set_all_tracks_visibility (false);
396 Editor::show_all_routes ()
398 set_all_tracks_visibility (true);
402 Editor::show_all_audiobus ()
404 set_all_audio_visibility (2, true);
407 Editor::hide_all_audiobus ()
409 set_all_audio_visibility (2, false);
413 Editor::show_all_audiotracks()
415 set_all_audio_visibility (1, true);
418 Editor::hide_all_audiotracks ()
420 set_all_audio_visibility (1, false);
424 Editor::route_list_display_button_press (GdkEventButton* ev)
426 if (Keyboard::is_context_menu_event (ev)) {
427 show_route_list_menu ();
432 TreeModel::Path path;
433 TreeViewColumn* column;
437 if (!route_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
441 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
443 if ((iter = route_display_model->get_iter (path))) {
444 TimeAxisView* tv = (*iter)[route_display_columns.tv];
446 bool visible = (*iter)[route_display_columns.visible];
447 (*iter)[route_display_columns.visible] = !visible;
453 /* allow normal processing to occur */
464 Editor::show_route_list_menu()
466 if (route_list_menu == 0) {
467 build_route_list_menu ();
470 route_list_menu->popup (1, 0);
474 Editor::route_list_selection_filter (const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
479 struct EditorOrderRouteSorter {
480 bool operator() (Route* a, Route* b) {
481 /* use of ">" forces the correct sort order */
482 return a->order_key ("editor") < b->order_key ("editor");
487 Editor::initial_route_list_display ()
489 Session::RouteList routes = session->get_routes();
490 EditorOrderRouteSorter sorter;
492 routes.sort (sorter);
494 no_route_list_redisplay = true;
496 route_display_model->clear ();
498 for (Session::RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
499 handle_new_route (**i);
502 no_route_list_redisplay = false;
504 redisplay_route_list ();
508 Editor::route_list_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
510 redisplay_route_list ();
514 Editor::route_list_delete (const Gtk::TreeModel::Path& path)
516 redisplay_route_list ();