add (back) PlaySelection to menus
[ardour2.git] / gtk2_ardour / route_params_ui.cc
blob10273b274c257b2d3b97cb1ccaa9387478eab570
1 /*
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.
20 #include <algorithm>
22 #include <glibmm/thread.h>
23 #include <gtkmm2ext/utils.h>
24 #include <gtkmm2ext/stop_signal.h>
25 #include <gtkmm2ext/window_title.h>
27 #include <ardour/session.h>
28 #include <ardour/session_route.h>
29 #include <ardour/audio_diskstream.h>
30 #include <ardour/plugin.h>
31 #include <ardour/plugin_manager.h>
32 #include <ardour/ardour.h>
33 #include <ardour/session.h>
34 #include <ardour/route.h>
35 #include <ardour/audio_track.h>
36 #include <ardour/send.h>
37 #include <ardour/insert.h>
38 #include <ardour/connection.h>
39 #include <ardour/session_connection.h>
41 #include "route_params_ui.h"
42 #include "keyboard.h"
43 #include "mixer_strip.h"
44 #include "plugin_selector.h"
45 #include "ardour_ui.h"
46 #include "plugin_ui.h"
47 #include "io_selector.h"
48 #include "send_ui.h"
49 #include "utils.h"
50 #include "gui_thread.h"
52 #include "i18n.h"
54 using namespace ARDOUR;
55 using namespace PBD;
56 using namespace Gtk;
57 using namespace Gtkmm2ext;
58 using namespace sigc;
60 RouteParams_UI::RouteParams_UI ()
61 : ArdourDialog ("track/bus inspector"),
62 track_menu(0)
64 pre_redirect_box = 0;
65 post_redirect_box = 0;
66 _input_iosel = 0;
67 _output_iosel = 0;
68 _active_pre_view = 0;
69 _active_post_view = 0;
71 using namespace Notebook_Helpers;
73 input_frame.set_shadow_type(Gtk::SHADOW_NONE);
74 output_frame.set_shadow_type(Gtk::SHADOW_NONE);
76 notebook.set_show_tabs (true);
77 notebook.set_show_border (true);
78 notebook.set_name ("RouteParamNotebook");
80 // create the tree model
81 route_display_model = ListStore::create(route_display_columns);
83 // setup the treeview
84 route_display.set_model(route_display_model);
85 route_display.append_column(_("Tracks/Buses"), route_display_columns.text);
86 route_display.set_name(X_("RouteParamsListDisplay"));
87 route_display.get_selection()->set_mode(Gtk::SELECTION_SINGLE); // default
88 route_display.set_reorderable(false);
89 route_display.set_size_request(75, -1);
90 route_display.set_headers_visible(true);
91 route_display.set_headers_clickable(true);
93 route_select_scroller.add(route_display);
94 route_select_scroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
97 route_select_frame.set_name("RouteSelectBaseFrame");
98 route_select_frame.set_shadow_type (Gtk::SHADOW_IN);
99 route_select_frame.add(route_select_scroller);
101 list_vpacker.pack_start (route_select_frame, true, true);
103 notebook.pages().push_back (TabElem (input_frame, _("Inputs")));
104 notebook.pages().push_back (TabElem (output_frame, _("Outputs")));
105 notebook.pages().push_back (TabElem (pre_redir_hpane, _("Pre-fader Redirects")));
106 notebook.pages().push_back (TabElem (post_redir_hpane, _("Post-fader Redirects")));
108 notebook.set_name ("InspectorNotebook");
110 title_label.set_name ("RouteParamsTitleLabel");
111 update_title();
113 // changeable area
114 route_param_frame.set_name("RouteParamsBaseFrame");
115 route_param_frame.set_shadow_type (Gtk::SHADOW_IN);
118 route_hpacker.pack_start (notebook, true, true);
121 route_vpacker.pack_start (title_label, false, false);
122 route_vpacker.pack_start (route_hpacker, true, true);
125 list_hpane.pack1 (list_vpacker);
126 list_hpane.add2 (route_vpacker);
128 list_hpane.set_position(110);
130 pre_redir_hpane.set_position(110);
131 post_redir_hpane.set_position(110);
133 //global_vpacker.pack_start (list_hpane, true, true);
134 //get_vbox()->pack_start (global_vpacker);
135 get_vbox()->pack_start (list_hpane);
138 set_name ("RouteParamsWindow");
139 set_default_size (620,370);
140 set_wmclass (X_("ardour_route_parameters"), "Ardour");
142 set_title (_("Track/Bus Inspector"));
144 // events
145 route_display.get_selection()->signal_changed().connect(mem_fun(*this, &RouteParams_UI::route_selected));
146 route_display.get_column(0)->signal_clicked().connect(mem_fun(*this, &RouteParams_UI::show_track_menu));
148 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
150 _plugin_selector = new PluginSelector (PluginManager::the_manager());
151 _plugin_selector->signal_delete_event().connect (bind (ptr_fun (just_hide_it),
152 static_cast<Window *> (_plugin_selector)));
155 signal_delete_event().connect(bind(ptr_fun(just_hide_it), static_cast<Gtk::Window *>(this)));
158 RouteParams_UI::~RouteParams_UI ()
162 void
163 RouteParams_UI::add_routes (Session::RouteList& routes)
165 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::add_routes), routes));
167 for (Session::RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
168 boost::shared_ptr<Route> route = (*x);
170 if (route->hidden()) {
171 return;
174 TreeModel::Row row = *(route_display_model->append());
175 row[route_display_columns.text] = route->name();
176 row[route_display_columns.route] = route;
178 //route_select_list.rows().back().select ();
180 route->name_changed.connect (bind (mem_fun(*this, &RouteParams_UI::route_name_changed), route));
181 route->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::route_removed), route));
186 void
187 RouteParams_UI::route_name_changed (void *src, boost::shared_ptr<Route> route)
189 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::route_name_changed), src, route));
191 bool found = false ;
192 TreeModel::Children rows = route_display_model->children();
193 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
194 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
195 if (r == route) {
196 (*iter)[route_display_columns.text] = route->name() ;
197 found = true ;
198 break;
202 if(!found) {
203 error << _("route display list item for renamed route not found!") << endmsg;
206 if (route == _route) {
207 track_input_label.set_text (route->name());
208 update_title();
212 void
213 RouteParams_UI::setup_redirect_boxes()
215 if (session && _route) {
217 // just in case... shouldn't need this
218 cleanup_redirect_boxes();
220 // construct new redirect boxes
221 pre_redirect_box = new RedirectBox(PreFader, *session, *_plugin_selector, _rr_selection);
222 post_redirect_box = new RedirectBox(PostFader, *session, *_plugin_selector, _rr_selection);
224 pre_redirect_box->set_route (_route);
225 post_redirect_box->set_route (_route);
227 pre_redir_hpane.pack1 (*pre_redirect_box);
228 post_redir_hpane.pack1 (*post_redirect_box);
230 pre_redirect_box->RedirectSelected.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_selected), PreFader));
231 pre_redirect_box->RedirectUnselected.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_selected), PreFader));
232 post_redirect_box->RedirectSelected.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_selected), PostFader));
233 post_redirect_box->RedirectUnselected.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_selected), PostFader));
235 pre_redir_hpane.show_all();
236 post_redir_hpane.show_all();
241 void
242 RouteParams_UI::cleanup_redirect_boxes()
244 if (pre_redirect_box) {
245 pre_redir_hpane.remove(*pre_redirect_box);
246 delete pre_redirect_box;
247 pre_redirect_box = 0;
250 if (post_redirect_box) {
251 post_redir_hpane.remove(*post_redirect_box);
252 delete post_redirect_box;
253 post_redirect_box = 0;
257 void
258 RouteParams_UI::setup_io_frames()
260 cleanup_io_frames();
262 // input
263 _input_iosel = new IOSelector (*session, _route, true);
264 _input_iosel->redisplay ();
265 input_frame.add (*_input_iosel);
266 input_frame.show_all();
268 // output
269 _output_iosel = new IOSelector (*session, _route, false);
270 _output_iosel->redisplay ();
271 output_frame.add (*_output_iosel);
272 output_frame.show_all();
275 void
276 RouteParams_UI::cleanup_io_frames()
278 if (_input_iosel) {
279 _input_iosel->Finished (IOSelector::Cancelled);
280 input_frame.remove();
281 delete _input_iosel;
282 _input_iosel = 0;
285 if (_output_iosel) {
286 _output_iosel->Finished (IOSelector::Cancelled);
288 output_frame.remove();
289 delete _output_iosel;
290 _output_iosel = 0;
294 void
295 RouteParams_UI::cleanup_pre_view (bool stopupdate)
297 if (_active_pre_view) {
298 GenericPluginUI * plugui = 0;
300 if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_pre_view)) != 0) {
301 plugui->stop_updating (0);
304 _pre_plugin_conn.disconnect();
305 pre_redir_hpane.remove(*_active_pre_view);
306 delete _active_pre_view;
307 _active_pre_view = 0;
311 void
312 RouteParams_UI::cleanup_post_view (bool stopupdate)
314 if (_active_post_view) {
315 GenericPluginUI * plugui = 0;
317 if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_post_view)) != 0) {
318 plugui->stop_updating (0);
320 _post_plugin_conn.disconnect();
321 post_redir_hpane.remove(*_active_post_view);
322 delete _active_post_view;
323 _active_post_view = 0;
328 void
329 RouteParams_UI::route_removed (boost::shared_ptr<Route> route)
331 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::route_removed), route));
333 TreeModel::Children rows = route_display_model->children();
334 TreeModel::Children::iterator ri;
336 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
337 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
339 if (r == route) {
340 route_display_model->erase(iter);
341 break;
345 if (route == _route) {
346 cleanup_io_frames();
347 cleanup_pre_view();
348 cleanup_post_view();
349 cleanup_redirect_boxes();
351 _route.reset ((Route*) 0);
352 _pre_redirect.reset ((Redirect*) 0);
353 _post_redirect.reset ((Redirect*) 0);
354 update_title();
358 void
359 RouteParams_UI::set_session (Session *sess)
361 ArdourDialog::set_session (sess);
363 route_display_model->clear();
365 if (session) {
366 boost::shared_ptr<Session::RouteList> r = session->get_routes();
367 add_routes (*r);
368 session->GoingAway.connect (mem_fun(*this, &ArdourDialog::session_gone));
369 session->RouteAdded.connect (mem_fun(*this, &RouteParams_UI::add_routes));
370 start_updating ();
371 } else {
372 stop_updating ();
375 //route_select_list.thaw ();
377 _plugin_selector->set_session (session);
381 void
382 RouteParams_UI::session_gone ()
384 ENSURE_GUI_THREAD(mem_fun(*this, &RouteParams_UI::session_gone));
386 route_display_model->clear();
388 cleanup_io_frames();
389 cleanup_pre_view();
390 cleanup_post_view();
391 cleanup_redirect_boxes();
393 _route.reset ((Route*) 0);
394 _pre_redirect.reset ((Redirect*) 0);
395 _post_redirect.reset ((Redirect*) 0);
396 update_title();
398 ArdourDialog::session_gone();
402 void
403 RouteParams_UI::route_selected()
405 Glib::RefPtr<TreeSelection> selection = route_display.get_selection();
406 TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
407 if(iter) {
408 //If anything is selected
409 boost::shared_ptr<Route> route = (*iter)[route_display_columns.route] ;
411 if (_route == route) {
412 // do nothing
413 return;
416 // remove event binding from previously selected
417 if (_route) {
418 _route_conn.disconnect();
419 _route_ds_conn.disconnect();
420 cleanup_redirect_boxes();
421 cleanup_pre_view();
422 cleanup_post_view();
423 cleanup_io_frames();
426 // update the other panes with the correct info
427 _route = route;
428 //update_routeinfo (route);
430 setup_io_frames();
431 setup_redirect_boxes();
433 // bind to redirects changed event for this route
434 _route_conn = route->redirects_changed.connect (mem_fun(*this, &RouteParams_UI::redirects_changed));
436 track_input_label.set_text (_route->name());
438 update_title();
439 } else {
440 // no selection
441 if (_route) {
442 _route_conn.disconnect();
444 // remove from view
445 cleanup_io_frames();
446 cleanup_pre_view();
447 cleanup_post_view();
448 cleanup_redirect_boxes();
450 _route.reset ((Route*) 0);
451 _pre_redirect.reset ((Redirect*) 0);
452 _post_redirect.reset ((Redirect *) 0);
453 track_input_label.set_text(_("NO TRACK"));
454 update_title();
459 //void
460 //RouteParams_UI::route_unselected (gint row, gint col, GdkEvent *ev)
462 // if (_route) {
463 // _route_conn.disconnect();
465 // remove from view
466 // cleanup_io_frames();
467 // cleanup_pre_view();
468 // cleanup_post_view();
469 // cleanup_redirect_boxes();
471 // _route.reset ((Route*)0);
472 // _pre_redirect = 0;
473 // _post_redirect = 0;
474 // track_input_label.set_text(_("NO TRACK"));
475 // update_title();
476 // }
479 void
480 RouteParams_UI::redirects_changed (void *src)
483 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::redirects_changed), src));
485 // pre_redirect_list.freeze ();
486 // pre_redirect_list.clear ();
487 // post_redirect_list.freeze ();
488 // post_redirect_list.clear ();
489 // if (_route) {
490 // _route->foreach_redirect (this, &RouteParams_UI::add_redirect_to_display);
491 // }
492 // pre_redirect_list.thaw ();
493 // post_redirect_list.thaw ();
495 cleanup_pre_view();
496 cleanup_post_view();
498 _pre_redirect.reset ((Redirect*) 0);
499 _post_redirect.reset ((Redirect*) 0);
500 //update_title();
505 void
506 RouteParams_UI::show_track_menu()
508 using namespace Menu_Helpers;
510 if (track_menu == 0) {
511 track_menu = new Menu;
512 track_menu->set_name ("ArdourContextMenu");
513 track_menu->items().push_back
514 (MenuElem (_("Add Track/Bus"),
515 bind (mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::add_route), (Gtk::Window*) 0)));
517 track_menu->popup (1, gtk_get_current_event_time());
522 void
523 RouteParams_UI::redirect_selected (boost::shared_ptr<ARDOUR::Redirect> redirect, ARDOUR::Placement place)
525 boost::shared_ptr<Insert> insert;
527 if ((place == PreFader && _pre_redirect == redirect)
528 || (place == PostFader && _post_redirect == redirect)){
529 return;
532 if ((insert = boost::dynamic_pointer_cast<Insert> (redirect)) == 0) {
534 boost::shared_ptr<Send> send;
536 if ((send = boost::dynamic_pointer_cast<Send> (redirect)) != 0) {
538 /* its a send */
540 SendUI *send_ui = new SendUI (send, *session);
542 if (place == PreFader) {
543 cleanup_pre_view();
544 _pre_plugin_conn = send->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect));
545 _active_pre_view = send_ui;
547 pre_redir_hpane.add2 (*_active_pre_view);
548 pre_redir_hpane.show_all();
550 else {
551 cleanup_post_view();
552 _post_plugin_conn = send->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect));
553 _active_post_view = send_ui;
555 post_redir_hpane.add2 (*_active_post_view);
556 post_redir_hpane.show_all();
560 } else {
561 /* its an insert, though we don't know what kind yet. */
563 boost::shared_ptr<PluginInsert> plugin_insert;
564 boost::shared_ptr<PortInsert> port_insert;
566 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (insert)) != 0) {
568 GenericPluginUI *plugin_ui = new GenericPluginUI (plugin_insert, true);
570 if (place == PreFader) {
571 cleanup_pre_view();
572 _pre_plugin_conn = plugin_insert->plugin()->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::plugin_going_away), PreFader));
573 plugin_ui->start_updating (0);
574 _active_pre_view = plugin_ui;
575 pre_redir_hpane.pack2 (*_active_pre_view);
576 pre_redir_hpane.show_all();
578 else {
579 cleanup_post_view();
580 _post_plugin_conn = plugin_insert->plugin()->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::plugin_going_away), PostFader));
581 plugin_ui->start_updating (0);
582 _active_post_view = plugin_ui;
583 post_redir_hpane.pack2 (*_active_post_view);
584 post_redir_hpane.show_all();
587 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (insert)) != 0) {
589 PortInsertUI *portinsert_ui = new PortInsertUI (*session, port_insert);
591 if (place == PreFader) {
592 cleanup_pre_view();
593 _pre_plugin_conn = port_insert->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect));
594 _active_pre_view = portinsert_ui;
595 pre_redir_hpane.pack2 (*_active_pre_view);
596 portinsert_ui->redisplay();
597 pre_redir_hpane.show_all();
599 else {
600 cleanup_post_view();
601 _post_plugin_conn = port_insert->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect));
602 _active_post_view = portinsert_ui;
603 post_redir_hpane.pack2 (*_active_post_view);
604 portinsert_ui->redisplay();
605 post_redir_hpane.show_all();
611 if (place == PreFader) {
612 _pre_redirect = redirect;
613 } else {
614 _post_redirect = redirect;
617 update_title();
621 void
622 RouteParams_UI::plugin_going_away (Placement place)
624 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::plugin_going_away), place));
626 // delete the current view without calling finish
628 if (place == PreFader) {
629 cleanup_pre_view (false);
630 _pre_redirect.reset ((Redirect*) 0);
632 else {
633 cleanup_post_view (false);
634 _post_redirect.reset ((Redirect*) 0);
638 void
639 RouteParams_UI::redirect_going_away (boost::shared_ptr<ARDOUR::Redirect> redirect)
642 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect));
644 printf ("redirect going away\n");
645 // delete the current view without calling finish
646 if (redirect == _pre_redirect) {
647 cleanup_pre_view (false);
648 _pre_redirect.reset ((Redirect*) 0);
649 } else if (redirect == _post_redirect) {
650 cleanup_post_view (false);
651 _post_redirect.reset ((Redirect*) 0);
656 void
657 RouteParams_UI::update_title ()
659 WindowTitle title(_("Track/Bus Inspector"));
661 if (_route) {
663 // title += ": ";
665 // if (_redirect && (_current_view == PLUGIN_CONFIG_VIEW || _current_view == SEND_CONFIG_VIEW)) {
666 // title += _redirect->name();
667 // }
668 // else if (_current_view == INPUT_CONFIG_VIEW) {
669 // title += _("INPUT");
670 // }
671 // else if (_current_view == OUTPUT_CONFIG_VIEW) {
672 // title += _("OUTPUT");
673 // }
675 title_label.set_text(_route->name());
677 title += _route->name();
679 set_title(title.get_string());
681 else {
682 title_label.set_text(_("No Route Selected"));
683 title += _("No Route Selected");
684 set_title(title.get_string());
689 void
690 RouteParams_UI::start_updating ()
692 update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect
693 (mem_fun(*this, &RouteParams_UI::update_views));
696 void
697 RouteParams_UI::stop_updating ()
699 update_connection.disconnect();
702 void
703 RouteParams_UI::update_views ()
705 SendUI *sui;
706 // TODO: only do it if correct tab is showing
708 if ((sui = dynamic_cast<SendUI*> (_active_pre_view)) != 0) {
709 sui->update ();
711 if ((sui = dynamic_cast<SendUI*> (_active_post_view)) != 0) {
712 sui->update ();