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.
23 #include <glibmm/threads.h>
24 #include <gtkmm2ext/utils.h>
25 #include <gtkmm2ext/window_title.h>
27 #include "ardour/audioengine.h"
28 #include "ardour/audio_track.h"
29 #include "ardour/plugin.h"
30 #include "ardour/plugin_insert.h"
31 #include "ardour/plugin_manager.h"
32 #include "ardour/port_insert.h"
33 #include "ardour/return.h"
34 #include "ardour/route.h"
35 #include "ardour/send.h"
36 #include "ardour/internal_send.h"
38 #include "ardour_ui.h"
39 #include "gui_thread.h"
40 #include "io_selector.h"
42 #include "mixer_strip.h"
43 #include "port_insert_ui.h"
44 #include "plugin_selector.h"
45 #include "plugin_ui.h"
46 #include "return_ui.h"
47 #include "route_params_ui.h"
52 using namespace ARDOUR;
55 using namespace Gtkmm2ext;
57 RouteParams_UI::RouteParams_UI ()
58 : ArdourWindow (_("Tracks and Busses")),
59 latency_apply_button (Stock::APPLY),
68 using namespace Notebook_Helpers;
70 input_frame.set_shadow_type(Gtk::SHADOW_NONE);
71 output_frame.set_shadow_type(Gtk::SHADOW_NONE);
72 latency_frame.set_shadow_type (Gtk::SHADOW_NONE);
74 notebook.set_show_tabs (true);
75 notebook.set_show_border (true);
76 notebook.set_name ("RouteParamNotebook");
78 // create the tree model
79 route_display_model = ListStore::create(route_display_columns);
82 route_display.set_model(route_display_model);
83 route_display.append_column(_("Tracks/Busses"), route_display_columns.text);
84 route_display.set_name(X_("RouteParamsListDisplay"));
85 route_display.get_selection()->set_mode(Gtk::SELECTION_SINGLE); // default
86 route_display.set_reorderable(false);
87 route_display.set_size_request(75, -1);
88 route_display.set_headers_visible(true);
89 route_display.set_headers_clickable(true);
91 dynamic_cast<Gtk::CellRendererText*>(route_display.get_column_cell_renderer(0))->property_ellipsize() = Pango::ELLIPSIZE_START;
93 route_select_scroller.add(route_display);
94 route_select_scroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
96 route_select_frame.set_name("RouteSelectBaseFrame");
97 route_select_frame.set_shadow_type (Gtk::SHADOW_IN);
98 route_select_frame.add(route_select_scroller);
100 list_vpacker.pack_start (route_select_frame, true, true);
102 notebook.pages().push_back (TabElem (input_frame, _("Inputs")));
103 notebook.pages().push_back (TabElem (output_frame, _("Outputs")));
104 notebook.pages().push_back (TabElem (redir_hpane, _("Plugins, Inserts & Sends")));
105 notebook.pages().push_back (TabElem (latency_frame, _("Latency")));
107 notebook.set_name ("InspectorNotebook");
109 title_label.set_name ("RouteParamsTitleLabel");
112 latency_packer.set_spacing (18);
113 latency_button_box.pack_start (latency_apply_button);
114 delay_label.set_alignment (0, 0.5);
117 route_param_frame.set_name("RouteParamsBaseFrame");
118 route_param_frame.set_shadow_type (Gtk::SHADOW_IN);
121 route_hpacker.pack_start (notebook, true, true);
123 route_vpacker.pack_start (title_label, false, false);
124 route_vpacker.pack_start (route_hpacker, true, true);
127 list_hpane.pack1 (list_vpacker);
128 list_hpane.add2 (route_vpacker);
130 list_hpane.set_position(110);
132 redir_hpane.set_position(110);
134 //global_vpacker.pack_start (list_hpane, true, true);
135 //get_vbox()->pack_start (global_vpacker);
139 set_name ("RouteParamsWindow");
140 set_default_size (620,370);
141 set_wmclass (X_("ardour_route_parameters"), PROGRAM_NAME);
144 route_display.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &RouteParams_UI::route_selected));
145 route_display.get_column(0)->signal_clicked().connect(sigc::mem_fun(*this, &RouteParams_UI::show_track_menu));
147 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
149 _plugin_selector = new PluginSelector (PluginManager::instance());
153 RouteParams_UI::~RouteParams_UI ()
158 RouteParams_UI::add_routes (RouteList& routes)
160 ENSURE_GUI_THREAD (*this, &RouteParams_UI::add_routes, routes)
162 for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
163 boost::shared_ptr<Route> route = (*x);
165 if (route->is_auditioner()) {
169 TreeModel::Row row = *(route_display_model->append());
170 row[route_display_columns.text] = route->name();
171 row[route_display_columns.route] = route;
173 //route_select_list.rows().back().select ();
175 route->PropertyChanged.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_property_changed, this, _1, boost::weak_ptr<Route>(route)), gui_context());
176 route->DropReferences.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_removed, this, boost::weak_ptr<Route>(route)), gui_context());
182 RouteParams_UI::route_property_changed (const PropertyChange& what_changed, boost::weak_ptr<Route> wr)
184 if (!what_changed.contains (ARDOUR::Properties::name)) {
188 boost::shared_ptr<Route> route (wr.lock());
194 ENSURE_GUI_THREAD (*this, &RouteParams_UI::route_name_changed, wr)
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::map_frozen()
220 ENSURE_GUI_THREAD (*this, &RouteParams_UI::map_frozen)
221 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(_route);
222 if (at && insert_box) {
223 switch (at->freeze_state()) {
224 case AudioTrack::Frozen:
225 insert_box->set_sensitive (false);
226 //hide_redirect_editors (); // TODO hide editor windows
229 insert_box->set_sensitive (true);
230 // XXX need some way, maybe, to retoggle redirect editors
237 RouteParams_UI::setup_processor_boxes()
239 if (_session && _route) {
241 // just in case... shouldn't need this
242 cleanup_processor_boxes();
244 // construct new redirect boxes
245 insert_box = new ProcessorBox (_session, boost::bind (&RouteParams_UI::plugin_selector, this), _rr_selection, 0);
246 insert_box->set_route (_route);
248 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(_route);
250 at->FreezeChange.connect (route_connections, invalidator (*this), boost::bind (&RouteParams_UI::map_frozen, this), gui_context());
252 redir_hpane.pack1 (*insert_box);
254 insert_box->ProcessorSelected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected)); //note: this indicates a double-click activation, not just a "selection"
255 insert_box->ProcessorUnselected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected));
257 redir_hpane.show_all();
262 RouteParams_UI::cleanup_processor_boxes()
265 redir_hpane.remove(*insert_box);
272 RouteParams_UI::refresh_latency ()
274 if (latency_widget) {
275 latency_widget->refresh();
278 snprintf (buf, sizeof (buf), _("Playback delay: %" PRId64 " samples"), _route->initial_delay());
279 delay_label.set_text (buf);
284 RouteParams_UI::cleanup_latency_frame ()
286 if (latency_widget) {
287 latency_frame.remove ();
288 latency_packer.remove (*latency_widget);
289 latency_packer.remove (latency_button_box);
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->frame_rate(), AudioEngine::instance()->samples_per_cycle());
306 snprintf (buf, sizeof (buf), _("Playback delay: %" PRId64 " samples"), _route->initial_delay());
307 delay_label.set_text (buf);
309 latency_packer.pack_start (*latency_widget, false, false);
310 latency_packer.pack_start (latency_button_box, false, false);
311 latency_packer.pack_start (delay_label);
313 latency_click_connection = latency_apply_button.signal_clicked().connect (sigc::mem_fun (*latency_widget, &LatencyGUI::finish));
314 _route->signal_latency_changed.connect (latency_connections, invalidator (*this), boost::bind (&RouteParams_UI::refresh_latency, this), gui_context());
315 _route->initial_delay_changed.connect (latency_connections, invalidator (*this), boost::bind (&RouteParams_UI::refresh_latency, this), gui_context());
317 latency_frame.add (latency_packer);
318 latency_frame.show_all ();
322 RouteParams_UI::setup_io_frames()
327 _input_iosel = new IOSelector (this, _session, _route->input());
328 _input_iosel->setup ();
329 input_frame.add (*_input_iosel);
330 input_frame.show_all();
333 _output_iosel = new IOSelector (this, _session, _route->output());
334 _output_iosel->setup ();
335 output_frame.add (*_output_iosel);
336 output_frame.show_all();
340 RouteParams_UI::cleanup_io_frames()
343 _input_iosel->Finished (IOSelector::Cancelled);
344 input_frame.remove();
350 _output_iosel->Finished (IOSelector::Cancelled);
352 output_frame.remove();
353 delete _output_iosel;
359 RouteParams_UI::cleanup_view (bool stopupdate)
362 GenericPluginUI * plugui = 0;
364 if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_view)) != 0) {
365 plugui->stop_updating (0);
368 _processor_going_away_connection.disconnect ();
369 redir_hpane.remove(*_active_view);
376 RouteParams_UI::route_removed (boost::weak_ptr<Route> wr)
378 boost::shared_ptr<Route> route (wr.lock());
384 ENSURE_GUI_THREAD (*this, invalidator (*this), &RouteParams_UI::route_removed, wr)
386 TreeModel::Children rows = route_display_model->children();
387 TreeModel::Children::iterator ri;
389 for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
390 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
393 route_display_model->erase(iter);
398 if (route == _route) {
401 cleanup_processor_boxes();
403 _route.reset ((Route*) 0);
404 _processor.reset ((Processor*) 0);
410 RouteParams_UI::set_session (Session *sess)
412 ArdourWindow::set_session (sess);
414 route_display_model->clear();
415 _plugin_selector->set_session (_session);
418 boost::shared_ptr<RouteList> r = _session->get_routes();
420 _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&RouteParams_UI::add_routes, this, _1), gui_context());
429 RouteParams_UI::session_going_away ()
431 ENSURE_GUI_THREAD (*this, &RouteParams_UI::session_going_away);
433 SessionHandlePtr::session_going_away ();
435 route_display_model->clear();
439 cleanup_processor_boxes();
440 cleanup_latency_frame ();
442 _route.reset ((Route*) 0);
443 _processor.reset ((Processor*) 0);
448 RouteParams_UI::route_selected()
450 Glib::RefPtr<TreeSelection> selection = route_display.get_selection();
451 TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
454 //If anything is selected
455 boost::shared_ptr<Route> route = (*iter)[route_display_columns.route] ;
457 if (_route == route) {
462 // remove event binding from previously selected
464 _route_processors_connection.disconnect ();
465 cleanup_processor_boxes();
468 cleanup_latency_frame ();
471 // update the other panes with the correct info
473 //update_routeinfo (route);
476 setup_processor_boxes();
477 setup_latency_frame ();
479 route->processors_changed.connect (_route_processors_connection, invalidator (*this), boost::bind (&RouteParams_UI::processors_changed, this, _1), gui_context());
481 track_input_label.set_text (_route->name());
488 _route_processors_connection.disconnect ();
493 cleanup_processor_boxes();
494 cleanup_latency_frame ();
496 _route.reset ((Route*) 0);
497 _processor.reset ((Processor*) 0);
498 track_input_label.set_text(_("NO TRACK"));
505 RouteParams_UI::processors_changed (RouteProcessorChange)
509 _processor.reset ((Processor*) 0);
515 RouteParams_UI::show_track_menu()
517 using namespace Menu_Helpers;
519 if (track_menu == 0) {
520 track_menu = new Menu;
521 track_menu->set_name ("ArdourContextMenu");
522 track_menu->items().push_back
523 (MenuElem (_("Add Track or Bus"),
524 sigc::bind (sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::add_route), (Gtk::Window*) 0)));
526 track_menu->popup (1, gtk_get_current_event_time());
530 RouteParams_UI::redirect_selected (boost::shared_ptr<ARDOUR::Processor> proc)
532 boost::shared_ptr<Send> send;
533 boost::shared_ptr<Return> retrn;
534 boost::shared_ptr<PluginInsert> plugin_insert;
535 boost::shared_ptr<PortInsert> port_insert;
537 if ((boost::dynamic_pointer_cast<InternalSend> (proc)) != 0) {
539 _processor.reset ((Processor*) 0);
542 } else if ((send = boost::dynamic_pointer_cast<Send> (proc)) != 0) {
544 SendUI *send_ui = new SendUI (this, send, _session);
547 send->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::processor_going_away, this, boost::weak_ptr<Processor>(proc)), gui_context());
548 _active_view = send_ui;
550 redir_hpane.add2 (*_active_view);
551 redir_hpane.show_all();
553 } else if ((retrn = boost::dynamic_pointer_cast<Return> (proc)) != 0) {
555 ReturnUI *return_ui = new ReturnUI (this, retrn, _session);
558 retrn->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::processor_going_away, this, boost::weak_ptr<Processor>(proc)), gui_context());
559 _active_view = return_ui;
561 redir_hpane.add2 (*_active_view);
562 redir_hpane.show_all();
564 } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (proc)) != 0) {
566 GenericPluginUI *plugin_ui = new GenericPluginUI (plugin_insert, true);
569 plugin_insert->plugin()->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::plugin_going_away, this, PreFader), gui_context());
570 plugin_ui->start_updating (0);
571 _active_view = plugin_ui;
573 redir_hpane.pack2 (*_active_view);
574 redir_hpane.show_all();
576 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (proc)) != 0) {
578 PortInsertUI *portinsert_ui = new PortInsertUI (this, _session, port_insert);
581 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());
582 _active_view = portinsert_ui;
584 redir_hpane.pack2 (*_active_view);
585 portinsert_ui->redisplay();
586 redir_hpane.show_all();
595 RouteParams_UI::plugin_going_away (Placement place)
597 ENSURE_GUI_THREAD (*this, &RouteParams_UI::plugin_going_away, place)
599 // delete the current view without calling finish
601 if (place == PreFader) {
602 cleanup_view (false);
603 _processor.reset ((Processor*) 0);
608 RouteParams_UI::processor_going_away (boost::weak_ptr<ARDOUR::Processor> wproc)
610 boost::shared_ptr<Processor> proc = (wproc.lock());
616 ENSURE_GUI_THREAD (*this, &RouteParams_UI::processor_going_away, wproc)
618 printf ("redirect going away\n");
619 // delete the current view without calling finish
620 if (proc == _processor) {
621 cleanup_view (false);
622 _processor.reset ((Processor*) 0);
627 RouteParams_UI::update_title ()
629 WindowTitle title (_("Tracks and Busses"));
632 title_label.set_text(_route->name());
633 title += _route->name();
634 set_title(title.get_string());
636 title_label.set_text(_("No Track or Bus Selected"));
637 title += _("No Track or Bus Selected");
638 set_title(title.get_string());
643 RouteParams_UI::start_updating ()
645 update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect
646 (sigc::mem_fun(*this, &RouteParams_UI::update_views));
650 RouteParams_UI::stop_updating ()
652 update_connection.disconnect();
656 RouteParams_UI::update_views ()
659 // TODO: only do it if correct tab is showing
661 if ((sui = dynamic_cast<SendUI*> (_active_view)) != 0) {