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"))
74 using namespace Notebook_Helpers;
76 input_frame.set_shadow_type(Gtk::SHADOW_NONE);
77 output_frame.set_shadow_type(Gtk::SHADOW_NONE);
78 latency_frame.set_shadow_type (Gtk::SHADOW_NONE);
80 notebook.set_show_tabs (true);
81 notebook.set_show_border (true);
82 notebook.set_name ("RouteParamNotebook");
84 // create the tree model
85 route_display_model = ListStore::create(route_display_columns);
88 route_display.set_model(route_display_model);
89 route_display.append_column(_("Tracks/Busses"), route_display_columns.text);
90 route_display.set_name(X_("RouteParamsListDisplay"));
91 route_display.get_selection()->set_mode(Gtk::SELECTION_SINGLE); // default
92 route_display.set_reorderable(false);
93 route_display.set_size_request(75, -1);
94 route_display.set_headers_visible(true);
95 route_display.set_headers_clickable(true);
97 dynamic_cast<Gtk::CellRendererText*>(route_display.get_column_cell_renderer(0))->property_ellipsize() = Pango::ELLIPSIZE_START;
99 route_select_scroller.add(route_display);
100 route_select_scroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
102 route_select_frame.set_name("RouteSelectBaseFrame");
103 route_select_frame.set_shadow_type (Gtk::SHADOW_IN);
104 route_select_frame.add(route_select_scroller);
106 list_vpacker.pack_start (route_select_frame, true, true);
108 notebook.pages().push_back (TabElem (input_frame, _("Inputs")));
109 notebook.pages().push_back (TabElem (output_frame, _("Outputs")));
110 notebook.pages().push_back (TabElem (redir_hpane, _("Plugins, Inserts & Sends")));
111 notebook.pages().push_back (TabElem (latency_frame, _("Latency")));
113 notebook.set_name ("InspectorNotebook");
115 title_label.set_name ("RouteParamsTitleLabel");
118 latency_packer.set_spacing (18);
119 delay_label.set_alignment (0, 0.5);
122 route_param_frame.set_name("RouteParamsBaseFrame");
123 route_param_frame.set_shadow_type (Gtk::SHADOW_IN);
125 route_hpacker.pack_start (notebook, true, true);
127 route_vpacker.pack_start (title_label, false, false);
128 route_vpacker.pack_start (route_hpacker, true, true);
130 list_hpane.add (list_vpacker);
131 list_hpane.add (route_vpacker);
135 set_name ("RouteParamsWindow");
136 set_default_size (620,370);
137 set_wmclass (X_("ardour_route_parameters"), PROGRAM_NAME);
140 route_display.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &RouteParams_UI::route_selected));
141 route_display.get_column(0)->signal_clicked().connect(sigc::mem_fun(*this, &RouteParams_UI::show_track_menu));
143 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
148 RouteParams_UI::~RouteParams_UI ()
154 RouteParams_UI::add_routes (RouteList& routes)
156 ENSURE_GUI_THREAD (*this, &RouteParams_UI::add_routes, routes)
158 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
159 boost::shared_ptr<Route> route = (*x);
161 if (route->is_auditioner()) {
165 TreeModel::Row row = *(route_display_model->append());
166 row[route_display_columns.text] = route->name();
167 row[route_display_columns.route] = route;
169 //route_select_list.rows().back().select ();
171 route->PropertyChanged.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_property_changed, this, _1, boost::weak_ptr<Route>(route)), gui_context());
172 route->DropReferences.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_removed, this, boost::weak_ptr<Route>(route)), gui_context());
178 RouteParams_UI::route_property_changed (const PropertyChange& what_changed, boost::weak_ptr<Route> wr)
180 if (!what_changed.contains (ARDOUR::Properties::name)) {
184 boost::shared_ptr<Route> route (wr.lock());
190 ENSURE_GUI_THREAD (*this, &RouteParams_UI::route_name_changed, wr)
193 TreeModel::Children rows = route_display_model->children();
194 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
195 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
197 (*iter)[route_display_columns.text] = route->name() ;
204 error << _("route display list item for renamed route not found!") << endmsg;
207 if (route == _route) {
208 track_input_label.set_text (route->name());
214 RouteParams_UI::map_frozen()
216 ENSURE_GUI_THREAD (*this, &RouteParams_UI::map_frozen)
217 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(_route);
218 if (at && insert_box) {
219 switch (at->freeze_state()) {
220 case AudioTrack::Frozen:
221 insert_box->set_sensitive (false);
222 //hide_redirect_editors (); // TODO hide editor windows
225 insert_box->set_sensitive (true);
226 // XXX need some way, maybe, to retoggle redirect editors
233 RouteParams_UI::plugin_selector() {
234 return Mixer_UI::instance()->plugin_selector ();
238 RouteParams_UI::setup_processor_boxes()
240 if (_session && _route) {
242 // just in case... shouldn't need this
243 cleanup_processor_boxes();
245 // construct new redirect boxes
246 insert_box = new ProcessorBox (_session, boost::bind (&RouteParams_UI::plugin_selector, this), _p_selection, 0);
247 insert_box->set_route (_route);
249 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(_route);
251 at->FreezeChange.connect (route_connections, invalidator (*this), boost::bind (&RouteParams_UI::map_frozen, this), gui_context());
253 redir_hpane.add (*insert_box);
255 insert_box->ProcessorSelected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected)); //note: this indicates a double-click activation, not just a "selection"
256 insert_box->ProcessorUnselected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected));
258 redir_hpane.show_all();
263 RouteParams_UI::cleanup_processor_boxes()
266 redir_hpane.remove(*insert_box);
273 RouteParams_UI::refresh_latency ()
275 if (latency_widget) {
276 latency_widget->refresh();
279 snprintf (buf, sizeof (buf), _("Latency: %" PRId64 " samples"), _route->signal_latency ());
280 delay_label.set_text (buf);
285 RouteParams_UI::cleanup_latency_frame ()
287 if (latency_widget) {
288 latency_frame.remove ();
289 latency_packer.remove (*latency_widget);
290 latency_packer.remove (delay_label);
291 latency_connections.drop_connections ();
292 latency_click_connection.disconnect ();
294 delete latency_widget;
301 RouteParams_UI::setup_latency_frame ()
303 latency_widget = new LatencyGUI (*(_route->output()), _session->sample_rate(), AudioEngine::instance()->samples_per_cycle());
307 latency_packer.pack_start (*latency_widget, false, false);
308 latency_packer.pack_start (delay_label, false, false);
310 _route->signal_latency_updated.connect (latency_connections, invalidator (*this), boost::bind (&RouteParams_UI::refresh_latency, this), gui_context());
312 latency_frame.add (latency_packer);
313 latency_frame.show_all ();
317 RouteParams_UI::setup_io_selector()
319 cleanup_io_selector();
322 _input_iosel = new IOSelector (this, _session, _route->input());
323 _input_iosel->setup ();
324 input_frame.add (*_input_iosel);
325 input_frame.show_all();
328 _output_iosel = new IOSelector (this, _session, _route->output());
329 _output_iosel->setup ();
330 output_frame.add (*_output_iosel);
331 output_frame.show_all();
335 RouteParams_UI::cleanup_io_selector()
338 _input_iosel->Finished (IOSelector::Cancelled);
339 input_frame.remove();
345 _output_iosel->Finished (IOSelector::Cancelled);
347 output_frame.remove();
348 delete _output_iosel;
354 RouteParams_UI::cleanup_view (bool stopupdate)
357 GenericPluginUI* plugui = 0;
359 if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_view)) != 0) {
360 plugui->stop_updating (0);
363 _processor_going_away_connection.disconnect ();
364 redir_hpane.remove(*_active_view);
371 RouteParams_UI::route_removed (boost::weak_ptr<Route> wr)
373 boost::shared_ptr<Route> route (wr.lock());
379 ENSURE_GUI_THREAD (*this, invalidator (*this), &RouteParams_UI::route_removed, wr)
381 TreeModel::Children rows = route_display_model->children();
382 TreeModel::Children::iterator ri;
384 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
385 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
388 route_display_model->erase(iter);
393 if (route == _route) {
394 cleanup_io_selector();
396 cleanup_processor_boxes();
398 _route.reset ((Route*) 0);
399 _processor.reset ((Processor*) 0);
405 RouteParams_UI::set_session (Session *sess)
407 ArdourWindow::set_session (sess);
409 route_display_model->clear();
412 boost::shared_ptr<RouteList> r = _session->get_routes();
414 _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&RouteParams_UI::add_routes, this, _1), gui_context());
423 RouteParams_UI::session_going_away ()
425 ENSURE_GUI_THREAD (*this, &RouteParams_UI::session_going_away);
427 SessionHandlePtr::session_going_away ();
429 route_display_model->clear();
431 cleanup_io_selector();
433 cleanup_processor_boxes();
434 cleanup_latency_frame ();
436 _route.reset ((Route*) 0);
437 _processor.reset ((Processor*) 0);
442 RouteParams_UI::route_selected()
444 Glib::RefPtr<TreeSelection> selection = route_display.get_selection();
445 TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
448 //If anything is selected
449 boost::shared_ptr<Route> route = (*iter)[route_display_columns.route] ;
451 if (_route == route) {
456 // remove event binding from previously selected
458 _route_processors_connection.disconnect ();
459 cleanup_processor_boxes();
461 cleanup_io_selector();
462 cleanup_latency_frame ();
465 // update the other panes with the correct info
467 //update_routeinfo (route);
470 setup_processor_boxes();
471 setup_latency_frame ();
473 route->processors_changed.connect (_route_processors_connection, invalidator (*this), boost::bind (&RouteParams_UI::processors_changed, this, _1), gui_context());
475 track_input_label.set_text (_route->name());
482 _route_processors_connection.disconnect ();
485 cleanup_io_selector();
487 cleanup_processor_boxes();
488 cleanup_latency_frame ();
490 _route.reset ((Route*) 0);
491 _processor.reset ((Processor*) 0);
492 track_input_label.set_text(_("NO TRACK"));
499 RouteParams_UI::processors_changed (RouteProcessorChange)
503 _processor.reset ((Processor*) 0);
509 RouteParams_UI::show_track_menu()
511 using namespace Menu_Helpers;
513 if (track_menu == 0) {
514 track_menu = new Menu;
515 track_menu->set_name ("ArdourContextMenu");
516 track_menu->items().push_back (MenuElem (_("Add Track or Bus"), sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::add_route)));
518 track_menu->popup (1, gtk_get_current_event_time());
522 RouteParams_UI::redirect_selected (boost::shared_ptr<ARDOUR::Processor> proc)
524 boost::shared_ptr<Send> send;
525 boost::shared_ptr<Return> retrn;
526 boost::shared_ptr<PluginInsert> plugin_insert;
527 boost::shared_ptr<PortInsert> port_insert;
529 if ((boost::dynamic_pointer_cast<InternalSend> (proc)) != 0) {
531 _processor.reset ((Processor*) 0);
534 } else if ((send = boost::dynamic_pointer_cast<Send> (proc)) != 0) {
536 SendUI *send_ui = new SendUI (this, send, _session);
539 send->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::processor_going_away, this, boost::weak_ptr<Processor>(proc)), gui_context());
540 _active_view = send_ui;
542 redir_hpane.add (*_active_view);
543 redir_hpane.show_all();
545 } else if ((retrn = boost::dynamic_pointer_cast<Return> (proc)) != 0) {
547 ReturnUI *return_ui = new ReturnUI (this, retrn, _session);
550 retrn->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::processor_going_away, this, boost::weak_ptr<Processor>(proc)), gui_context());
551 _active_view = return_ui;
553 redir_hpane.add (*_active_view);
554 redir_hpane.show_all();
556 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (proc)) != 0) {
558 GenericPluginUI *plugin_ui = new GenericPluginUI (plugin_insert, true);
561 plugin_insert->plugin()->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::plugin_going_away, this, PreFader), gui_context());
562 plugin_ui->start_updating (0);
563 _active_view = plugin_ui;
565 redir_hpane.add (*_active_view);
566 redir_hpane.show_all();
568 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (proc)) != 0) {
570 PortInsertUI *portinsert_ui = new PortInsertUI (this, _session, port_insert);
573 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());
574 _active_view = portinsert_ui;
576 redir_hpane.add (*_active_view);
577 portinsert_ui->redisplay();
578 redir_hpane.show_all();
587 RouteParams_UI::plugin_going_away (Placement place)
589 ENSURE_GUI_THREAD (*this, &RouteParams_UI::plugin_going_away, place)
591 // delete the current view without calling finish
593 if (place == PreFader) {
594 cleanup_view (false);
595 _processor.reset ((Processor*) 0);
600 RouteParams_UI::processor_going_away (boost::weak_ptr<ARDOUR::Processor> wproc)
602 boost::shared_ptr<Processor> proc = (wproc.lock());
608 ENSURE_GUI_THREAD (*this, &RouteParams_UI::processor_going_away, wproc)
610 printf ("redirect going away\n");
611 // delete the current view without calling finish
612 if (proc == _processor) {
613 cleanup_view (false);
614 _processor.reset ((Processor*) 0);
619 RouteParams_UI::update_title ()
621 WindowTitle title (_("Tracks and Busses"));
624 title_label.set_text(_route->name());
625 title += _route->name();
626 set_title(title.get_string());
628 title_label.set_text(_("No Track or Bus Selected"));
629 title += _("No Track or Bus Selected");
630 set_title(title.get_string());
635 RouteParams_UI::start_updating ()
637 update_connection = Timers::rapid_connect
638 (sigc::mem_fun(*this, &RouteParams_UI::update_views));
642 RouteParams_UI::stop_updating ()
644 update_connection.disconnect();
648 RouteParams_UI::update_views ()
651 // TODO: only do it if correct tab is showing
653 if ((sui = dynamic_cast<SendUI*> (_active_view)) != 0) {