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.
21 #define __STDC_FORMAT_MACROS
24 #include <glibmm/thread.h>
25 #include <gtkmm2ext/utils.h>
26 #include <gtkmm2ext/stop_signal.h>
27 #include <gtkmm2ext/window_title.h>
29 #include "ardour/ardour.h"
30 #include "ardour/audio_diskstream.h"
31 #include "ardour/audio_track.h"
32 #include "ardour/plugin.h"
33 #include "ardour/plugin_insert.h"
34 #include "ardour/plugin_manager.h"
35 #include "ardour/port_insert.h"
36 #include "ardour/return.h"
37 #include "ardour/route.h"
38 #include "ardour/send.h"
39 #include "ardour/session.h"
40 #include "ardour/session.h"
41 #include "ardour/session_route.h"
43 #include "ardour_ui.h"
44 #include "gui_thread.h"
45 #include "io_selector.h"
47 #include "mixer_strip.h"
48 #include "plugin_selector.h"
49 #include "plugin_ui.h"
50 #include "return_ui.h"
51 #include "route_params_ui.h"
57 using namespace ARDOUR;
60 using namespace Gtkmm2ext;
63 RouteParams_UI::RouteParams_UI ()
64 : ArdourDialog ("track/bus inspector"),
65 latency_apply_button (Stock::APPLY),
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 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")));
109 notebook.pages().push_back (TabElem (latency_frame, _("Latency")));
111 notebook.set_name ("InspectorNotebook");
113 title_label.set_name ("RouteParamsTitleLabel");
116 latency_packer.set_spacing (18);
117 latency_button_box.pack_start (latency_apply_button);
118 delay_label.set_alignment (0, 0.5);
121 route_param_frame.set_name("RouteParamsBaseFrame");
122 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);
131 list_hpane.pack1 (list_vpacker);
132 list_hpane.add2 (route_vpacker);
134 list_hpane.set_position(110);
136 redir_hpane.set_position(110);
138 //global_vpacker.pack_start (list_hpane, true, true);
139 //get_vbox()->pack_start (global_vpacker);
140 get_vbox()->pack_start (list_hpane);
143 set_name ("RouteParamsWindow");
144 set_default_size (620,370);
145 set_wmclass (X_("ardour_route_parameters"), "Ardour");
147 set_title (_("Track/Bus Inspector"));
150 route_display.get_selection()->signal_changed().connect(mem_fun(*this, &RouteParams_UI::route_selected));
151 route_display.get_column(0)->signal_clicked().connect(mem_fun(*this, &RouteParams_UI::show_track_menu));
153 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
155 _plugin_selector = new PluginSelector (PluginManager::the_manager());
156 _plugin_selector->signal_delete_event().connect (bind (ptr_fun (just_hide_it),
157 static_cast<Window *> (_plugin_selector)));
160 signal_delete_event().connect(bind(ptr_fun(just_hide_it), static_cast<Gtk::Window *>(this)));
163 RouteParams_UI::~RouteParams_UI ()
168 RouteParams_UI::add_routes (RouteList& routes)
170 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::add_routes), routes));
172 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
173 boost::shared_ptr<Route> route = (*x);
175 if (route->is_hidden()) {
179 TreeModel::Row row = *(route_display_model->append());
180 row[route_display_columns.text] = route->name();
181 row[route_display_columns.route] = route;
183 //route_select_list.rows().back().select ();
185 route->NameChanged.connect (bind (mem_fun(*this, &RouteParams_UI::route_name_changed), route));
186 route->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::route_removed), route));
192 RouteParams_UI::route_name_changed (boost::shared_ptr<Route> route)
194 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::route_name_changed), route));
197 TreeModel::Children rows = route_display_model->children();
198 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
199 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
201 (*iter)[route_display_columns.text] = route->name() ;
208 error << _("route display list item for renamed route not found!") << endmsg;
211 if (route == _route) {
212 track_input_label.set_text (route->name());
218 RouteParams_UI::setup_processor_boxes()
220 if (session && _route) {
222 // just in case... shouldn't need this
223 cleanup_processor_boxes();
225 // construct new redirect boxes
226 insert_box = new ProcessorBox(*session,
227 sigc::mem_fun(*this, &RouteParams_UI::plugin_selector), _rr_selection, 0);
228 insert_box->set_route (_route);
230 redir_hpane.pack1 (*insert_box);
232 insert_box->ProcessorSelected.connect (mem_fun(*this, &RouteParams_UI::redirect_selected));
233 insert_box->ProcessorUnselected.connect (mem_fun(*this, &RouteParams_UI::redirect_selected));
235 redir_hpane.show_all();
240 RouteParams_UI::cleanup_processor_boxes()
243 redir_hpane.remove(*insert_box);
250 RouteParams_UI::refresh_latency ()
252 if (latency_widget) {
253 latency_widget->refresh();
256 snprintf (buf, sizeof (buf), _("Playback delay: %u samples"), _route->initial_delay());
257 delay_label.set_text (buf);
262 RouteParams_UI::cleanup_latency_frame ()
264 if (latency_widget) {
265 latency_frame.remove ();
266 latency_packer.remove (*latency_widget);
267 latency_packer.remove (latency_button_box);
268 latency_packer.remove (delay_label);
269 delete latency_widget;
271 latency_conn.disconnect ();
272 delay_conn.disconnect ();
273 latency_apply_conn.disconnect ();
278 RouteParams_UI::setup_latency_frame ()
280 latency_widget = new LatencyGUI (*(_route->output()), session->frame_rate(), session->engine().frames_per_cycle());
283 snprintf (buf, sizeof (buf), _("Playback delay: %u samples"), _route->initial_delay());
284 delay_label.set_text (buf);
286 latency_packer.pack_start (*latency_widget, false, false);
287 latency_packer.pack_start (latency_button_box, false, false);
288 latency_packer.pack_start (delay_label);
290 latency_apply_conn = latency_apply_button.signal_clicked().connect (mem_fun (*latency_widget, &LatencyGUI::finish));
291 latency_conn = _route->signal_latency_changed.connect (mem_fun (*this, &RouteParams_UI::refresh_latency));
292 delay_conn = _route->initial_delay_changed.connect (mem_fun (*this, &RouteParams_UI::refresh_latency));
294 latency_frame.add (latency_packer);
295 latency_frame.show_all ();
299 RouteParams_UI::setup_io_frames()
304 _input_iosel = new IOSelector (this, session, _route->input());
305 _input_iosel->setup ();
306 input_frame.add (*_input_iosel);
307 input_frame.show_all();
310 _output_iosel = new IOSelector (this, session, _route->output());
311 _output_iosel->setup ();
312 output_frame.add (*_output_iosel);
313 output_frame.show_all();
317 RouteParams_UI::cleanup_io_frames()
320 _input_iosel->Finished (IOSelector::Cancelled);
321 input_frame.remove();
327 _output_iosel->Finished (IOSelector::Cancelled);
329 output_frame.remove();
330 delete _output_iosel;
336 RouteParams_UI::cleanup_view (bool stopupdate)
339 GenericPluginUI * plugui = 0;
341 if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_view)) != 0) {
342 plugui->stop_updating (0);
345 _plugin_conn.disconnect();
346 redir_hpane.remove(*_active_view);
353 RouteParams_UI::route_removed (boost::shared_ptr<Route> route)
355 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::route_removed), route));
357 TreeModel::Children rows = route_display_model->children();
358 TreeModel::Children::iterator ri;
360 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
361 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
364 route_display_model->erase(iter);
369 if (route == _route) {
372 cleanup_processor_boxes();
374 _route.reset ((Route*) 0);
375 _processor.reset ((Processor*) 0);
381 RouteParams_UI::set_session (Session *sess)
383 ArdourDialog::set_session (sess);
385 route_display_model->clear();
388 boost::shared_ptr<RouteList> r = session->get_routes();
390 session->GoingAway.connect (mem_fun(*this, &ArdourDialog::session_gone));
391 session->RouteAdded.connect (mem_fun(*this, &RouteParams_UI::add_routes));
397 //route_select_list.thaw ();
399 _plugin_selector->set_session (session);
404 RouteParams_UI::session_gone ()
406 ENSURE_GUI_THREAD(mem_fun(*this, &RouteParams_UI::session_gone));
408 route_display_model->clear();
412 cleanup_processor_boxes();
413 cleanup_latency_frame ();
415 _route.reset ((Route*) 0);
416 _processor.reset ((Processor*) 0);
419 ArdourDialog::session_gone();
424 RouteParams_UI::route_selected()
426 Glib::RefPtr<TreeSelection> selection = route_display.get_selection();
427 TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
430 //If anything is selected
431 boost::shared_ptr<Route> route = (*iter)[route_display_columns.route] ;
433 if (_route == route) {
438 // remove event binding from previously selected
440 _route_conn.disconnect();
441 _route_ds_conn.disconnect();
442 cleanup_processor_boxes();
445 cleanup_latency_frame ();
448 // update the other panes with the correct info
450 //update_routeinfo (route);
453 setup_processor_boxes();
454 setup_latency_frame ();
456 // bind to redirects changed event for this route
457 _route_conn = route->processors_changed.connect (mem_fun(*this, &RouteParams_UI::processors_changed));
459 track_input_label.set_text (_route->name());
466 _route_conn.disconnect();
471 cleanup_processor_boxes();
472 cleanup_latency_frame ();
474 _route.reset ((Route*) 0);
475 _processor.reset ((Processor*) 0);
476 track_input_label.set_text(_("NO TRACK"));
483 RouteParams_UI::processors_changed (RouteProcessorChange c)
485 ENSURE_GUI_THREAD (bind (mem_fun (*this, &RouteParams_UI::processors_changed), c));
488 _processor.reset ((Processor*) 0);
494 RouteParams_UI::show_track_menu()
496 using namespace Menu_Helpers;
498 if (track_menu == 0) {
499 track_menu = new Menu;
500 track_menu->set_name ("ArdourContextMenu");
501 track_menu->items().push_back
502 (MenuElem (_("Add Track/Bus"),
503 bind (mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::add_route), (Gtk::Window*) 0)));
505 track_menu->popup (1, gtk_get_current_event_time());
509 RouteParams_UI::redirect_selected (boost::shared_ptr<ARDOUR::Processor> insert)
511 boost::shared_ptr<Send> send;
512 boost::shared_ptr<Return> retrn;
513 boost::shared_ptr<PluginInsert> plugin_insert;
514 boost::shared_ptr<PortInsert> port_insert;
516 if ((send = boost::dynamic_pointer_cast<Send> (insert)) != 0) {
518 SendUI *send_ui = new SendUI (this, send, *session);
521 _plugin_conn = send->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away),
523 _active_view = send_ui;
525 redir_hpane.add2 (*_active_view);
526 redir_hpane.show_all();
528 } else if ((retrn = boost::dynamic_pointer_cast<Return> (insert)) != 0) {
530 ReturnUI *return_ui = new ReturnUI (this, retrn, *session);
533 _plugin_conn = retrn->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away),
535 _active_view = return_ui;
537 redir_hpane.add2 (*_active_view);
538 redir_hpane.show_all();
540 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (insert)) != 0) {
542 GenericPluginUI *plugin_ui = new GenericPluginUI (plugin_insert, true);
545 _plugin_conn = plugin_insert->plugin()->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::plugin_going_away),
547 plugin_ui->start_updating (0);
548 _active_view = plugin_ui;
549 redir_hpane.pack2 (*_active_view);
550 redir_hpane.show_all();
552 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (insert)) != 0) {
554 PortInsertUI *portinsert_ui = new PortInsertUI (this, session, port_insert);
557 _plugin_conn = port_insert->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away),
559 _active_view = portinsert_ui;
560 redir_hpane.pack2 (*_active_view);
561 portinsert_ui->redisplay();
562 redir_hpane.show_all();
572 RouteParams_UI::plugin_going_away (Placement place)
574 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::plugin_going_away), place));
576 // delete the current view without calling finish
578 if (place == PreFader) {
579 cleanup_view (false);
580 _processor.reset ((Processor*) 0);
585 RouteParams_UI::redirect_going_away (boost::shared_ptr<ARDOUR::Processor> insert)
588 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), insert));
590 printf ("redirect going away\n");
591 // delete the current view without calling finish
592 if (insert == _processor) {
593 cleanup_view (false);
594 _processor.reset ((Processor*) 0);
599 RouteParams_UI::update_title ()
601 WindowTitle title(_("Track/Bus Inspector"));
607 // if (_redirect && (_current_view == PLUGIN_CONFIG_VIEW || _current_view == SEND_CONFIG_VIEW)) {
608 // title += _redirect->name();
610 // else if (_current_view == INPUT_CONFIG_VIEW) {
611 // title += _("INPUT");
613 // else if (_current_view == OUTPUT_CONFIG_VIEW) {
614 // title += _("OUTPUT");
617 title_label.set_text(_route->name());
619 title += _route->name();
621 set_title(title.get_string());
624 title_label.set_text(_("No Route Selected"));
625 title += _("No Route Selected");
626 set_title(title.get_string());
631 RouteParams_UI::start_updating ()
633 update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect
634 (mem_fun(*this, &RouteParams_UI::update_views));
638 RouteParams_UI::stop_updating ()
640 update_connection.disconnect();
644 RouteParams_UI::update_views ()
647 // TODO: only do it if correct tab is showing
649 if ((sui = dynamic_cast<SendUI*> (_active_view)) != 0) {