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),
75 using namespace Notebook_Helpers;
77 input_frame.set_shadow_type(Gtk::SHADOW_NONE);
78 output_frame.set_shadow_type(Gtk::SHADOW_NONE);
79 latency_frame.set_shadow_type (Gtk::SHADOW_NONE);
81 notebook.set_show_tabs (true);
82 notebook.set_show_border (true);
83 notebook.set_name ("RouteParamNotebook");
85 // create the tree model
86 route_display_model = ListStore::create(route_display_columns);
89 route_display.set_model(route_display_model);
90 route_display.append_column(_("Tracks/Busses"), route_display_columns.text);
91 route_display.set_name(X_("RouteParamsListDisplay"));
92 route_display.get_selection()->set_mode(Gtk::SELECTION_SINGLE); // default
93 route_display.set_reorderable(false);
94 route_display.set_size_request(75, -1);
95 route_display.set_headers_visible(true);
96 route_display.set_headers_clickable(true);
98 route_select_scroller.add(route_display);
99 route_select_scroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
101 route_select_frame.set_name("RouteSelectBaseFrame");
102 route_select_frame.set_shadow_type (Gtk::SHADOW_IN);
103 route_select_frame.add(route_select_scroller);
105 list_vpacker.pack_start (route_select_frame, true, true);
107 notebook.pages().push_back (TabElem (input_frame, _("Inputs")));
108 notebook.pages().push_back (TabElem (output_frame, _("Outputs")));
109 notebook.pages().push_back (TabElem (redir_hpane, _("Plugins, Inserts & Sends")));
110 notebook.pages().push_back (TabElem (latency_frame, _("Latency")));
112 notebook.set_name ("InspectorNotebook");
114 title_label.set_name ("RouteParamsTitleLabel");
117 latency_packer.set_spacing (18);
118 latency_button_box.pack_start (latency_apply_button);
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);
126 route_hpacker.pack_start (notebook, true, true);
128 route_vpacker.pack_start (title_label, false, false);
129 route_vpacker.pack_start (route_hpacker, true, true);
132 list_hpane.pack1 (list_vpacker);
133 list_hpane.add2 (route_vpacker);
135 list_hpane.set_position(110);
137 redir_hpane.set_position(110);
139 //global_vpacker.pack_start (list_hpane, true, true);
140 //get_vbox()->pack_start (global_vpacker);
141 get_vbox()->pack_start (list_hpane);
144 set_name ("RouteParamsWindow");
145 set_default_size (620,370);
146 set_wmclass (X_("ardour_route_parameters"), "Ardour");
148 WindowTitle title(Glib::get_application_name());
149 title += _("Track/Bus Inspector");
150 set_title (title.get_string());
154 route_display.get_selection()->signal_changed().connect(mem_fun(*this, &RouteParams_UI::route_selected));
155 route_display.get_column(0)->signal_clicked().connect(mem_fun(*this, &RouteParams_UI::show_track_menu));
157 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
159 _plugin_selector = new PluginSelector (PluginManager::the_manager());
160 _plugin_selector->signal_delete_event().connect (bind (ptr_fun (just_hide_it),
161 static_cast<Window *> (_plugin_selector)));
164 signal_delete_event().connect(bind(ptr_fun(just_hide_it), static_cast<Gtk::Window *>(this)));
167 RouteParams_UI::~RouteParams_UI ()
172 RouteParams_UI::add_routes (RouteList& routes)
174 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::add_routes), routes));
176 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
177 boost::shared_ptr<Route> route = (*x);
179 if (route->is_hidden()) {
183 TreeModel::Row row = *(route_display_model->append());
184 row[route_display_columns.text] = route->name();
185 row[route_display_columns.route] = route;
187 //route_select_list.rows().back().select ();
189 route->NameChanged.connect (bind (mem_fun(*this, &RouteParams_UI::route_name_changed), route));
190 route->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::route_removed), route));
196 RouteParams_UI::route_name_changed (boost::shared_ptr<Route> route)
198 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::route_name_changed), route));
201 TreeModel::Children rows = route_display_model->children();
202 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
203 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
205 (*iter)[route_display_columns.text] = route->name() ;
212 error << _("route display list item for renamed route not found!") << endmsg;
215 if (route == _route) {
216 track_input_label.set_text (route->name());
222 RouteParams_UI::setup_processor_boxes()
224 if (session && _route) {
226 // just in case... shouldn't need this
227 cleanup_processor_boxes();
229 // construct new redirect boxes
230 insert_box = new ProcessorBox(*session, *_plugin_selector, _rr_selection, 0);
231 insert_box->set_route (_route);
233 redir_hpane.pack1 (*insert_box);
235 insert_box->ProcessorSelected.connect (mem_fun(*this, &RouteParams_UI::redirect_selected));
236 insert_box->ProcessorUnselected.connect (mem_fun(*this, &RouteParams_UI::redirect_selected));
238 redir_hpane.show_all();
243 RouteParams_UI::cleanup_processor_boxes()
246 redir_hpane.remove(*insert_box);
253 RouteParams_UI::refresh_latency ()
255 if (latency_widget) {
256 latency_widget->refresh();
259 snprintf (buf, sizeof (buf), _("Playback delay: %u samples"), _route->initial_delay());
260 delay_label.set_text (buf);
265 RouteParams_UI::cleanup_latency_frame ()
267 if (latency_widget) {
268 latency_frame.remove ();
269 latency_packer.remove (*latency_widget);
270 latency_packer.remove (latency_button_box);
271 latency_packer.remove (delay_label);
272 delete latency_widget;
274 latency_conn.disconnect ();
275 delay_conn.disconnect ();
276 latency_apply_conn.disconnect ();
281 RouteParams_UI::setup_latency_frame ()
283 latency_widget = new LatencyGUI (*(_route->output()), session->frame_rate(), session->engine().frames_per_cycle());
286 snprintf (buf, sizeof (buf), _("Playback delay: %u samples"), _route->initial_delay());
287 delay_label.set_text (buf);
289 latency_packer.pack_start (*latency_widget, false, false);
290 latency_packer.pack_start (latency_button_box, false, false);
291 latency_packer.pack_start (delay_label);
293 latency_apply_conn = latency_apply_button.signal_clicked().connect (mem_fun (*latency_widget, &LatencyGUI::finish));
294 latency_conn = _route->signal_latency_changed.connect (mem_fun (*this, &RouteParams_UI::refresh_latency));
295 delay_conn = _route->initial_delay_changed.connect (mem_fun (*this, &RouteParams_UI::refresh_latency));
297 latency_frame.add (latency_packer);
298 latency_frame.show_all ();
302 RouteParams_UI::setup_io_frames()
307 _input_iosel = new IOSelector (this, *session, _route->input());
308 _input_iosel->setup ();
309 input_frame.add (*_input_iosel);
310 input_frame.show_all();
313 _output_iosel = new IOSelector (this, *session, _route->output());
314 _output_iosel->setup ();
315 output_frame.add (*_output_iosel);
316 output_frame.show_all();
320 RouteParams_UI::cleanup_io_frames()
323 _input_iosel->Finished (IOSelector::Cancelled);
324 input_frame.remove();
330 _output_iosel->Finished (IOSelector::Cancelled);
332 output_frame.remove();
333 delete _output_iosel;
339 RouteParams_UI::cleanup_view (bool stopupdate)
342 GenericPluginUI * plugui = 0;
344 if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_view)) != 0) {
345 plugui->stop_updating (0);
348 _plugin_conn.disconnect();
349 redir_hpane.remove(*_active_view);
356 RouteParams_UI::route_removed (boost::shared_ptr<Route> route)
358 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::route_removed), route));
360 TreeModel::Children rows = route_display_model->children();
361 TreeModel::Children::iterator ri;
363 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
364 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
367 route_display_model->erase(iter);
372 if (route == _route) {
375 cleanup_processor_boxes();
377 _route.reset ((Route*) 0);
378 _processor.reset ((Processor*) 0);
384 RouteParams_UI::set_session (Session *sess)
386 ArdourDialog::set_session (sess);
388 route_display_model->clear();
391 boost::shared_ptr<RouteList> r = session->get_routes();
393 session->GoingAway.connect (mem_fun(*this, &ArdourDialog::session_gone));
394 session->RouteAdded.connect (mem_fun(*this, &RouteParams_UI::add_routes));
400 //route_select_list.thaw ();
402 _plugin_selector->set_session (session);
407 RouteParams_UI::session_gone ()
409 ENSURE_GUI_THREAD(mem_fun(*this, &RouteParams_UI::session_gone));
411 route_display_model->clear();
415 cleanup_processor_boxes();
416 cleanup_latency_frame ();
418 _route.reset ((Route*) 0);
419 _processor.reset ((Processor*) 0);
422 ArdourDialog::session_gone();
427 RouteParams_UI::route_selected()
429 Glib::RefPtr<TreeSelection> selection = route_display.get_selection();
430 TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
433 //If anything is selected
434 boost::shared_ptr<Route> route = (*iter)[route_display_columns.route] ;
436 if (_route == route) {
441 // remove event binding from previously selected
443 _route_conn.disconnect();
444 _route_ds_conn.disconnect();
445 cleanup_processor_boxes();
448 cleanup_latency_frame ();
451 // update the other panes with the correct info
453 //update_routeinfo (route);
456 setup_processor_boxes();
457 setup_latency_frame ();
459 // bind to redirects changed event for this route
460 _route_conn = route->processors_changed.connect (mem_fun(*this, &RouteParams_UI::processors_changed));
462 track_input_label.set_text (_route->name());
469 _route_conn.disconnect();
474 cleanup_processor_boxes();
475 cleanup_latency_frame ();
477 _route.reset ((Route*) 0);
478 _processor.reset ((Processor*) 0);
479 track_input_label.set_text(_("NO TRACK"));
486 RouteParams_UI::processors_changed ()
488 ENSURE_GUI_THREAD(mem_fun(*this, &RouteParams_UI::processors_changed));
491 _processor.reset ((Processor*) 0);
497 RouteParams_UI::show_track_menu()
499 using namespace Menu_Helpers;
501 if (track_menu == 0) {
502 track_menu = new Menu;
503 track_menu->set_name ("ArdourContextMenu");
504 track_menu->items().push_back
505 (MenuElem (_("Add Track/Bus"),
506 bind (mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::add_route), (Gtk::Window*) 0)));
508 track_menu->popup (1, gtk_get_current_event_time());
512 RouteParams_UI::redirect_selected (boost::shared_ptr<ARDOUR::Processor> insert)
514 boost::shared_ptr<Send> send;
515 boost::shared_ptr<Return> retrn;
516 boost::shared_ptr<PluginInsert> plugin_insert;
517 boost::shared_ptr<PortInsert> port_insert;
519 if ((send = boost::dynamic_pointer_cast<Send> (insert)) != 0) {
521 SendUI *send_ui = new SendUI (this, send, *session);
524 _plugin_conn = send->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away),
526 _active_view = send_ui;
528 redir_hpane.add2 (*_active_view);
529 redir_hpane.show_all();
531 } else if ((retrn = boost::dynamic_pointer_cast<Return> (insert)) != 0) {
533 ReturnUI *return_ui = new ReturnUI (this, retrn, *session);
536 _plugin_conn = retrn->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away),
538 _active_view = return_ui;
540 redir_hpane.add2 (*_active_view);
541 redir_hpane.show_all();
543 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (insert)) != 0) {
545 GenericPluginUI *plugin_ui = new GenericPluginUI (plugin_insert, true);
548 _plugin_conn = plugin_insert->plugin()->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::plugin_going_away),
550 plugin_ui->start_updating (0);
551 _active_view = plugin_ui;
552 redir_hpane.pack2 (*_active_view);
553 redir_hpane.show_all();
555 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (insert)) != 0) {
557 PortInsertUI *portinsert_ui = new PortInsertUI (this, *session, port_insert);
560 _plugin_conn = port_insert->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away),
562 _active_view = portinsert_ui;
563 redir_hpane.pack2 (*_active_view);
564 portinsert_ui->redisplay();
565 redir_hpane.show_all();
575 RouteParams_UI::plugin_going_away (Placement place)
577 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::plugin_going_away), place));
579 // delete the current view without calling finish
581 if (place == PreFader) {
582 cleanup_view (false);
583 _processor.reset ((Processor*) 0);
588 RouteParams_UI::redirect_going_away (boost::shared_ptr<ARDOUR::Processor> insert)
591 ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), insert));
593 printf ("redirect going away\n");
594 // delete the current view without calling finish
595 if (insert == _processor) {
596 cleanup_view (false);
597 _processor.reset ((Processor*) 0);
602 RouteParams_UI::update_title ()
604 WindowTitle title(Glib::get_application_name());
605 title += _("Track/Bus Inspector");
611 // if (_redirect && (_current_view == PLUGIN_CONFIG_VIEW || _current_view == SEND_CONFIG_VIEW)) {
612 // title += _redirect->name();
614 // else if (_current_view == INPUT_CONFIG_VIEW) {
615 // title += _("INPUT");
617 // else if (_current_view == OUTPUT_CONFIG_VIEW) {
618 // title += _("OUTPUT");
621 title_label.set_text(_route->name());
623 title += _route->name();
625 set_title(title.get_string());
628 title_label.set_text(_("No Route Selected"));
629 title += _("No Route Selected");
630 set_title(title.get_string());
635 RouteParams_UI::start_updating ()
637 update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect
638 (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) {