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>
36 using namespace ARDOUR;
40 Editor::handle_new_route_p (Route* route)
42 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_new_route_p), route));
43 handle_new_route (*route);
47 Editor::handle_new_route (Route& route)
50 AudioTimeAxisView *atv;
51 TreeModel::Row row = *(route_display_model->append());
57 tv = new AudioTimeAxisView (*this, *session, route, track_canvas);
59 track_views.push_back (tv);
61 row[route_display_columns.text] = route.name();
62 row[route_display_columns.tv] = tv;
64 ignore_route_list_reorder = true;
66 if (tv->marked_for_display()) {
67 route_list.get_selection()->select (row);
70 if ((atv = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
71 /* added a new fresh one at the end */
72 if (atv->route().order_key(N_("editor")) == -1) {
73 atv->route().set_order_key (N_("editor"), route_display_model->children().size()-1);
77 ignore_route_list_reorder = false;
79 route.gui_changed.connect (mem_fun(*this, &Editor::handle_gui_changes));
81 tv->GoingAway.connect (bind (mem_fun(*this, &Editor::remove_route), tv));
83 editor_mixer_button.set_sensitive(true);
88 Editor::handle_gui_changes (const string & what, void *src)
90 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::handle_gui_changes), what, src));
92 if (what == "track_height") {
93 route_list_reordered ();
99 Editor::remove_route (TimeAxisView *tv)
101 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::remove_route), tv));
104 TrackViewList::iterator i;
105 TreeModel::Children rows = route_display_model->children();
106 TreeModel::Children::iterator ri;
108 if ((i = find (track_views.begin(), track_views.end(), tv)) != track_views.end()) {
109 track_views.erase (i);
112 for (ri = rows.begin(); ri != rows.end(); ++ri) {
113 if ((*ri)[route_display_columns.tv] == tv) {
114 route_display_model->erase (ri);
118 /* since the editor mixer goes away when you remove a route, set the
119 * button to inacttive
121 editor_mixer_button.set_active(false);
123 /* and disable if all tracks and/or routes are gone */
125 if (track_views.size() == 0) {
126 editor_mixer_button.set_sensitive(false);
131 Editor::route_name_changed (TimeAxisView *tv)
133 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::route_name_changed), tv));
135 TreeModel::Children rows = route_display_model->children();
136 TreeModel::Children::iterator i;
138 for (i = rows.begin(); i != rows.end(); ++i) {
139 if ((*i)[route_display_columns.tv] == tv) {
140 (*i)[route_display_columns.text] = tv->name();
148 Editor::route_display_selection_changed ()
152 TreeModel::Children rows = route_display_model->children();
153 TreeModel::Children::iterator i;
154 Glib::RefPtr<TreeSelection> selection = route_list.get_selection();
156 for (i = rows.begin(); i != rows.end(); ++i) {
157 tv = (*i)[route_display_columns.tv];
158 if (!selection->is_selected (i)) {
159 tv->set_marked_for_display (false);
161 AudioTimeAxisView *atv;
162 tv->set_marked_for_display (true);
163 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
164 if (current_mixer_strip && &(atv->route()) == &(current_mixer_strip->route())) {
165 // this will hide the mixer strip
166 set_selected_mixer_strip(*atv);
172 route_list_reordered ();
176 Editor::unselect_strip_in_display (TimeAxisView& tv)
178 TreeModel::Children rows = route_display_model->children();
179 TreeModel::Children::iterator i;
180 Glib::RefPtr<TreeSelection> selection = route_list.get_selection();
182 for (i = rows.begin(); i != rows.end(); ++i) {
183 if ((*i)[route_display_columns.tv] == &tv) {
184 selection->unselect (*i);
190 Editor::select_strip_in_display (TimeAxisView* tv)
192 TreeModel::Children rows = route_display_model->children();
193 TreeModel::Children::iterator i;
194 Glib::RefPtr<TreeSelection> selection = route_list.get_selection();
196 for (i = rows.begin(); i != rows.end(); ++i) {
197 if ((*i)[route_display_columns.tv] == tv) {
198 selection->select (*i);
204 Editor::queue_route_list_reordered ()
207 /* the problem here is that we are called *before* the
208 list has been reordered. so just queue up
209 the actual re-drawer to happen once the re-ordering
213 Glib::signal_idle().connect (mem_fun(*this, &Editor::route_list_reordered));
217 Editor::redisplay_route_list ()
219 route_list_reordered ();
223 Editor::route_list_reordered ()
225 TreeModel::Children rows = route_display_model->children();
226 TreeModel::Children::iterator i;
230 for (n = 0, order = 0, i = rows.begin(); i != rows.end(); ++i, ++order) {
231 TimeAxisView *tv = (*i)[route_display_columns.tv];
232 AudioTimeAxisView* at;
233 if (!ignore_route_list_reorder) {
235 /* this reorder is caused by user action, so reassign sort order keys
239 if ((at = dynamic_cast<AudioTimeAxisView*> (tv)) != 0) {
240 at->route().set_order_key (N_("editor"), order);
243 if (tv->marked_for_display()) {
244 order += tv->show_at (order, n, &edit_controls_vbox);
245 order += track_spacing;
254 // controls_layout.queue_resize ();
255 reset_scrolling_region ();
260 Editor::hide_all_tracks (bool with_select)
262 TreeModel::Children rows = route_display_model->children();
263 TreeModel::Children::iterator i;
266 // track_display_list.freeze ();
268 for (i = rows.begin(); i != rows.end(); ++i) {
270 TreeModel::Row row = (*i);
271 TimeAxisView *tv = row[route_display_columns.tv];
274 route_list.get_selection()->unselect (i);
276 tv->set_marked_for_display (false);
281 //route_list.thaw ();
282 reset_scrolling_region ();
286 Editor::route_list_column_click ()
288 if (route_list_menu == 0) {
289 build_route_list_menu ();
292 route_list_menu->popup (0, 0);
296 Editor::build_route_list_menu ()
298 using namespace Menu_Helpers;
302 route_list_menu = new Menu;
304 MenuList& items = route_list_menu->items();
305 route_list_menu->set_name ("ArdourContextMenu");
307 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::select_all_routes)));
308 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::unselect_all_routes)));
309 items.push_back (MenuElem (_("Show All AbstractTracks"), mem_fun(*this, &Editor::select_all_audiotracks)));
310 items.push_back (MenuElem (_("Hide All AbstractTracks"), mem_fun(*this, &Editor::unselect_all_audiotracks)));
311 items.push_back (MenuElem (_("Show All AudioBus"), mem_fun(*this, &Editor::select_all_audiobus)));
312 items.push_back (MenuElem (_("Hide All AudioBus"), mem_fun(*this, &Editor::unselect_all_audiobus)));
317 Editor::unselect_all_routes ()
319 hide_all_tracks (true);
323 Editor::select_all_routes ()
326 TreeModel::Children rows = route_display_model->children();
327 TreeModel::Children::iterator i;
329 for (i = rows.begin(); i != rows.end(); ++i) {
330 route_list.get_selection()->select (i);
335 Editor::select_all_audiotracks ()
337 TreeModel::Children rows = route_display_model->children();
338 TreeModel::Children::iterator i;
340 for (i = rows.begin(); i != rows.end(); ++i) {
341 TreeModel::Row row = (*i);
342 TimeAxisView* tv = row[route_display_columns.tv];
343 AudioTimeAxisView* atv;
345 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
346 if (atv->is_audio_track()) {
347 route_list.get_selection()->select (i);
356 Editor::unselect_all_audiotracks ()
358 TreeModel::Children rows = route_display_model->children();
359 TreeModel::Children::iterator i;
361 for (i = rows.begin(); i != rows.end(); ++i) {
362 TreeModel::Row row = (*i);
363 TimeAxisView *tv = row[route_display_columns.tv];
364 AudioTimeAxisView* atv;
366 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
367 if (atv->is_audio_track()) {
368 route_list.get_selection()->unselect (i);
377 Editor::select_all_audiobus ()
379 TreeModel::Children rows = route_display_model->children();
380 TreeModel::Children::iterator i;
382 for (i = rows.begin(); i != rows.end(); ++i) {
383 TreeModel::Row row = (*i);
384 TimeAxisView* tv = row[route_display_columns.tv];
385 AudioTimeAxisView* atv;
387 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
388 if (!atv->is_audio_track()) {
389 route_list.get_selection()->select (i);
398 Editor::unselect_all_audiobus ()
400 TreeModel::Children rows = route_display_model->children();
401 TreeModel::Children::iterator i;
403 for (i = rows.begin(); i != rows.end(); ++i) {
404 TreeModel::Row row = (*i);
405 TimeAxisView* tv = row[route_display_columns.tv];
406 AudioTimeAxisView* atv;
408 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
409 if (!atv->is_audio_track()) {
410 route_list.get_selection()->unselect (i);
419 Editor::route_list_compare_func (TreeModel::iterator a, TreeModel::iterator b)
423 AudioTimeAxisView *atv1;
424 AudioTimeAxisView *atv2;
428 tv1 = (*a)[route_display_columns.tv];
429 tv2 = (*b)[route_display_columns.tv];
431 if ((atv1 = dynamic_cast<AudioTimeAxisView*>(tv1)) == 0 ||
432 (atv2 = dynamic_cast<AudioTimeAxisView*>(tv2)) == 0) {
439 /* use of ">" forces the correct sort order */
441 return ra->order_key ("editor") > rb->order_key ("editor");