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;
62 RouteParams_UI::RouteParams_UI ()
63 : ArdourDialog ("track/bus inspector"),
64 latency_apply_button (Stock::APPLY),
73 using namespace Notebook_Helpers;
75 input_frame.set_shadow_type(Gtk::SHADOW_NONE);
76 output_frame.set_shadow_type(Gtk::SHADOW_NONE);
77 latency_frame.set_shadow_type (Gtk::SHADOW_NONE);
79 notebook.set_show_tabs (true);
80 notebook.set_show_border (true);
81 notebook.set_name ("RouteParamNotebook");
83 // create the tree model
84 route_display_model = ListStore::create(route_display_columns);
87 route_display.set_model(route_display_model);
88 route_display.append_column(_("Tracks/Busses"), route_display_columns.text);
89 route_display.set_name(X_("RouteParamsListDisplay"));
90 route_display.get_selection()->set_mode(Gtk::SELECTION_SINGLE); // default
91 route_display.set_reorderable(false);
92 route_display.set_size_request(75, -1);
93 route_display.set_headers_visible(true);
94 route_display.set_headers_clickable(true);
96 route_select_scroller.add(route_display);
97 route_select_scroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
99 route_select_frame.set_name("RouteSelectBaseFrame");
100 route_select_frame.set_shadow_type (Gtk::SHADOW_IN);
101 route_select_frame.add(route_select_scroller);
103 list_vpacker.pack_start (route_select_frame, true, true);
105 notebook.pages().push_back (TabElem (input_frame, _("Inputs")));
106 notebook.pages().push_back (TabElem (output_frame, _("Outputs")));
107 notebook.pages().push_back (TabElem (redir_hpane, _("Plugins, Inserts & Sends")));
108 notebook.pages().push_back (TabElem (latency_frame, _("Latency")));
110 notebook.set_name ("InspectorNotebook");
112 title_label.set_name ("RouteParamsTitleLabel");
115 latency_packer.set_spacing (18);
116 latency_button_box.pack_start (latency_apply_button);
117 delay_label.set_alignment (0, 0.5);
120 route_param_frame.set_name("RouteParamsBaseFrame");
121 route_param_frame.set_shadow_type (Gtk::SHADOW_IN);
124 route_hpacker.pack_start (notebook, true, true);
126 route_vpacker.pack_start (title_label, false, false);
127 route_vpacker.pack_start (route_hpacker, true, true);
130 list_hpane.pack1 (list_vpacker);
131 list_hpane.add2 (route_vpacker);
133 list_hpane.set_position(110);
135 redir_hpane.set_position(110);
137 //global_vpacker.pack_start (list_hpane, true, true);
138 //get_vbox()->pack_start (global_vpacker);
139 get_vbox()->pack_start (list_hpane);
142 set_name ("RouteParamsWindow");
143 set_default_size (620,370);
144 set_wmclass (X_("ardour_route_parameters"), "Ardour");
146 set_title (_("Track/Bus Inspector"));
149 route_display.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &RouteParams_UI::route_selected));
150 route_display.get_column(0)->signal_clicked().connect(sigc::mem_fun(*this, &RouteParams_UI::show_track_menu));
152 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
154 _plugin_selector = new PluginSelector (PluginManager::the_manager());
155 _plugin_selector->signal_delete_event().connect (sigc::bind (ptr_fun (just_hide_it),
156 static_cast<Window *> (_plugin_selector)));
159 signal_delete_event().connect(sigc::bind(ptr_fun(just_hide_it), static_cast<Gtk::Window *>(this)));
162 RouteParams_UI::~RouteParams_UI ()
167 RouteParams_UI::add_routes (RouteList& routes)
169 ENSURE_GUI_THREAD (*this, &RouteParams_UI::add_routes, routes)
171 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
172 boost::shared_ptr<Route> route = (*x);
174 if (route->is_hidden()) {
178 TreeModel::Row row = *(route_display_model->append());
179 row[route_display_columns.text] = route->name();
180 row[route_display_columns.route] = route;
182 //route_select_list.rows().back().select ();
184 route->NameChanged.connect (sigc::bind (sigc::mem_fun(*this, &RouteParams_UI::route_name_changed), route));
185 route->GoingAway.connect (sigc::bind (sigc::mem_fun(*this, &RouteParams_UI::route_removed), route));
191 RouteParams_UI::route_name_changed (boost::shared_ptr<Route> route)
193 ENSURE_GUI_THREAD (*this, &RouteParams_UI::route_name_changed, route)
196 TreeModel::Children rows = route_display_model->children();
197 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
198 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
200 (*iter)[route_display_columns.text] = route->name() ;
207 error << _("route display list item for renamed route not found!") << endmsg;
210 if (route == _route) {
211 track_input_label.set_text (route->name());
217 RouteParams_UI::setup_processor_boxes()
219 if (session && _route) {
221 // just in case... shouldn't need this
222 cleanup_processor_boxes();
224 // construct new redirect boxes
225 insert_box = new ProcessorBox(*session,
226 sigc::mem_fun(*this, &RouteParams_UI::plugin_selector), _rr_selection, 0);
227 insert_box->set_route (_route);
229 redir_hpane.pack1 (*insert_box);
231 insert_box->ProcessorSelected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected));
232 insert_box->ProcessorUnselected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected));
234 redir_hpane.show_all();
239 RouteParams_UI::cleanup_processor_boxes()
242 redir_hpane.remove(*insert_box);
249 RouteParams_UI::refresh_latency ()
251 if (latency_widget) {
252 latency_widget->refresh();
255 snprintf (buf, sizeof (buf), _("Playback delay: %u samples"), _route->initial_delay());
256 delay_label.set_text (buf);
261 RouteParams_UI::cleanup_latency_frame ()
263 if (latency_widget) {
264 latency_frame.remove ();
265 latency_packer.remove (*latency_widget);
266 latency_packer.remove (latency_button_box);
267 latency_packer.remove (delay_label);
268 delete latency_widget;
270 latency_conn.disconnect ();
271 delay_conn.disconnect ();
272 latency_apply_conn.disconnect ();
277 RouteParams_UI::setup_latency_frame ()
279 latency_widget = new LatencyGUI (*(_route->output()), session->frame_rate(), session->engine().frames_per_cycle());
282 snprintf (buf, sizeof (buf), _("Playback delay: %u samples"), _route->initial_delay());
283 delay_label.set_text (buf);
285 latency_packer.pack_start (*latency_widget, false, false);
286 latency_packer.pack_start (latency_button_box, false, false);
287 latency_packer.pack_start (delay_label);
289 latency_apply_conn = latency_apply_button.signal_clicked().connect (sigc::mem_fun (*latency_widget, &LatencyGUI::finish));
290 latency_conn = _route->signal_latency_changed.connect (sigc::mem_fun (*this, &RouteParams_UI::refresh_latency));
291 delay_conn = _route->initial_delay_changed.connect (sigc::mem_fun (*this, &RouteParams_UI::refresh_latency));
293 latency_frame.add (latency_packer);
294 latency_frame.show_all ();
298 RouteParams_UI::setup_io_frames()
303 _input_iosel = new IOSelector (this, session, _route->input());
304 _input_iosel->setup ();
305 input_frame.add (*_input_iosel);
306 input_frame.show_all();
309 _output_iosel = new IOSelector (this, session, _route->output());
310 _output_iosel->setup ();
311 output_frame.add (*_output_iosel);
312 output_frame.show_all();
316 RouteParams_UI::cleanup_io_frames()
319 _input_iosel->Finished (IOSelector::Cancelled);
320 input_frame.remove();
326 _output_iosel->Finished (IOSelector::Cancelled);
328 output_frame.remove();
329 delete _output_iosel;
335 RouteParams_UI::cleanup_view (bool stopupdate)
338 GenericPluginUI * plugui = 0;
340 if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_view)) != 0) {
341 plugui->stop_updating (0);
344 _plugin_conn.disconnect();
345 redir_hpane.remove(*_active_view);
352 RouteParams_UI::route_removed (boost::shared_ptr<Route> route)
354 ENSURE_GUI_THREAD (*this, &RouteParams_UI::route_removed, route)
356 TreeModel::Children rows = route_display_model->children();
357 TreeModel::Children::iterator ri;
359 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
360 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
363 route_display_model->erase(iter);
368 if (route == _route) {
371 cleanup_processor_boxes();
373 _route.reset ((Route*) 0);
374 _processor.reset ((Processor*) 0);
380 RouteParams_UI::set_session (Session *sess)
382 ArdourDialog::set_session (sess);
384 route_display_model->clear();
387 boost::shared_ptr<RouteList> r = session->get_routes();
389 session->GoingAway.connect (sigc::mem_fun(*this, &ArdourDialog::session_gone));
390 session->RouteAdded.connect (sigc::mem_fun(*this, &RouteParams_UI::add_routes));
396 //route_select_list.thaw ();
398 _plugin_selector->set_session (session);
403 RouteParams_UI::session_gone ()
405 ENSURE_GUI_THREAD (*this, &RouteParams_UI::session_gone)
407 route_display_model->clear();
411 cleanup_processor_boxes();
412 cleanup_latency_frame ();
414 _route.reset ((Route*) 0);
415 _processor.reset ((Processor*) 0);
418 ArdourDialog::session_gone();
423 RouteParams_UI::route_selected()
425 Glib::RefPtr<TreeSelection> selection = route_display.get_selection();
426 TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
429 //If anything is selected
430 boost::shared_ptr<Route> route = (*iter)[route_display_columns.route] ;
432 if (_route == route) {
437 // remove event binding from previously selected
439 _route_conn.disconnect();
440 _route_ds_conn.disconnect();
441 cleanup_processor_boxes();
444 cleanup_latency_frame ();
447 // update the other panes with the correct info
449 //update_routeinfo (route);
452 setup_processor_boxes();
453 setup_latency_frame ();
455 // sigc::bind to redirects changed event for this route
456 _route_conn = route->processors_changed.connect (sigc::mem_fun(*this, &RouteParams_UI::processors_changed));
458 track_input_label.set_text (_route->name());
465 _route_conn.disconnect();
470 cleanup_processor_boxes();
471 cleanup_latency_frame ();
473 _route.reset ((Route*) 0);
474 _processor.reset ((Processor*) 0);
475 track_input_label.set_text(_("NO TRACK"));
482 RouteParams_UI::processors_changed (RouteProcessorChange c)
484 ENSURE_GUI_THREAD (*this, &RouteParams_UI::processors_changed, c)
487 _processor.reset ((Processor*) 0);
493 RouteParams_UI::show_track_menu()
495 using namespace Menu_Helpers;
497 if (track_menu == 0) {
498 track_menu = new Menu;
499 track_menu->set_name ("ArdourContextMenu");
500 track_menu->items().push_back
501 (MenuElem (_("Add Track/Bus"),
502 sigc::bind (sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::add_route), (Gtk::Window*) 0)));
504 track_menu->popup (1, gtk_get_current_event_time());
508 RouteParams_UI::redirect_selected (boost::shared_ptr<ARDOUR::Processor> insert)
510 boost::shared_ptr<Send> send;
511 boost::shared_ptr<Return> retrn;
512 boost::shared_ptr<PluginInsert> plugin_insert;
513 boost::shared_ptr<PortInsert> port_insert;
515 if ((send = boost::dynamic_pointer_cast<Send> (insert)) != 0) {
517 SendUI *send_ui = new SendUI (this, send, *session);
520 _plugin_conn = send->GoingAway.connect (sigc::bind (sigc::mem_fun(*this, &RouteParams_UI::redirect_going_away),
522 _active_view = send_ui;
524 redir_hpane.add2 (*_active_view);
525 redir_hpane.show_all();
527 } else if ((retrn = boost::dynamic_pointer_cast<Return> (insert)) != 0) {
529 ReturnUI *return_ui = new ReturnUI (this, retrn, *session);
532 _plugin_conn = retrn->GoingAway.connect (sigc::bind (sigc::mem_fun(*this, &RouteParams_UI::redirect_going_away),
534 _active_view = return_ui;
536 redir_hpane.add2 (*_active_view);
537 redir_hpane.show_all();
539 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (insert)) != 0) {
541 GenericPluginUI *plugin_ui = new GenericPluginUI (plugin_insert, true);
544 _plugin_conn = plugin_insert->plugin()->GoingAway.connect (sigc::bind (sigc::mem_fun(*this, &RouteParams_UI::plugin_going_away),
546 plugin_ui->start_updating (0);
547 _active_view = plugin_ui;
548 redir_hpane.pack2 (*_active_view);
549 redir_hpane.show_all();
551 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (insert)) != 0) {
553 PortInsertUI *portinsert_ui = new PortInsertUI (this, session, port_insert);
556 _plugin_conn = port_insert->GoingAway.connect (sigc::bind (sigc::mem_fun(*this, &RouteParams_UI::redirect_going_away),
558 _active_view = portinsert_ui;
559 redir_hpane.pack2 (*_active_view);
560 portinsert_ui->redisplay();
561 redir_hpane.show_all();
571 RouteParams_UI::plugin_going_away (Placement place)
573 ENSURE_GUI_THREAD (*this, &RouteParams_UI::plugin_going_away, place)
575 // delete the current view without calling finish
577 if (place == PreFader) {
578 cleanup_view (false);
579 _processor.reset ((Processor*) 0);
584 RouteParams_UI::redirect_going_away (boost::shared_ptr<ARDOUR::Processor> insert)
587 ENSURE_GUI_THREAD (*this, &RouteParams_UI::redirect_going_away, insert)
589 printf ("redirect going away\n");
590 // delete the current view without calling finish
591 if (insert == _processor) {
592 cleanup_view (false);
593 _processor.reset ((Processor*) 0);
598 RouteParams_UI::update_title ()
600 WindowTitle title(_("Track/Bus Inspector"));
606 // if (_redirect && (_current_view == PLUGIN_CONFIG_VIEW || _current_view == SEND_CONFIG_VIEW)) {
607 // title += _redirect->name();
609 // else if (_current_view == INPUT_CONFIG_VIEW) {
610 // title += _("INPUT");
612 // else if (_current_view == OUTPUT_CONFIG_VIEW) {
613 // title += _("OUTPUT");
616 title_label.set_text(_route->name());
618 title += _route->name();
620 set_title(title.get_string());
623 title_label.set_text(_("No Route Selected"));
624 title += _("No Route Selected");
625 set_title(title.get_string());
630 RouteParams_UI::start_updating ()
632 update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect
633 (sigc::mem_fun(*this, &RouteParams_UI::update_views));
637 RouteParams_UI::stop_updating ()
639 update_connection.disconnect();
643 RouteParams_UI::update_views ()
646 // TODO: only do it if correct tab is showing
648 if ((sui = dynamic_cast<SendUI*> (_active_view)) != 0) {