NO-OP: mark various state property names as explicitly non-translated
[ardour.git] / gtk2_ardour / route_params_ui.cc
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 <gtkmm/stock.h>
25
26 #include "ardour/audioengine.h"
27 #include "ardour/audio_track.h"
28 #include "ardour/plugin.h"
29 #include "ardour/plugin_insert.h"
30 #include "ardour/plugin_manager.h"
31 #include "ardour/port_insert.h"
32 #include "ardour/return.h"
33 #include "ardour/route.h"
34 #include "ardour/send.h"
35 #include "ardour/internal_send.h"
36
37 #include "gtkmm2ext/utils.h"
38 #include "gtkmm2ext/window_title.h"
39
40 #include "ardour_ui.h"
41 #include "gui_thread.h"
42 #include "io_selector.h"
43 #include "keyboard.h"
44 #include "mixer_strip.h"
45 #include "port_insert_ui.h"
46 #include "plugin_selector.h"
47 #include "plugin_ui.h"
48 #include "return_ui.h"
49 #include "route_params_ui.h"
50 #include "send_ui.h"
51 #include "timers.h"
52
53 #include "pbd/i18n.h"
54
55 using namespace ARDOUR;
56 using namespace PBD;
57 using namespace Gtk;
58 using namespace Gtkmm2ext;
59
60 RouteParams_UI::RouteParams_UI ()
61         : ArdourWindow (_("Tracks and Busses"))
62         , latency_apply_button (Stock::APPLY)
63         , track_menu(0)
64 {
65         insert_box = 0;
66         _input_iosel = 0;
67         _output_iosel = 0;
68         _active_view = 0;
69         latency_widget = 0;
70
71         using namespace Notebook_Helpers;
72
73         input_frame.set_shadow_type(Gtk::SHADOW_NONE);
74         output_frame.set_shadow_type(Gtk::SHADOW_NONE);
75         latency_frame.set_shadow_type (Gtk::SHADOW_NONE);
76
77         notebook.set_show_tabs (true);
78         notebook.set_show_border (true);
79         notebook.set_name ("RouteParamNotebook");
80
81         // create the tree model
82         route_display_model = ListStore::create(route_display_columns);
83
84         // setup the treeview
85         route_display.set_model(route_display_model);
86         route_display.append_column(_("Tracks/Busses"), route_display_columns.text);
87         route_display.set_name(X_("RouteParamsListDisplay"));
88         route_display.get_selection()->set_mode(Gtk::SELECTION_SINGLE); // default
89         route_display.set_reorderable(false);
90         route_display.set_size_request(75, -1);
91         route_display.set_headers_visible(true);
92         route_display.set_headers_clickable(true);
93
94         dynamic_cast<Gtk::CellRendererText*>(route_display.get_column_cell_renderer(0))->property_ellipsize() = Pango::ELLIPSIZE_START;
95
96         route_select_scroller.add(route_display);
97         route_select_scroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
98
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);
102
103         list_vpacker.pack_start (route_select_frame, true, true);
104
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")));
109
110         notebook.set_name ("InspectorNotebook");
111
112         title_label.set_name ("RouteParamsTitleLabel");
113         update_title();
114
115         latency_packer.set_spacing (18);
116         latency_button_box.pack_start (latency_apply_button);
117         delay_label.set_alignment (0, 0.5);
118
119         // changeable area
120         route_param_frame.set_name("RouteParamsBaseFrame");
121         route_param_frame.set_shadow_type (Gtk::SHADOW_IN);
122
123
124         route_hpacker.pack_start (notebook, true, true);
125
126         route_vpacker.pack_start (title_label, false, false);
127         route_vpacker.pack_start (route_hpacker, true, true);
128
129         list_hpane.add (list_vpacker);
130         list_hpane.add (route_vpacker);
131
132         add (list_hpane);
133
134         set_name ("RouteParamsWindow");
135         set_default_size (620,370);
136         set_wmclass (X_("ardour_route_parameters"), PROGRAM_NAME);
137
138         // events
139         route_display.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &RouteParams_UI::route_selected));
140         route_display.get_column(0)->signal_clicked().connect(sigc::mem_fun(*this, &RouteParams_UI::show_track_menu));
141
142         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
143
144         _plugin_selector = new PluginSelector (PluginManager::instance());
145         show_all();
146 }
147
148 RouteParams_UI::~RouteParams_UI ()
149 {
150 }
151
152 void
153 RouteParams_UI::add_routes (RouteList& routes)
154 {
155         ENSURE_GUI_THREAD (*this, &RouteParams_UI::add_routes, routes)
156
157         for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
158                 boost::shared_ptr<Route> route = (*x);
159
160                 if (route->is_auditioner()) {
161                         return;
162                 }
163
164                 TreeModel::Row row = *(route_display_model->append());
165                 row[route_display_columns.text] = route->name();
166                 row[route_display_columns.route] = route;
167
168                 //route_select_list.rows().back().select ();
169
170                 route->PropertyChanged.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_property_changed, this, _1, boost::weak_ptr<Route>(route)), gui_context());
171                 route->DropReferences.connect (*this, invalidator (*this), boost::bind (&RouteParams_UI::route_removed, this, boost::weak_ptr<Route>(route)), gui_context());
172         }
173 }
174
175
176 void
177 RouteParams_UI::route_property_changed (const PropertyChange& what_changed, boost::weak_ptr<Route> wr)
178 {
179         if (!what_changed.contains (ARDOUR::Properties::name)) {
180                 return;
181         }
182
183         boost::shared_ptr<Route> route (wr.lock());
184
185         if (!route) {
186                 return;
187         }
188
189         ENSURE_GUI_THREAD (*this, &RouteParams_UI::route_name_changed, wr)
190
191         bool found = false ;
192         TreeModel::Children rows = route_display_model->children();
193         for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
194                 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
195                 if (r == route) {
196                         (*iter)[route_display_columns.text] = route->name() ;
197                         found = true ;
198                         break;
199                 }
200         }
201
202         if(!found) {
203                 error << _("route display list item for renamed route not found!") << endmsg;
204         }
205
206         if (route == _route) {
207                 track_input_label.set_text (route->name());
208                 update_title();
209         }
210 }
211
212 void
213 RouteParams_UI::map_frozen()
214 {
215         ENSURE_GUI_THREAD (*this, &RouteParams_UI::map_frozen)
216         boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(_route);
217         if (at && insert_box) {
218                 switch (at->freeze_state()) {
219                         case AudioTrack::Frozen:
220                                 insert_box->set_sensitive (false);
221                                 //hide_redirect_editors (); // TODO hide editor windows
222                                 break;
223                         default:
224                                 insert_box->set_sensitive (true);
225                                 // XXX need some way, maybe, to retoggle redirect editors
226                                 break;
227                 }
228         }
229 }
230
231 void
232 RouteParams_UI::setup_processor_boxes()
233 {
234         if (_session && _route) {
235
236                 // just in case... shouldn't need this
237                 cleanup_processor_boxes();
238
239                 // construct new redirect boxes
240                 insert_box = new ProcessorBox (_session, boost::bind (&RouteParams_UI::plugin_selector, this), _p_selection, 0);
241                 insert_box->set_route (_route);
242
243                 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(_route);
244                 if (at) {
245                         at->FreezeChange.connect (route_connections, invalidator (*this), boost::bind (&RouteParams_UI::map_frozen, this), gui_context());
246                 }
247                 redir_hpane.add (*insert_box);
248
249                 insert_box->ProcessorSelected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected));  //note:  this indicates a double-click activation, not just a "selection"
250                 insert_box->ProcessorUnselected.connect (sigc::mem_fun(*this, &RouteParams_UI::redirect_selected));
251
252                 redir_hpane.show_all();
253         }
254 }
255
256 void
257 RouteParams_UI::cleanup_processor_boxes()
258 {
259         if (insert_box) {
260                 redir_hpane.remove(*insert_box);
261                 delete insert_box;
262                 insert_box = 0;
263         }
264 }
265
266 void
267 RouteParams_UI::refresh_latency ()
268 {
269         if (latency_widget) {
270                 latency_widget->refresh();
271
272                 char buf[128];
273                 snprintf (buf, sizeof (buf), _("Playback delay: %" PRId64 " samples"), _route->initial_delay());
274                 delay_label.set_text (buf);
275         }
276 }
277
278 void
279 RouteParams_UI::cleanup_latency_frame ()
280 {
281         if (latency_widget) {
282                 latency_frame.remove ();
283                 latency_packer.remove (*latency_widget);
284                 latency_packer.remove (latency_button_box);
285                 latency_packer.remove (delay_label);
286                 latency_connections.drop_connections ();
287                 latency_click_connection.disconnect ();
288
289                 delete latency_widget;
290                 latency_widget = 0;
291
292         }
293 }
294
295 void
296 RouteParams_UI::setup_latency_frame ()
297 {
298         latency_widget = new LatencyGUI (*(_route->output()), _session->frame_rate(), AudioEngine::instance()->samples_per_cycle());
299
300         char buf[128];
301         snprintf (buf, sizeof (buf), _("Playback delay: %" PRId64 " samples"), _route->initial_delay());
302         delay_label.set_text (buf);
303
304         latency_packer.pack_start (*latency_widget, false, false);
305         latency_packer.pack_start (latency_button_box, false, false);
306         latency_packer.pack_start (delay_label);
307
308         latency_click_connection = latency_apply_button.signal_clicked().connect (sigc::mem_fun (*latency_widget, &LatencyGUI::finish));
309         _route->signal_latency_changed.connect (latency_connections, invalidator (*this), boost::bind (&RouteParams_UI::refresh_latency, this), gui_context());
310         _route->initial_delay_changed.connect (latency_connections, invalidator (*this), boost::bind (&RouteParams_UI::refresh_latency, this), gui_context());
311
312         latency_frame.add (latency_packer);
313         latency_frame.show_all ();
314 }
315
316 void
317 RouteParams_UI::setup_io_frames()
318 {
319         cleanup_io_frames();
320
321         // input
322         _input_iosel = new IOSelector (this, _session, _route->input());
323         _input_iosel->setup ();
324         input_frame.add (*_input_iosel);
325         input_frame.show_all();
326
327         // output
328         _output_iosel = new IOSelector (this, _session, _route->output());
329         _output_iosel->setup ();
330         output_frame.add (*_output_iosel);
331         output_frame.show_all();
332 }
333
334 void
335 RouteParams_UI::cleanup_io_frames()
336 {
337         if (_input_iosel) {
338                 _input_iosel->Finished (IOSelector::Cancelled);
339                 input_frame.remove();
340                 delete _input_iosel;
341                 _input_iosel = 0;
342         }
343
344         if (_output_iosel) {
345                 _output_iosel->Finished (IOSelector::Cancelled);
346
347                 output_frame.remove();
348                 delete _output_iosel;
349                 _output_iosel = 0;
350         }
351 }
352
353 void
354 RouteParams_UI::cleanup_view (bool stopupdate)
355 {
356         if (_active_view) {
357                 GenericPluginUI *   plugui = 0;
358
359                 if (stopupdate && (plugui = dynamic_cast<GenericPluginUI*>(_active_view)) != 0) {
360                           plugui->stop_updating (0);
361                 }
362
363                 _processor_going_away_connection.disconnect ();
364                 redir_hpane.remove(*_active_view);
365                 delete _active_view;
366                 _active_view = 0;
367         }
368 }
369
370 void
371 RouteParams_UI::route_removed (boost::weak_ptr<Route> wr)
372 {
373         boost::shared_ptr<Route> route (wr.lock());
374
375         if (!route) {
376                 return;
377         }
378
379         ENSURE_GUI_THREAD (*this, invalidator (*this), &RouteParams_UI::route_removed, wr)
380
381         TreeModel::Children rows = route_display_model->children();
382         TreeModel::Children::iterator ri;
383
384         for(TreeModel::Children::iterator iter = rows.begin(); iter != rows.end(); ++iter) {
385                 boost::shared_ptr<Route> r =(*iter)[route_display_columns.route];
386
387                 if (r == route) {
388                         route_display_model->erase(iter);
389                         break;
390                 }
391         }
392
393         if (route == _route) {
394                 cleanup_io_frames();
395                 cleanup_view();
396                 cleanup_processor_boxes();
397
398                 _route.reset ((Route*) 0);
399                 _processor.reset ((Processor*) 0);
400                 update_title();
401         }
402 }
403
404 void
405 RouteParams_UI::set_session (Session *sess)
406 {
407         ArdourWindow::set_session (sess);
408
409         route_display_model->clear();
410         _plugin_selector->set_session (_session);
411
412         if (_session) {
413                 boost::shared_ptr<RouteList> r = _session->get_routes();
414                 add_routes (*r);
415                 _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&RouteParams_UI::add_routes, this, _1), gui_context());
416                 start_updating ();
417         } else {
418                 stop_updating ();
419         }
420 }
421
422
423 void
424 RouteParams_UI::session_going_away ()
425 {
426         ENSURE_GUI_THREAD (*this, &RouteParams_UI::session_going_away);
427
428         SessionHandlePtr::session_going_away ();
429
430         route_display_model->clear();
431
432         cleanup_io_frames();
433         cleanup_view();
434         cleanup_processor_boxes();
435         cleanup_latency_frame ();
436
437         _route.reset ((Route*) 0);
438         _processor.reset ((Processor*) 0);
439         update_title();
440 }
441
442 void
443 RouteParams_UI::route_selected()
444 {
445         Glib::RefPtr<TreeSelection> selection = route_display.get_selection();
446         TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
447
448         if(iter) {
449                 //If anything is selected
450                 boost::shared_ptr<Route> route = (*iter)[route_display_columns.route] ;
451
452                 if (_route == route) {
453                         // do nothing
454                         return;
455                 }
456
457                 // remove event binding from previously selected
458                 if (_route) {
459                         _route_processors_connection.disconnect ();
460                         cleanup_processor_boxes();
461                         cleanup_view();
462                         cleanup_io_frames();
463                         cleanup_latency_frame ();
464                 }
465
466                 // update the other panes with the correct info
467                 _route = route;
468                 //update_routeinfo (route);
469
470                 setup_io_frames();
471                 setup_processor_boxes();
472                 setup_latency_frame ();
473
474                 route->processors_changed.connect (_route_processors_connection, invalidator (*this), boost::bind (&RouteParams_UI::processors_changed, this, _1), gui_context());
475
476                 track_input_label.set_text (_route->name());
477
478                 update_title();
479
480         } else {
481                 // no selection
482                 if (_route) {
483                         _route_processors_connection.disconnect ();
484
485                         // remove from view
486                         cleanup_io_frames();
487                         cleanup_view();
488                         cleanup_processor_boxes();
489                         cleanup_latency_frame ();
490
491                         _route.reset ((Route*) 0);
492                         _processor.reset ((Processor*) 0);
493                         track_input_label.set_text(_("NO TRACK"));
494                         update_title();
495                 }
496         }
497 }
498
499 void
500 RouteParams_UI::processors_changed (RouteProcessorChange)
501 {
502         cleanup_view();
503
504         _processor.reset ((Processor*) 0);
505
506         //update_title();
507 }
508
509 void
510 RouteParams_UI::show_track_menu()
511 {
512         using namespace Menu_Helpers;
513
514         if (track_menu == 0) {
515                 track_menu = new Menu;
516                 track_menu->set_name ("ArdourContextMenu");
517                 track_menu->items().push_back (MenuElem (_("Add Track or Bus"), sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::add_route)));
518         }
519         track_menu->popup (1, gtk_get_current_event_time());
520 }
521
522 void
523 RouteParams_UI::redirect_selected (boost::shared_ptr<ARDOUR::Processor> proc)
524 {
525         boost::shared_ptr<Send> send;
526         boost::shared_ptr<Return> retrn;
527         boost::shared_ptr<PluginInsert> plugin_insert;
528         boost::shared_ptr<PortInsert> port_insert;
529
530         if ((boost::dynamic_pointer_cast<InternalSend> (proc)) != 0) {
531                 cleanup_view();
532                 _processor.reset ((Processor*) 0);
533                 update_title();
534                 return;
535         } else if ((send = boost::dynamic_pointer_cast<Send> (proc)) != 0) {
536
537                 SendUI *send_ui = new SendUI (this, send, _session);
538
539                 cleanup_view();
540                 send->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::processor_going_away, this, boost::weak_ptr<Processor>(proc)), gui_context());
541                 _active_view = send_ui;
542
543                 redir_hpane.add (*_active_view);
544                 redir_hpane.show_all();
545
546         } else if ((retrn = boost::dynamic_pointer_cast<Return> (proc)) != 0) {
547
548                 ReturnUI *return_ui = new ReturnUI (this, retrn, _session);
549
550                 cleanup_view();
551                 retrn->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::processor_going_away, this, boost::weak_ptr<Processor>(proc)), gui_context());
552                 _active_view = return_ui;
553
554                 redir_hpane.add (*_active_view);
555                 redir_hpane.show_all();
556
557         } else if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (proc)) != 0) {
558
559                 GenericPluginUI *plugin_ui = new GenericPluginUI (plugin_insert, true);
560
561                 cleanup_view();
562                 plugin_insert->plugin()->DropReferences.connect (_processor_going_away_connection, invalidator (*this), boost::bind (&RouteParams_UI::plugin_going_away, this, PreFader), gui_context());
563                 plugin_ui->start_updating (0);
564                 _active_view = plugin_ui;
565
566                 redir_hpane.add (*_active_view);
567                 redir_hpane.show_all();
568
569         } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (proc)) != 0) {
570
571                 PortInsertUI *portinsert_ui = new PortInsertUI (this, _session, port_insert);
572
573                 cleanup_view();
574                 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());
575                 _active_view = portinsert_ui;
576
577                 redir_hpane.add (*_active_view);
578                 portinsert_ui->redisplay();
579                 redir_hpane.show_all();
580         }
581
582         _processor = proc;
583         update_title();
584
585 }
586
587 void
588 RouteParams_UI::plugin_going_away (Placement place)
589 {
590         ENSURE_GUI_THREAD (*this, &RouteParams_UI::plugin_going_away, place)
591
592         // delete the current view without calling finish
593
594         if (place == PreFader) {
595                 cleanup_view (false);
596                 _processor.reset ((Processor*) 0);
597         }
598 }
599
600 void
601 RouteParams_UI::processor_going_away (boost::weak_ptr<ARDOUR::Processor> wproc)
602 {
603         boost::shared_ptr<Processor> proc = (wproc.lock());
604
605         if (!proc) {
606                 return;
607         }
608
609         ENSURE_GUI_THREAD (*this, &RouteParams_UI::processor_going_away, wproc)
610
611         printf ("redirect going away\n");
612         // delete the current view without calling finish
613         if (proc == _processor) {
614                 cleanup_view (false);
615                 _processor.reset ((Processor*) 0);
616         }
617 }
618
619 void
620 RouteParams_UI::update_title ()
621 {
622         WindowTitle title (_("Tracks and Busses"));
623
624         if (_route) {
625                 title_label.set_text(_route->name());
626                 title += _route->name();
627                 set_title(title.get_string());
628         } else {
629                 title_label.set_text(_("No Track or Bus Selected"));
630                 title += _("No Track or Bus Selected");
631                 set_title(title.get_string());
632         }
633 }
634
635 void
636 RouteParams_UI::start_updating ()
637 {
638         update_connection = Timers::rapid_connect
639                 (sigc::mem_fun(*this, &RouteParams_UI::update_views));
640 }
641
642 void
643 RouteParams_UI::stop_updating ()
644 {
645         update_connection.disconnect();
646 }
647
648 void
649 RouteParams_UI::update_views ()
650 {
651         SendUI *sui;
652         // TODO: only do it if correct tab is showing
653
654         if ((sui = dynamic_cast<SendUI*> (_active_view)) != 0) {
655                 sui->update ();
656         }
657 }