2 * Copyright (C) 2005-2007 Taybin Rutkin <taybin@taybin.com>
3 * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2007-2011 Carl Hetherington <carl@carlh.net>
5 * Copyright (C) 2007-2012 David Robillard <d@drobilla.net>
6 * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <glibmm/threads.h>
27 #include <gtkmm/stock.h>
29 #include "ardour/audioengine.h"
30 #include "ardour/audio_track.h"
31 #include "ardour/plugin.h"
32 #include "ardour/plugin_insert.h"
33 #include "ardour/plugin_manager.h"
34 #include "ardour/port_insert.h"
35 #include "ardour/return.h"
36 #include "ardour/route.h"
37 #include "ardour/send.h"
38 #include "ardour/internal_send.h"
40 #include "gtkmm2ext/utils.h"
41 #include "gtkmm2ext/window_title.h"
43 #include "ardour_ui.h"
44 #include "gui_thread.h"
45 #include "io_selector.h"
48 #include "mixer_strip.h"
49 #include "port_insert_ui.h"
50 #include "plugin_selector.h"
51 #include "plugin_ui.h"
52 #include "return_ui.h"
53 #include "route_params_ui.h"
59 using namespace ARDOUR;
62 using namespace Gtkmm2ext;
64 RouteParams_UI::RouteParams_UI ()
65 : ArdourWindow (_("Tracks and Busses"))
73 using namespace Notebook_Helpers;
75 input_frame.set_shadow_type(Gtk::SHADOW_NONE);
76 output_frame.set_shadow_type(Gtk::SHADOW_NONE);
78 notebook.set_show_tabs (true);
79 notebook.set_show_border (true);
80 notebook.set_name ("RouteParamNotebook");
82 // create the tree model
83 route_display_model = ListStore::create(route_display_columns);
86 route_display.set_model(route_display_model);
87 route_display.append_column(_("Tracks/Busses"), route_display_columns.text);
88 route_display.set_name(X_("RouteParamsListDisplay"));
89 route_display.get_selection()->set_mode(Gtk::SELECTION_SINGLE); // default
90 route_display.set_reorderable(false);
91 route_display.set_size_request(75, -1);
92 route_display.set_headers_visible(true);
93 route_display.set_headers_clickable(true);
95 dynamic_cast<Gtk::CellRendererText*>(route_display.get_column_cell_renderer(0))->property_ellipsize() = Pango::ELLIPSIZE_START;
97 route_select_scroller.add(route_display);
98 route_select_scroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
100 route_select_frame.set_name("RouteSelectBaseFrame");
101 route_select_frame.set_shadow_type (Gtk::SHADOW_IN);
102 route_select_frame.add(route_select_scroller);
104 list_vpacker.pack_start (route_select_frame, true, true);
106 notebook.pages().push_back (TabElem (input_frame, _("Inputs")));
107 notebook.pages().push_back (TabElem (output_frame, _("Outputs")));
108 notebook.pages().push_back (TabElem (redir_hpane, _("Plugins, Inserts & Sends")));
110 notebook.set_name ("InspectorNotebook");
112 title_label.set_name ("RouteParamsTitleLabel");
116 route_param_frame.set_name("RouteParamsBaseFrame");
117 route_param_frame.set_shadow_type (Gtk::SHADOW_IN);
119 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);
124 list_hpane.add (list_vpacker);
125 list_hpane.add (route_vpacker);
129 set_name ("RouteParamsWindow");
130 set_default_size (620,370);
131 set_wmclass (X_("ardour_route_parameters"), PROGRAM_NAME);
134 route_display.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &RouteParams_UI::route_selected));
135 route_display.get_column(0)->signal_clicked().connect(sigc::mem_fun(*this, &RouteParams_UI::show_track_menu));
137 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
142 RouteParams_UI::~RouteParams_UI ()
148 RouteParams_UI::add_routes (RouteList& routes)
150 ENSURE_GUI_THREAD (*this, &RouteParams_UI::add_routes, routes)
152 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
153 boost::shared_ptr<Route> route = (*x);
155 if (route->is_auditioner()) {
159 TreeModel::Row row = *(route_display_model->append());
160 row[route_display_columns.text] = route->name();
161 row[route_display_columns.route] = route;
163 //route_select_list.rows().back().select ();
165 route->PropertyChanged.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_property_changed, this, _1, boost::weak_ptr<Route>(route)), gui_context());
166 route->DropReferences.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_removed, this, boost::weak_ptr<Route>(route)), gui_context());
172 RouteParams_UI::route_property_changed (const PropertyChange& what_changed, boost::weak_ptr<Route> wr)
174 if (!what_changed.contains (ARDOUR::Properties::name)) {
178 boost::shared_ptr<Route> route (wr.lock());
184 ENSURE_GUI_THREAD (*this, &RouteParams_UI::route_name_changed, wr)
187 TreeModel::Children rows = route_display_model->children();
188 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
189 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
191 (*iter)[route_display_columns.text] = route->name() ;
198 error << _("route display list item for renamed route not found!") << endmsg;
201 if (route == _route) {
202 track_input_label.set_text (route->name());
208 RouteParams_UI::map_frozen()
210 ENSURE_GUI_THREAD (*this, &RouteParams_UI::map_frozen)
211 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(_route);
212 if (at && insert_box) {
213 switch (at->freeze_state()) {
214 case AudioTrack::Frozen:
215 insert_box->set_sensitive (false);
216 //hide_redirect_editors (); // TODO hide editor windows
219 insert_box->set_sensitive (true);
220 // XXX need some way, maybe, to retoggle redirect editors
227 RouteParams_UI::plugin_selector() {
228 return Mixer_UI::instance()->plugin_selector ();
232 RouteParams_UI::setup_processor_boxes()
234 if (_session && _route) {
236 // just in case... shouldn't need this
237 cleanup_processor_boxes();
239 // construct new redirect boxes
240 insert_box = new ProcessorBox (_session, boost::bind (&RouteParams_UI::plugin_selector, this), _p_selection, 0);
241 insert_box->set_route (_route);
243 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(_route);
245 at->FreezeChange.connect (route_connections, invalidator (*this), boost::bind (&RouteParams_UI::map_frozen, this), gui_context());
247 redir_hpane.add (*insert_box);
249 insert_box->ProcessorSelected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected)); //note: this indicates a double-click activation, not just a "selection"
250 insert_box->ProcessorUnselected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected));
252 redir_hpane.show_all();
257 RouteParams_UI::cleanup_processor_boxes()
260 redir_hpane.remove(*insert_box);
267 RouteParams_UI::setup_io_selector()
269 cleanup_io_selector();
272 _input_iosel = new IOSelector (this, _session, _route->input());
273 _input_iosel->setup ();
274 input_frame.add (*_input_iosel);
275 input_frame.show_all();
278 _output_iosel = new IOSelector (this, _session, _route->output());
279 _output_iosel->setup ();
280 output_frame.add (*_output_iosel);
281 output_frame.show_all();
285 RouteParams_UI::cleanup_io_selector()
288 _input_iosel->Finished (IOSelector::Cancelled);
289 input_frame.remove();
295 _output_iosel->Finished (IOSelector::Cancelled);
297 output_frame.remove();
298 delete _output_iosel;
304 RouteParams_UI::cleanup_view (bool stopupdate)
307 GenericPluginUI* plugui = 0;
309 if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_view)) != 0) {
310 plugui->stop_updating (0);
313 _processor_going_away_connection.disconnect ();
314 redir_hpane.remove(*_active_view);
321 RouteParams_UI::route_removed (boost::weak_ptr<Route> wr)
323 boost::shared_ptr<Route> route (wr.lock());
329 ENSURE_GUI_THREAD (*this, invalidator (*this), &RouteParams_UI::route_removed, wr)
331 TreeModel::Children rows = route_display_model->children();
332 TreeModel::Children::iterator ri;
334 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
335 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
338 route_display_model->erase(iter);
343 if (route == _route) {
344 cleanup_io_selector();
346 cleanup_processor_boxes();
348 _route.reset ((Route*) 0);
349 _processor.reset ((Processor*) 0);
355 RouteParams_UI::set_session (Session *sess)
357 ArdourWindow::set_session (sess);
359 route_display_model->clear();
362 boost::shared_ptr<RouteList> r = _session->get_routes();
364 _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&RouteParams_UI::add_routes, this, _1), gui_context());
373 RouteParams_UI::session_going_away ()
375 ENSURE_GUI_THREAD (*this, &RouteParams_UI::session_going_away);
377 SessionHandlePtr::session_going_away ();
379 route_display_model->clear();
381 cleanup_io_selector();
383 cleanup_processor_boxes();
385 _route.reset ((Route*) 0);
386 _processor.reset ((Processor*) 0);
391 RouteParams_UI::route_selected()
393 Glib::RefPtr<TreeSelection> selection = route_display.get_selection();
394 TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
397 //If anything is selected
398 boost::shared_ptr<Route> route = (*iter)[route_display_columns.route] ;
400 if (_route == route) {
405 // remove event binding from previously selected
407 _route_processors_connection.disconnect ();
408 cleanup_processor_boxes();
410 cleanup_io_selector();
413 // update the other panes with the correct info
415 //update_routeinfo (route);
418 setup_processor_boxes();
420 route->processors_changed.connect (_route_processors_connection, invalidator (*this), boost::bind (&RouteParams_UI::processors_changed, this, _1), gui_context());
422 track_input_label.set_text (_route->name());
429 _route_processors_connection.disconnect ();
432 cleanup_io_selector();
434 cleanup_processor_boxes();
436 _route.reset ((Route*) 0);
437 _processor.reset ((Processor*) 0);
438 track_input_label.set_text(_("NO TRACK"));
445 RouteParams_UI::processors_changed (RouteProcessorChange)
449 _processor.reset ((Processor*) 0);
455 RouteParams_UI::show_track_menu()
457 using namespace Menu_Helpers;
459 if (track_menu == 0) {
460 track_menu = new Menu;
461 track_menu->set_name ("ArdourContextMenu");
462 track_menu->items().push_back (MenuElem (_("Add Track or Bus"), sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::add_route)));
464 track_menu->popup (1, gtk_get_current_event_time());
468 RouteParams_UI::redirect_selected (boost::shared_ptr<ARDOUR::Processor> proc)
470 boost::shared_ptr<Send> send;
471 boost::shared_ptr<Return> retrn;
472 boost::shared_ptr<PluginInsert> plugin_insert;
473 boost::shared_ptr<PortInsert> port_insert;
475 if ((boost::dynamic_pointer_cast<InternalSend> (proc)) != 0) {
477 _processor.reset ((Processor*) 0);
480 } else if ((send = boost::dynamic_pointer_cast<Send> (proc)) != 0) {
482 SendUI *send_ui = new SendUI (this, send, _session);
485 send->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::processor_going_away, this, boost::weak_ptr<Processor>(proc)), gui_context());
486 _active_view = send_ui;
488 redir_hpane.add (*_active_view);
489 redir_hpane.show_all();
491 } else if ((retrn = boost::dynamic_pointer_cast<Return> (proc)) != 0) {
493 ReturnUI *return_ui = new ReturnUI (this, retrn, _session);
496 retrn->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::processor_going_away, this, boost::weak_ptr<Processor>(proc)), gui_context());
497 _active_view = return_ui;
499 redir_hpane.add (*_active_view);
500 redir_hpane.show_all();
502 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (proc)) != 0) {
504 GenericPluginUI *plugin_ui = new GenericPluginUI (plugin_insert, true);
507 plugin_insert->plugin()->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::plugin_going_away, this, PreFader), gui_context());
508 plugin_ui->start_updating (0);
509 _active_view = plugin_ui;
511 redir_hpane.add (*_active_view);
512 redir_hpane.show_all();
514 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (proc)) != 0) {
516 PortInsertUI *portinsert_ui = new PortInsertUI (this, _session, port_insert);
519 port_insert->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::processor_going_away, this, boost::weak_ptr<Processor> (proc)), gui_context());
520 _active_view = portinsert_ui;
522 redir_hpane.add (*_active_view);
523 portinsert_ui->redisplay();
524 redir_hpane.show_all();
533 RouteParams_UI::plugin_going_away (Placement place)
535 ENSURE_GUI_THREAD (*this, &RouteParams_UI::plugin_going_away, place)
537 // delete the current view without calling finish
539 if (place == PreFader) {
540 cleanup_view (false);
541 _processor.reset ((Processor*) 0);
546 RouteParams_UI::processor_going_away (boost::weak_ptr<ARDOUR::Processor> wproc)
548 boost::shared_ptr<Processor> proc = (wproc.lock());
554 ENSURE_GUI_THREAD (*this, &RouteParams_UI::processor_going_away, wproc)
556 printf ("redirect going away\n");
557 // delete the current view without calling finish
558 if (proc == _processor) {
559 cleanup_view (false);
560 _processor.reset ((Processor*) 0);
565 RouteParams_UI::update_title ()
567 WindowTitle title (_("Tracks and Busses"));
570 title_label.set_text(_route->name());
571 title += _route->name();
572 set_title(title.get_string());
574 title_label.set_text(_("No Track or Bus Selected"));
575 title += _("No Track or Bus Selected");
576 set_title(title.get_string());
581 RouteParams_UI::start_updating ()
583 update_connection = Timers::rapid_connect
584 (sigc::mem_fun(*this, &RouteParams_UI::update_views));
588 RouteParams_UI::stop_updating ()
590 update_connection.disconnect();
594 RouteParams_UI::update_views ()
597 // TODO: only do it if correct tab is showing
599 if ((sui = dynamic_cast<SendUI*> (_active_view)) != 0) {