ardour
route_params_ui.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include <algorithm>
21 #include <inttypes.h>
22 
23 #include <glibmm/threads.h>
24 #include <gtkmm2ext/utils.h>
25 #include <gtkmm2ext/window_title.h>
26 
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"
37 
38 #include "ardour_ui.h"
39 #include "gui_thread.h"
40 #include "io_selector.h"
41 #include "keyboard.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"
48 #include "send_ui.h"
49 #include "timers.h"
50 
51 #include "i18n.h"
52 
53 using namespace ARDOUR;
54 using namespace PBD;
55 using namespace Gtk;
56 using namespace Gtkmm2ext;
57 
59  : ArdourWindow (_("Tracks and Busses")),
60  latency_apply_button (Stock::APPLY),
61  track_menu(0)
62 {
63  insert_box = 0;
64  _input_iosel = 0;
65  _output_iosel = 0;
66  _active_view = 0;
67  latency_widget = 0;
68 
69  using namespace Notebook_Helpers;
70 
71  input_frame.set_shadow_type(Gtk::SHADOW_NONE);
72  output_frame.set_shadow_type(Gtk::SHADOW_NONE);
73  latency_frame.set_shadow_type (Gtk::SHADOW_NONE);
74 
75  notebook.set_show_tabs (true);
76  notebook.set_show_border (true);
77  notebook.set_name ("RouteParamNotebook");
78 
79  // create the tree model
80  route_display_model = ListStore::create(route_display_columns);
81 
82  // setup the treeview
84  route_display.append_column(_("Tracks/Busses"), route_display_columns.text);
85  route_display.set_name(X_("RouteParamsListDisplay"));
86  route_display.get_selection()->set_mode(Gtk::SELECTION_SINGLE); // default
87  route_display.set_reorderable(false);
88  route_display.set_size_request(75, -1);
89  route_display.set_headers_visible(true);
90  route_display.set_headers_clickable(true);
91 
92  dynamic_cast<Gtk::CellRendererText*>(route_display.get_column_cell_renderer(0))->property_ellipsize() = Pango::ELLIPSIZE_START;
93 
95  route_select_scroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
96 
97  route_select_frame.set_name("RouteSelectBaseFrame");
98  route_select_frame.set_shadow_type (Gtk::SHADOW_IN);
100 
101  list_vpacker.pack_start (route_select_frame, true, true);
102 
103  notebook.pages().push_back (TabElem (input_frame, _("Inputs")));
104  notebook.pages().push_back (TabElem (output_frame, _("Outputs")));
105  notebook.pages().push_back (TabElem (redir_hpane, _("Plugins, Inserts & Sends")));
106  notebook.pages().push_back (TabElem (latency_frame, _("Latency")));
107 
108  notebook.set_name ("InspectorNotebook");
109 
110  title_label.set_name ("RouteParamsTitleLabel");
111  update_title();
112 
113  latency_packer.set_spacing (18);
115  delay_label.set_alignment (0, 0.5);
116 
117  // changeable area
118  route_param_frame.set_name("RouteParamsBaseFrame");
119  route_param_frame.set_shadow_type (Gtk::SHADOW_IN);
120 
121 
122  route_hpacker.pack_start (notebook, true, true);
123 
124  route_vpacker.pack_start (title_label, false, false);
125  route_vpacker.pack_start (route_hpacker, true, true);
126 
127 
128  list_hpane.pack1 (list_vpacker);
129  list_hpane.add2 (route_vpacker);
130 
131  list_hpane.set_position(110);
132 
133  redir_hpane.set_position(110);
134 
135  //global_vpacker.pack_start (list_hpane, true, true);
136  //get_vbox()->pack_start (global_vpacker);
137  add (list_hpane);
138 
139 
140  set_name ("RouteParamsWindow");
141  set_default_size (620,370);
142  set_wmclass (X_("ardour_route_parameters"), PROGRAM_NAME);
143 
144  // events
145  route_display.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &RouteParams_UI::route_selected));
146  route_display.get_column(0)->signal_clicked().connect(sigc::mem_fun(*this, &RouteParams_UI::show_track_menu));
147 
148  add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
149 
150  _plugin_selector = new PluginSelector (PluginManager::instance());
151  show_all();
152 }
153 
155 {
156 }
157 
158 void
160 {
162 
163  for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
164  boost::shared_ptr<Route> route = (*x);
165 
166  if (route->is_auditioner()) {
167  return;
168  }
169 
170  TreeModel::Row row = *(route_display_model->append());
171  row[route_display_columns.text] = route->name();
172  row[route_display_columns.route] = route;
173 
174  //route_select_list.rows().back().select ();
175 
176  route->PropertyChanged.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_property_changed, this, _1, boost::weak_ptr<Route>(route)), gui_context());
177  route->DropReferences.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_removed, this, boost::weak_ptr<Route>(route)), gui_context());
178  }
179 }
180 
181 
182 void
184 {
185  if (!what_changed.contains (ARDOUR::Properties::name)) {
186  return;
187  }
188 
189  boost::shared_ptr<Route> route (wr.lock());
190 
191  if (!route) {
192  return;
193  }
194 
195  ENSURE_GUI_THREAD (*this, &RouteParams_UI::route_name_changed, wr)
196 
197  bool found = false ;
198  TreeModel::Children rows = route_display_model->children();
199  for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
201  if (r == route) {
202  (*iter)[route_display_columns.text] = route->name() ;
203  found = true ;
204  break;
205  }
206  }
207 
208  if(!found) {
209  error << _("route display list item for renamed route not found!") << endmsg;
210  }
211 
212  if (route == _route) {
213  track_input_label.set_text (route->name());
214  update_title();
215  }
216 }
217 
218 void
220 {
223  if (at && insert_box) {
224  switch (at->freeze_state()) {
225  case AudioTrack::Frozen:
226  insert_box->set_sensitive (false);
227  //hide_redirect_editors (); // TODO hide editor windows
228  break;
229  default:
230  insert_box->set_sensitive (true);
231  // XXX need some way, maybe, to retoggle redirect editors
232  break;
233  }
234  }
235 }
236 
237 void
239 {
240  if (_session && _route) {
241 
242  // just in case... shouldn't need this
244 
245  // construct new redirect boxes
248 
250  if (at) {
251  at->FreezeChange.connect (route_connections, invalidator (*this), boost::bind (&RouteParams_UI::map_frozen, this), gui_context());
252  }
253  redir_hpane.pack1 (*insert_box);
254 
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));
257 
258  redir_hpane.show_all();
259  }
260 }
261 
262 void
264 {
265  if (insert_box) {
266  redir_hpane.remove(*insert_box);
267  delete insert_box;
268  insert_box = 0;
269  }
270 }
271 
272 void
274 {
275  if (latency_widget) {
277 
278  char buf[128];
279  snprintf (buf, sizeof (buf), _("Playback delay: %" PRId64 " samples"), _route->initial_delay());
280  delay_label.set_text (buf);
281  }
282 }
283 
284 void
286 {
287  if (latency_widget) {
288  latency_frame.remove ();
289  latency_packer.remove (*latency_widget);
291  latency_packer.remove (delay_label);
293  latency_click_connection.disconnect ();
294 
295  delete latency_widget;
296  latency_widget = 0;
297 
298  }
299 }
300 
301 void
303 {
304  latency_widget = new LatencyGUI (*(_route->output()), _session->frame_rate(), AudioEngine::instance()->samples_per_cycle());
305 
306  char buf[128];
307  snprintf (buf, sizeof (buf), _("Playback delay: %" PRId64 " samples"), _route->initial_delay());
308  delay_label.set_text (buf);
309 
310  latency_packer.pack_start (*latency_widget, false, false);
311  latency_packer.pack_start (latency_button_box, false, false);
312  latency_packer.pack_start (delay_label);
313 
314  latency_click_connection = latency_apply_button.signal_clicked().connect (sigc::mem_fun (*latency_widget, &LatencyGUI::finish));
317 
319  latency_frame.show_all ();
320 }
321 
322 void
324 {
326 
327  // input
328  _input_iosel = new IOSelector (this, _session, _route->input());
329  _input_iosel->setup ();
330  input_frame.add (*_input_iosel);
331  input_frame.show_all();
332 
333  // output
334  _output_iosel = new IOSelector (this, _session, _route->output());
335  _output_iosel->setup ();
337  output_frame.show_all();
338 }
339 
340 void
342 {
343  if (_input_iosel) {
345  input_frame.remove();
346  delete _input_iosel;
347  _input_iosel = 0;
348  }
349 
350  if (_output_iosel) {
352 
353  output_frame.remove();
354  delete _output_iosel;
355  _output_iosel = 0;
356  }
357 }
358 
359 void
361 {
362  if (_active_view) {
363  GenericPluginUI * plugui = 0;
364 
365  if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_view)) != 0) {
366  plugui->stop_updating (0);
367  }
368 
370  redir_hpane.remove(*_active_view);
371  delete _active_view;
372  _active_view = 0;
373  }
374 }
375 
376 void
378 {
379  boost::shared_ptr<Route> route (wr.lock());
380 
381  if (!route) {
382  return;
383  }
384 
386 
387  TreeModel::Children rows = route_display_model->children();
388  TreeModel::Children::iterator ri;
389 
390  for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
392 
393  if (r == route) {
394  route_display_model->erase(iter);
395  break;
396  }
397  }
398 
399  if (route == _route) {
401  cleanup_view();
403 
404  _route.reset ((Route*) 0);
405  _processor.reset ((Processor*) 0);
406  update_title();
407  }
408 }
409 
410 void
412 {
414 
415  route_display_model->clear();
417 
418  if (_session) {
420  add_routes (*r);
421  _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&RouteParams_UI::add_routes, this, _1), gui_context());
422  start_updating ();
423  } else {
424  stop_updating ();
425  }
426 }
427 
428 
429 void
431 {
433 
434  SessionHandlePtr::session_going_away ();
435 
436  route_display_model->clear();
437 
439  cleanup_view();
442 
443  _route.reset ((Route*) 0);
444  _processor.reset ((Processor*) 0);
445  update_title();
446 }
447 
448 void
450 {
451  Glib::RefPtr<TreeSelection> selection = route_display.get_selection();
452  TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
453 
454  if(iter) {
455  //If anything is selected
457 
458  if (_route == route) {
459  // do nothing
460  return;
461  }
462 
463  // remove event binding from previously selected
464  if (_route) {
467  cleanup_view();
470  }
471 
472  // update the other panes with the correct info
473  _route = route;
474  //update_routeinfo (route);
475 
476  setup_io_frames();
479 
481 
482  track_input_label.set_text (_route->name());
483 
484  update_title();
485 
486  } else {
487  // no selection
488  if (_route) {
490 
491  // remove from view
493  cleanup_view();
496 
497  _route.reset ((Route*) 0);
498  _processor.reset ((Processor*) 0);
499  track_input_label.set_text(_("NO TRACK"));
500  update_title();
501  }
502  }
503 }
504 
505 void
507 {
508  cleanup_view();
509 
510  _processor.reset ((Processor*) 0);
511 
512  //update_title();
513 }
514 
515 void
517 {
518  using namespace Menu_Helpers;
519 
520  if (track_menu == 0) {
521  track_menu = new Menu;
522  track_menu->set_name ("ArdourContextMenu");
523  track_menu->items().push_back
524  (MenuElem (_("Add Track or Bus"),
525  sigc::bind (sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::add_route), (Gtk::Window*) 0)));
526  }
527  track_menu->popup (1, gtk_get_current_event_time());
528 }
529 
530 void
532 {
535  boost::shared_ptr<PluginInsert> plugin_insert;
536  boost::shared_ptr<PortInsert> port_insert;
537 
538  if ((boost::dynamic_pointer_cast<InternalSend> (proc)) != 0) {
539  cleanup_view();
540  _processor.reset ((Processor*) 0);
541  update_title();
542  return;
543  } else if ((send = boost::dynamic_pointer_cast<Send> (proc)) != 0) {
544 
545  SendUI *send_ui = new SendUI (this, send, _session);
546 
547  cleanup_view();
549  _active_view = send_ui;
550 
551  redir_hpane.add2 (*_active_view);
552  redir_hpane.show_all();
553 
554  } else if ((retrn = boost::dynamic_pointer_cast<Return> (proc)) != 0) {
555 
556  ReturnUI *return_ui = new ReturnUI (this, retrn, _session);
557 
558  cleanup_view();
560  _active_view = return_ui;
561 
562  redir_hpane.add2 (*_active_view);
563  redir_hpane.show_all();
564 
565  } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (proc)) != 0) {
566 
567  GenericPluginUI *plugin_ui = new GenericPluginUI (plugin_insert, true);
568 
569  cleanup_view();
570  plugin_insert->plugin()->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::plugin_going_away, this, PreFader), gui_context());
571  plugin_ui->start_updating (0);
572  _active_view = plugin_ui;
573 
574  redir_hpane.pack2 (*_active_view);
575  redir_hpane.show_all();
576 
577  } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (proc)) != 0) {
578 
579  PortInsertUI *portinsert_ui = new PortInsertUI (this, _session, port_insert);
580 
581  cleanup_view();
583  _active_view = portinsert_ui;
584 
585  redir_hpane.pack2 (*_active_view);
586  portinsert_ui->redisplay();
587  redir_hpane.show_all();
588  }
589 
590  _processor = proc;
591  update_title();
592 
593 }
594 
595 void
597 {
599 
600  // delete the current view without calling finish
601 
602  if (place == PreFader) {
603  cleanup_view (false);
604  _processor.reset ((Processor*) 0);
605  }
606 }
607 
608 void
610 {
611  boost::shared_ptr<Processor> proc = (wproc.lock());
612 
613  if (!proc) {
614  return;
615  }
616 
618 
619  printf ("redirect going away\n");
620  // delete the current view without calling finish
621  if (proc == _processor) {
622  cleanup_view (false);
623  _processor.reset ((Processor*) 0);
624  }
625 }
626 
627 void
629 {
630  WindowTitle title (_("Tracks and Busses"));
631 
632  if (_route) {
633  title_label.set_text(_route->name());
634  title += _route->name();
635  set_title(title.get_string());
636  } else {
637  title_label.set_text(_("No Track or Bus Selected"));
638  title += _("No Track or Bus Selected");
639  set_title(title.get_string());
640  }
641 }
642 
643 void
645 {
647  (sigc::mem_fun(*this, &RouteParams_UI::update_views));
648 }
649 
650 void
652 {
653  update_connection.disconnect();
654 }
655 
656 void
658 {
659  SendUI *sui;
660  // TODO: only do it if correct tab is showing
661 
662  if ((sui = dynamic_cast<SendUI*> (_active_view)) != 0) {
663  sui->update ();
664  }
665 }
PBD::Signal0< void > initial_delay_changed
Definition: route.h:317
Gtk::VBox latency_packer
Gtk::VBox route_vpacker
void setup()
Definition: port_matrix.cc:210
PBD::ScopedConnectionList latency_connections
void cleanup_processor_boxes()
void cleanup_view(bool stopupdate=true)
PBD::Signal0< void > DropReferences
Definition: destructible.h:34
bool stop_updating(GdkEventAny *)
void route_property_changed(const PBD::PropertyChange &, boost::weak_ptr< ARDOUR::Route > route)
PBD::ScopedConnectionList route_connections
PBD::Signal1< void, const PropertyChange & > PropertyChanged
Definition: stateful.h:87
LatencyGUI * latency_widget
Gtk::HPaned redir_hpane
Gtk::ScrolledWindow route_select_scroller
PBD::Signal0< void > FreezeChange
Definition: track.h:164
PluginSelector * _plugin_selector
Definition: ardour_ui.h:130
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr.hpp:396
static ARDOUR_UI * instance()
Definition: ardour_ui.h:187
LIBARDOUR_API PBD::PropertyDescriptor< std::string > name
Gtk::TreeView route_display
void setup_latency_frame()
LIBPBD_API Transmitter error
Gtk::Frame latency_frame
RouteDisplayModelColumns route_display_columns
bool is_auditioner() const
Definition: route.h:110
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
Definition: send_ui.h:34
boost::shared_ptr< Plugin > plugin(uint32_t num=0) const
void redirect_selected(boost::shared_ptr< ARDOUR::Processor >)
void set_route(boost::shared_ptr< ARDOUR::Route >)
framecnt_t frame_rate() const
Definition: session.h:365
#define ENSURE_GUI_THREAD(obj, method,...)
Definition: gui_thread.h:34
#define invalidator(x)
Definition: gui_thread.h:40
boost::shared_ptr< ARDOUR::Route > _route
PBD::ScopedConnection _processor_going_away_connection
Gtk::HPaned list_hpane
const std::string & get_string()
Definition: window_title.h:53
sigc::signal< void, boost::shared_ptr< ARDOUR::Processor > > ProcessorSelected
#define _(Text)
Definition: i18n.h:11
void route_removed(boost::weak_ptr< ARDOUR::Route > route)
Glib::RefPtr< Gtk::ListStore > route_display_model
PluginSelector * plugin_selector()
Gtk::Button latency_apply_button
Gtk::Notebook notebook
Gtk::Frame input_frame
Gtk::Label title_label
#define X_(Text)
Definition: i18n.h:13
static char * place
Definition: getopt_long.c:126
RouteProcessorSelection _rr_selection
Gtk::Frame route_param_frame
void set_session(ARDOUR::Session *)
void cleanup_latency_frame()
sigc::connection update_connection
Definition: amp.h:29
IOSelector * _input_iosel
void update()
Definition: send_ui.cc:117
#define gui_context()
Definition: gui_thread.h:36
Gtk::Container * _active_view
boost::shared_ptr< RouteList > get_routes() const
Definition: session.h:229
framecnt_t initial_delay() const
Definition: route.h:282
Gtk::TreeModelColumn< boost::shared_ptr< ARDOUR::Route > > route
PBD::ScopedConnectionList _session_connections
void finish()
Definition: latency_gui.cc:114
Gtk::Menu * track_menu
Gtk::Label track_input_label
void plugin_going_away(ARDOUR::Placement)
PBD::Signal1< void, RouteProcessorChange > processors_changed
Definition: route.h:312
ProcessorBox * insert_box
void processor_going_away(boost::weak_ptr< ARDOUR::Processor >)
Gtk::Label delay_label
std::string name() const
Gtk::HBox route_hpacker
IOSelector * _output_iosel
sigc::signal< void, Result > Finished
Definition: port_matrix.h:164
Definition: debug.h:30
boost::shared_ptr< IO > input() const
Definition: route.h:89
void processors_changed(ARDOUR::RouteProcessorChange)
void setup_processor_boxes()
FreezeState freeze_state() const
Definition: track.cc:175
bool contains(PropertyDescriptor< T > p) const
virtual void set_session(ARDOUR::Session *)
boost::shared_ptr< IO > output() const
Definition: route.h:90
void refresh()
Definition: latency_gui.cc:130
boost::shared_ptr< ARDOUR::Processor > _processor
PBD::ScopedConnection _route_processors_connection
Gtk::TreeModelColumn< std::string > text
void add_routes(ARDOUR::RouteList &)
Gtk::HButtonBox latency_button_box
bool start_updating(GdkEventAny *)
sigc::connection rapid_connect(const sigc::slot< void > &slot)
Definition: timers.cc:183
std::list< boost::shared_ptr< Route > > RouteList
Definition: types.h:532
sigc::signal< void, boost::shared_ptr< ARDOUR::Processor > > ProcessorUnselected
Placement
Definition: types.h:375
void add_route(Gtk::Window *float_window)
Definition: ardour_ui.cc:3660
Gtk::Frame route_select_frame
ARDOUR::Session * _session
sigc::connection latency_click_connection
Gtk::VBox list_vpacker
Gtk::Frame output_frame
PBD::Signal1< void, RouteList & > RouteAdded
Definition: session.h:317
PBD::Signal0< void > signal_latency_changed
Definition: route.h:316