Reenable the correct sort column and type when redisplaying regions
[ardour.git] / gtk2_ardour / ardour_ui2.cc
1 /*
2  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3  * Copyright (C) 2005-2015 Tim Mayberry <mojofunk@gmail.com>
4  * Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2006-2007 Doug McLain <doug@nostar.net>
6  * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
7  * Copyright (C) 2006 Karsten Wiese <fzuuzf@googlemail.com>
8  * Copyright (C) 2006 Nick Mainsbridge <mainsbridge@gmail.com>
9  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
10  * Copyright (C) 2008 Hans Baier <hansfbaier@googlemail.com>
11  * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
12  * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  */
28
29 #ifdef WAF_BUILD
30 #include "gtk2ardour-config.h"
31 #endif
32
33 #include <fcntl.h>
34 #include <signal.h>
35 #include <unistd.h>
36 #include <cerrno>
37 #include <iostream>
38 #include <cmath>
39
40 #include <sigc++/bind.h>
41 #include <gtkmm/settings.h>
42
43 #include "canvas/canvas.h"
44
45 #include "pbd/error.h"
46 #include "pbd/basename.h"
47 #include "pbd/fastlog.h"
48
49 #include "gtkmm2ext/utils.h"
50 #include "gtkmm2ext/window_title.h"
51
52 #include "ardour/profile.h"
53 #include "ardour/session.h"
54 #include "ardour/types.h"
55
56 #include "ardour_ui.h"
57 #include "keyboard.h"
58 #include "public_editor.h"
59 #include "audio_clock.h"
60 #include "actions.h"
61 #include "main_clock.h"
62 #include "mixer_ui.h"
63 #include "utils.h"
64 #include "time_info_box.h"
65 #include "midi_tracer.h"
66 #include "global_port_matrix.h"
67 #include "location_ui.h"
68 #include "rc_option_editor.h"
69
70 #include "pbd/i18n.h"
71
72 using namespace std;
73 using namespace ARDOUR;
74 using namespace PBD;
75 using namespace Gtkmm2ext;
76 using namespace ArdourWidgets;
77 using namespace Gtk;
78 using namespace Glib;
79 using namespace ARDOUR_UI_UTILS;
80
81 void
82 ARDOUR_UI::setup_tooltips ()
83 {
84         ArdourCanvas::Canvas::set_tooltip_timeout (Gtk::Settings::get_default()->property_gtk_tooltip_timeout ());
85
86         set_tip (auto_return_button, _("Return to last playback start when stopped"));
87         set_tip (follow_edits_button, _("Playhead follows Range tool clicks, and Range selections"));
88         set_tip (auto_input_button, _("Track Input Monitoring automatically follows transport state"));
89         parameter_changed("click-gain");
90         set_tip (solo_alert_button, _("When active, something is soloed.\nClick to de-solo everything"));
91         set_tip (auditioning_alert_button, _("When active, auditioning is taking place.\nClick to stop the audition"));
92         set_tip (feedback_alert_button, _("When active, there is a feedback loop."));
93         set_tip (primary_clock, _("<b>Primary Clock</b> right-click to set display mode. Click to edit, click+drag a digit or mouse-over+scroll wheel to modify.\nText edits: right-to-left overwrite <tt>Esc</tt>: cancel; <tt>Enter</tt>: confirm; postfix the edit with '+' or '-' to enter delta times.\n"));
94         set_tip (secondary_clock, _("<b>Secondary Clock</b> right-click to set display mode. Click to edit, click+drag a digit or mouse-over+scroll wheel to modify.\nText edits: right-to-left overwrite <tt>Esc</tt>: cancel; <tt>Enter</tt>: confirm; postfix the edit with '+' or '-' to enter delta times.\n"));
95         set_tip (editor_meter_peak_display, _("Reset All Peak Meters"));
96         set_tip (error_alert_button, _("Show Error Log and acknowledge warnings"));
97
98         set_tip (latency_disable_button, _("Disable all latency compensation. This will result in playback and monitoring to not be out of sync."));
99
100         synchronize_sync_source_and_video_pullup ();
101
102         editor->setup_tooltips ();
103 }
104
105 bool
106 ARDOUR_UI::status_bar_button_press (GdkEventButton* ev)
107 {
108         bool handled = false;
109
110         switch (ev->button) {
111         case 1:
112                 status_bar_label.set_text ("");
113                 handled = true;
114                 break;
115         default:
116                 break;
117         }
118
119         return handled;
120 }
121
122 void
123 ARDOUR_UI::display_message (const char* prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char* msg)
124 {
125         UI::display_message (prefix, prefix_len, ptag, mtag, msg);
126
127         ArdourLogLevel ll = LogLevelNone;
128
129         if (strcmp (prefix, _("[ERROR]: ")) == 0) {
130                 ll = LogLevelError;
131         } else if (strcmp (prefix, _("[WARNING]: ")) == 0) {
132                 ll = LogLevelWarning;
133         } else if (strcmp (prefix, _("[INFO]: ")) == 0) {
134                 ll = LogLevelInfo;
135         }
136
137         _log_not_acknowledged = std::max(_log_not_acknowledged, ll);
138 }
139
140 XMLNode*
141 ARDOUR_UI::tearoff_settings (const char* name) const
142 {
143         XMLNode* ui_node = Config->extra_xml(X_("UI"));
144
145         if (ui_node) {
146                 XMLNode* tearoff_node = ui_node->child (X_("Tearoffs"));
147                 if (tearoff_node) {
148                         XMLNode* mnode = tearoff_node->child (name);
149                         return mnode;
150                 }
151         }
152
153         return 0;
154 }
155
156 #define PX_SCALE(px) std::max((float)px, rintf((float)px * UIConfiguration::instance().get_ui_scale()))
157
158 static
159 bool drag_failed (const Glib::RefPtr<Gdk::DragContext>& context, DragResult result, Tabbable* tab)
160 {
161         if (result == Gtk::DRAG_RESULT_NO_TARGET) {
162                 tab->detach ();
163                 return true;
164         }
165         return false;
166 }
167
168 void
169 ARDOUR_UI::repack_transport_hbox ()
170 {
171         if (time_info_box) {
172                 if (time_info_box->get_parent()) {
173                         transport_hbox.remove (*time_info_box);
174                 }
175                 if (UIConfiguration::instance().get_show_toolbar_selclock ()) {
176                         transport_hbox.pack_start (*time_info_box, false, false);
177                         time_info_box->show();
178                 }
179         }
180
181         if (mini_timeline.get_parent()) {
182                 transport_hbox.remove (mini_timeline);
183         }
184         if (UIConfiguration::instance().get_show_mini_timeline ()) {
185                 transport_hbox.pack_start (mini_timeline, true, true);
186                 mini_timeline.show();
187         }
188
189         if (editor_meter) {
190                 if (editor_meter_table.get_parent()) {
191                         transport_hbox.remove (editor_meter_table);
192                 }
193                 if (meterbox_spacer.get_parent()) {
194                         transport_hbox.remove (meterbox_spacer);
195                         transport_hbox.remove (meterbox_spacer2);
196                 }
197
198                 if (UIConfiguration::instance().get_show_editor_meter()) {
199                         transport_hbox.pack_end (meterbox_spacer, false, false, 3);
200                         transport_hbox.pack_end (editor_meter_table, false, false);
201                         transport_hbox.pack_end (meterbox_spacer2, false, false, 3);
202                         editor_meter_table.show();
203                         meterbox_spacer.show();
204                         meterbox_spacer2.show();
205                 }
206         }
207
208         bool show_mon = UIConfiguration::instance().get_show_toolbar_monitoring ();
209         if (show_mon) {
210                 monitor_in_button.show ();
211                 monitor_disk_button.show ();
212                 auto_input_button.show ();
213                 monitoring_spacer.show ();
214         } else {
215                 monitor_in_button.hide ();
216                 monitor_disk_button.hide ();
217                 auto_input_button.hide ();
218                 monitoring_spacer.hide ();
219         }
220
221         bool show_rec = UIConfiguration::instance().get_show_toolbar_recpunch ();
222         if (show_rec) {
223                 punch_label.show ();
224                 layered_label.show ();
225                 punch_in_button.show ();
226                 punch_out_button.show ();
227                 layered_button.show ();
228                 recpunch_spacer.show ();
229         } else {
230                 punch_label.hide ();
231                 layered_label.hide ();
232                 punch_in_button.hide ();
233                 punch_out_button.hide ();
234                 layered_button.hide ();
235                 recpunch_spacer.hide ();
236         }
237
238         bool show_pdc = UIConfiguration::instance().get_show_toolbar_latency ();
239         if (show_pdc) {
240                 latency_disable_button.show ();
241                 route_latency_value.show ();
242                 io_latency_label.show ();
243                 io_latency_value.show ();
244                 latency_spacer.show ();
245         } else {
246                 latency_disable_button.hide ();
247                 route_latency_value.hide ();
248                 io_latency_label.hide ();
249                 io_latency_value.hide ();
250                 latency_spacer.hide ();
251         }
252 }
253
254 void
255 ARDOUR_UI::update_clock_visibility ()
256 {
257         if (ARDOUR::Profile->get_small_screen()) {
258                 return;
259         }
260         if (UIConfiguration::instance().get_show_secondary_clock ()) {
261                 secondary_clock->show();
262                 secondary_clock->left_btn()->show();
263                 secondary_clock->right_btn()->show();
264                 if (secondary_clock_spacer) {
265                         secondary_clock_spacer->show();
266                 }
267         } else {
268                 secondary_clock->hide();
269                 secondary_clock->left_btn()->hide();
270                 secondary_clock->right_btn()->hide();
271                 if (secondary_clock_spacer) {
272                         secondary_clock_spacer->hide();
273                 }
274         }
275 }
276
277 void
278 ARDOUR_UI::setup_transport ()
279 {
280         RefPtr<Action> act;
281         /* setup actions */
282
283         act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
284         sync_button.set_related_action (act);
285         sync_button.signal_button_press_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::sync_button_clicked), false);
286
287         sync_button.set_sizing_text (S_("LogestSync|M-Clk"));
288
289         /* CANNOT sigc::bind these to clicked or toggled, must use pressed or released */
290         act = ActionManager::get_action (X_("Main"), X_("cancel-solo"));
291         solo_alert_button.set_related_action (act);
292         auditioning_alert_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::audition_alert_clicked));
293         error_alert_button.signal_button_release_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::error_alert_press), false);
294         act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
295         error_alert_button.set_related_action(act);
296         error_alert_button.set_fallthrough_to_parent(true);
297
298         layered_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::layered_button_clicked));
299
300         editor_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-editor-visibility")));
301         mixer_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-mixer-visibility")));
302         prefs_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-preferences-visibility")));
303
304         act = ActionManager::get_action ("Transport", "ToggleAutoReturn");
305         auto_return_button.set_related_action (act);
306         act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
307         follow_edits_button.set_related_action (act);
308         act = ActionManager::get_action ("Transport", "ToggleAutoInput");
309         auto_input_button.set_related_action (act);
310
311         act = ActionManager::get_action ("Transport", "TogglePunchIn");
312         punch_in_button.set_related_action (act);
313         act = ActionManager::get_action ("Transport", "TogglePunchOut");
314         punch_out_button.set_related_action (act);
315
316         act = ActionManager::get_action ("Transport", "SessionMonitorIn");
317         monitor_in_button.set_related_action (act);
318         act = ActionManager::get_action ("Transport", "SessionMonitorDisk");
319         monitor_disk_button.set_related_action (act);
320
321         act = ActionManager::get_action ("Main", "ToggleLatencyCompensation");
322         latency_disable_button.set_related_action (act);
323
324         set_size_request_to_display_given_text (route_latency_value, "1000 spl", 0, 0);
325         set_size_request_to_display_given_text (io_latency_value, "1000 spl", 0, 0);
326
327         /* connect signals */
328         ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (primary_clock, &MainClock::set), false, 0));
329         ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (secondary_clock, &MainClock::set), false, 0));
330
331         primary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::primary_clock_value_changed));
332         secondary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::secondary_clock_value_changed));
333         big_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::big_clock_value_changed));
334
335         editor_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), editor));
336         mixer_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), mixer));
337         prefs_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), rc_option_editor));
338
339         /* catch context clicks so that we can show a menu on these buttons */
340
341         editor_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("editor")), false);
342         mixer_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("mixer")), false);
343         prefs_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("preferences")), false);
344
345         /* setup widget style/name */
346
347         auto_return_button.set_name ("transport option button");
348         follow_edits_button.set_name ("transport option button");
349
350         solo_alert_button.set_name ("rude solo");
351         auditioning_alert_button.set_name ("rude audition");
352         feedback_alert_button.set_name ("feedback alert");
353         error_alert_button.set_name ("error alert");
354
355         solo_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
356         auditioning_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
357         feedback_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
358
359         solo_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
360         auditioning_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
361         feedback_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
362
363         editor_visibility_button.set_name (X_("page switch button"));
364         mixer_visibility_button.set_name (X_("page switch button"));
365         prefs_visibility_button.set_name (X_("page switch button"));
366
367         punch_in_button.set_name ("punch button");
368         punch_out_button.set_name ("punch button");
369         layered_button.set_name (("layered button"));
370
371         monitor_in_button.set_name ("monitor button");
372         monitor_disk_button.set_name ("monitor button");
373         auto_input_button.set_name ("transport option button");
374
375         latency_disable_button.set_name ("latency button");
376
377         sync_button.set_name ("transport active option button");
378
379         /* and widget text */
380         auto_return_button.set_text(_("Auto Return"));
381         follow_edits_button.set_text(_("Follow Range"));
382         punch_in_button.set_text (_("In"));
383         punch_out_button.set_text (_("Out"));
384         layered_button.set_text (_("Non-Layered"));
385
386         monitor_in_button.set_text (_("All In"));
387         monitor_disk_button.set_text (_("All Disk"));
388         auto_input_button.set_text (_("Auto-Input"));
389
390         latency_disable_button.set_text (_("Disable PDC"));
391         io_latency_label.set_text (_("I/O Latency:"));
392
393         punch_label.set_text (_("Punch:"));
394         layered_label.set_text (_("Rec:"));
395
396         /* and tooltips */
397
398         Gtkmm2ext::UI::instance()->set_tip (editor_visibility_button,
399                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
400                                                               "To re-attach the window, use the Window > %1 > Attach menu action"), editor->name()));
401
402         Gtkmm2ext::UI::instance()->set_tip (mixer_visibility_button,
403                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
404                                                               "To re-attach the window, use the Window > %1 > Attach menu action"), mixer->name()));
405
406         Gtkmm2ext::UI::instance()->set_tip (prefs_visibility_button,
407                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
408                                                               "To re-attach the window, use the Window > %1 > Attach menu action"), rc_option_editor->name()));
409
410         Gtkmm2ext::UI::instance()->set_tip (punch_in_button, _("Start recording at auto-punch start"));
411         Gtkmm2ext::UI::instance()->set_tip (punch_out_button, _("Stop recording at auto-punch end"));
412
413         Gtkmm2ext::UI::instance()->set_tip (monitor_in_button, _("Force all tracks to monitor Input, unless they are explicitly set to monitor Disk"));
414         Gtkmm2ext::UI::instance()->set_tip (monitor_disk_button, _("Force all tracks to monitor Disk playback, unless they are explicitly set to Input"));
415
416         /* transport control size-group */
417
418         Glib::RefPtr<SizeGroup> punch_button_size_group = SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
419         punch_button_size_group->add_widget (punch_in_button);
420         punch_button_size_group->add_widget (punch_out_button);
421
422         Glib::RefPtr<SizeGroup> monitor_button_size_group = SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
423         monitor_button_size_group->add_widget (monitor_in_button);
424         monitor_button_size_group->add_widget (monitor_disk_button);
425
426         /* and now the layout... */
427
428         /* top level packing */
429         transport_table.set_spacings (0);
430         transport_table.set_row_spacings (4);
431         transport_table.set_border_width (0);
432
433         transport_frame.set_name ("TransportFrame");
434         transport_frame.set_shadow_type (Gtk::SHADOW_NONE);
435
436         /* An event box to hold the table. We use this because we want specific
437            control over the background color, and without this event box,
438            nothing inside the transport_frame actually draws a background. We
439            would therefore end up seeing the background of the parent widget,
440            which is probably some default color. Adding the EventBox adds a
441            widget that will draw the background, using a style based on
442            the parent, "TransportFrame".
443         */
444         Gtk::EventBox* ebox = manage (new Gtk::EventBox);
445         transport_frame.add (*ebox);
446         ebox->add (transport_table);
447
448         /* alert box sub-group */
449         VBox* alert_box = manage (new VBox);
450         alert_box->set_homogeneous (true);
451         alert_box->set_spacing (1);
452         alert_box->set_border_width (0);
453         alert_box->pack_start (solo_alert_button, true, true);
454         alert_box->pack_start (auditioning_alert_button, true, true);
455         alert_box->pack_start (feedback_alert_button, true, true);
456
457         /* clock button size groups */
458         Glib::RefPtr<SizeGroup> button_height_size_group = SizeGroup::create (Gtk::SIZE_GROUP_VERTICAL);
459         button_height_size_group->add_widget (follow_edits_button);
460         button_height_size_group->add_widget (*primary_clock->left_btn());
461         button_height_size_group->add_widget (*primary_clock->right_btn());
462         button_height_size_group->add_widget (*secondary_clock->left_btn());
463         button_height_size_group->add_widget (*secondary_clock->right_btn());
464
465         button_height_size_group->add_widget (transport_ctrl.size_button ());
466         button_height_size_group->add_widget (sync_button);
467         button_height_size_group->add_widget (auto_return_button);
468
469         //tab selections
470         button_height_size_group->add_widget (editor_visibility_button);
471         button_height_size_group->add_widget (mixer_visibility_button);
472
473         //punch section
474         button_height_size_group->add_widget (punch_in_button);
475         button_height_size_group->add_widget (punch_out_button);
476         button_height_size_group->add_widget (layered_button);
477
478         //input monitoring section
479         button_height_size_group->add_widget (monitor_in_button);
480         button_height_size_group->add_widget (monitor_disk_button);
481         button_height_size_group->add_widget (auto_input_button);
482
483         // PDC
484         button_height_size_group->add_widget (latency_disable_button);
485
486         for (int i = 0; i < MAX_LUA_ACTION_BUTTONS; ++i) {
487                 button_height_size_group->add_widget (action_script_call_btn[i]);
488         }
489
490         Glib::RefPtr<SizeGroup> clock1_size_group = SizeGroup::create (SIZE_GROUP_HORIZONTAL);
491         clock1_size_group->add_widget (*primary_clock->left_btn());
492         clock1_size_group->add_widget (*primary_clock->right_btn());
493
494         Glib::RefPtr<SizeGroup> clock2_size_group = SizeGroup::create (SIZE_GROUP_HORIZONTAL);
495         clock2_size_group->add_widget (*secondary_clock->left_btn());
496         clock2_size_group->add_widget (*secondary_clock->right_btn());
497
498         /* sub-layout for Sync | Shuttle (grow) */
499         HBox* ssbox = manage (new HBox);
500         ssbox->set_spacing (PX_SCALE(2));
501         ssbox->pack_start (sync_button, false, false, 0);
502         ssbox->pack_start (shuttle_box, true, true, 0);
503         ssbox->pack_start (*shuttle_box.info_button(), false, false, 0);
504
505
506         /* and the main table layout */
507         int vpadding = 1;
508         int hpadding = 2;
509         int col = 0;
510 #define TCOL col, col + 1
511
512         transport_table.attach (transport_ctrl, TCOL, 0, 1 , SHRINK, SHRINK, 0, 0);
513         transport_table.attach (*ssbox, TCOL, 1, 2 , FILL, SHRINK, 0, 0);
514         ++col;
515
516         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
517         ++col;
518
519         transport_table.attach (punch_label, TCOL, 0, 1 , FILL, SHRINK, 3, 0);
520         transport_table.attach (layered_label, TCOL, 1, 2 , FILL, SHRINK, 3, 0);
521         ++col;
522
523         transport_table.attach (punch_in_button,  col,      col + 1, 0, 1 , FILL, SHRINK, hpadding, vpadding);
524         transport_table.attach (punch_space,      col + 1,  col + 2, 0, 1 , FILL, SHRINK, 0, vpadding);
525         transport_table.attach (punch_out_button, col + 2,  col + 3, 0, 1 , FILL, SHRINK, hpadding, vpadding);
526         transport_table.attach (layered_button,   col,      col + 3, 1, 2 , FILL, SHRINK, hpadding, vpadding);
527         col += 3;
528
529         transport_table.attach (recpunch_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
530         ++col;
531
532         transport_table.attach (auto_input_button,   col,     col + 3, 0, 1 , FILL, SHRINK, hpadding, vpadding);
533         transport_table.attach (monitor_in_button,   col,     col + 1, 1, 2 , FILL, SHRINK, hpadding, vpadding);
534         transport_table.attach (mon_space,           col + 1, col + 2, 1, 2 , FILL, SHRINK, 2, vpadding);
535         transport_table.attach (monitor_disk_button, col + 2, col + 3, 1, 2 , FILL, SHRINK, hpadding, vpadding);
536         col += 3;
537
538         transport_table.attach (monitoring_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
539         ++col;
540
541
542         transport_table.attach (latency_disable_button, TCOL, 0, 1 , FILL, SHRINK, hpadding, vpadding);
543         transport_table.attach (io_latency_label, TCOL, 1, 2 , SHRINK, EXPAND|FILL, hpadding, 0);
544         ++col;
545         transport_table.attach (route_latency_value, TCOL, 0, 1 , SHRINK, EXPAND|FILL, hpadding, 0);
546         transport_table.attach (io_latency_value, TCOL, 1, 2 , SHRINK, EXPAND|FILL, hpadding, 0);
547         ++col;
548
549         route_latency_value.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
550         io_latency_value.set_alignment (Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
551
552         transport_table.attach (latency_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
553         ++col;
554
555         transport_table.attach (follow_edits_button, TCOL, 0, 1 , FILL, SHRINK, hpadding, vpadding);
556         transport_table.attach (auto_return_button,  TCOL, 1, 2 , FILL, SHRINK, hpadding, vpadding);
557         ++col;
558
559         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
560         ++col;
561
562         transport_table.attach (*primary_clock,              col,     col + 2, 0, 1 , FILL, SHRINK, hpadding, 0);
563         transport_table.attach (*primary_clock->left_btn(),  col,     col + 1, 1, 2 , FILL, SHRINK, hpadding, 0);
564         transport_table.attach (*primary_clock->right_btn(), col + 1, col + 2, 1, 2 , FILL, SHRINK, hpadding, 0);
565         col += 2;
566
567         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
568         ++col;
569
570         if (!ARDOUR::Profile->get_small_screen()) {
571                 transport_table.attach (*secondary_clock,              col,     col + 2, 0, 1 , FILL, SHRINK, hpadding, 0);
572                 transport_table.attach (*secondary_clock->left_btn(),  col,     col + 1, 1, 2 , FILL, SHRINK, hpadding, 0);
573                 transport_table.attach (*secondary_clock->right_btn(), col + 1, col + 2, 1, 2 , FILL, SHRINK, hpadding, 0);
574                 secondary_clock->set_no_show_all (true);
575                 secondary_clock->left_btn()->set_no_show_all (true);
576                 secondary_clock->right_btn()->set_no_show_all (true);
577                 col += 2;
578
579                 secondary_clock_spacer = manage (new ArdourVSpacer ());
580                 transport_table.attach (*secondary_clock_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
581                 ++col;
582         }
583
584         transport_table.attach (*alert_box, TCOL, 0, 2, SHRINK, EXPAND|FILL, hpadding, 0);
585         ++col;
586
587         /* editor-meter, mini-timeline and selection clock are options in the transport_hbox */
588         transport_hbox.set_spacing (3);
589         transport_table.attach (transport_hbox, TCOL, 0, 2, EXPAND|FILL, EXPAND|FILL, hpadding, 0);
590         ++col;
591
592         /* lua script action buttons */
593         for (int i = 0; i < MAX_LUA_ACTION_BUTTONS; ++i) {
594                 const int r = i % 2;
595                 const int c = col + i / 2;
596                 transport_table.attach (action_script_call_btn[i], c, c + 1, r, r + 1, FILL, SHRINK, 1, vpadding);
597         }
598         col += MAX_LUA_ACTION_BUTTONS / 2;
599
600         transport_table.attach (editor_visibility_button, TCOL, 0, 1 , FILL, SHRINK, hpadding, vpadding);
601         transport_table.attach (mixer_visibility_button,  TCOL, 1, 2 , FILL, SHRINK, hpadding, vpadding);
602         ++col;
603
604         /* initialize */
605         latency_switch_changed ();
606         session_latency_updated ();
607
608         repack_transport_hbox ();
609         update_clock_visibility ();
610         /* desensitize */
611
612         feedback_alert_button.set_sensitive (false);
613         feedback_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
614         auditioning_alert_button.set_sensitive (false);
615         auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
616
617         set_transport_sensitivity (false);
618 }
619 #undef PX_SCALE
620 #undef TCOL
621
622
623 void
624 ARDOUR_UI::latency_switch_changed ()
625 {
626         bool pdc_off = ARDOUR::Latent::zero_latency ();
627         if (latency_disable_button.get_active() != pdc_off) {
628                 latency_disable_button.set_active (pdc_off);
629         }
630 }
631
632 void
633 ARDOUR_UI::session_latency_updated ()
634 {
635         if (!_session) {
636                 route_latency_value.set_text ("--");
637                 io_latency_value.set_text ("--");
638         } else {
639                 samplecnt_t wrl = _session->worst_route_latency ();
640                 samplecnt_t wpl = _session->worst_latency_preroll ();
641                 float rate      = _session->nominal_sample_rate ();
642
643                 route_latency_value.set_text (samples_as_time_string (wrl, rate));
644                 io_latency_value.set_text (samples_as_time_string (wpl, rate));
645         }
646 }
647
648 void
649 ARDOUR_UI::soloing_changed (bool onoff)
650 {
651         if (solo_alert_button.get_active() != onoff) {
652                 solo_alert_button.set_active (onoff);
653         }
654 }
655
656 void
657 ARDOUR_UI::_auditioning_changed (bool onoff)
658 {
659         auditioning_alert_button.set_active (onoff);
660         auditioning_alert_button.set_sensitive (onoff);
661         if (!onoff) {
662                 auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
663         }
664         set_transport_sensitivity (!onoff);
665 }
666
667 void
668 ARDOUR_UI::auditioning_changed (bool onoff)
669 {
670         UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::_auditioning_changed, this, onoff));
671 }
672
673 void
674 ARDOUR_UI::audition_alert_clicked ()
675 {
676         if (_session) {
677                 _session->cancel_audition();
678         }
679 }
680
681 bool
682 ARDOUR_UI::error_alert_press (GdkEventButton* ev)
683 {
684         bool do_toggle = true;
685         if (ev->button == 1) {
686                 if (_log_not_acknowledged == LogLevelError) {
687                         // just acknowledge the error, don't hide the log if it's already visible
688                         RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-log-window"));
689                         if (tact->get_active()) {
690                                 do_toggle = false;
691                         }
692                 }
693                 _log_not_acknowledged = LogLevelNone;
694                 error_blink (false); // immediate acknowledge
695         }
696         // maybe fall through to to button toggle
697         return !do_toggle;
698 }
699
700 void
701 ARDOUR_UI::layered_button_clicked ()
702 {
703         if (_session) {
704                 _session->config.set_layered_record_mode (!_session->config.get_layered_record_mode ());
705         }
706 }
707
708 void
709 ARDOUR_UI::solo_blink (bool onoff)
710 {
711         if (_session == 0) {
712                 return;
713         }
714
715         if (_session->soloing() || _session->listening()) {
716                 if (onoff) {
717                         solo_alert_button.set_active (true);
718                 } else {
719                         solo_alert_button.set_active (false);
720                 }
721         } else {
722                 solo_alert_button.set_active (false);
723         }
724 }
725
726 void
727 ARDOUR_UI::sync_blink (bool onoff)
728 {
729         if (_session == 0 || !_session->config.get_external_sync()) {
730                 /* internal sync */
731                 sync_button.set_active (false);
732                 return;
733         }
734
735         if (!_session->transport_locked()) {
736                 /* not locked, so blink on and off according to the onoff argument */
737
738                 if (onoff) {
739                         sync_button.set_active (true);
740                 } else {
741                         sync_button.set_active (false);
742                 }
743         } else {
744                 /* locked */
745                 sync_button.set_active (true);
746         }
747 }
748
749 void
750 ARDOUR_UI::audition_blink (bool onoff)
751 {
752         if (_session == 0) {
753                 return;
754         }
755
756         if (_session->is_auditioning()) {
757                 if (onoff) {
758                         auditioning_alert_button.set_active (true);
759                 } else {
760                         auditioning_alert_button.set_active (false);
761                 }
762         } else {
763                 auditioning_alert_button.set_active (false);
764         }
765 }
766
767 void
768 ARDOUR_UI::feedback_blink (bool onoff)
769 {
770         if (_feedback_exists) {
771                 feedback_alert_button.set_active (true);
772                 if (onoff) {
773                         feedback_alert_button.reset_fixed_colors ();
774                 } else {
775                         feedback_alert_button.set_active_color (UIConfigurationBase::instance().color ("feedback alert: alt active", NULL));
776                 }
777         } else {
778                 feedback_alert_button.reset_fixed_colors ();
779                 feedback_alert_button.set_active (false);
780         }
781 }
782
783 void
784 ARDOUR_UI::error_blink (bool onoff)
785 {
786         switch (_log_not_acknowledged) {
787                 case LogLevelError:
788                         // blink
789                         if (onoff) {
790                                 error_alert_button.set_custom_led_color(0xff0000ff); // bright red
791                         } else {
792                                 error_alert_button.set_custom_led_color(0x880000ff); // dark red
793                         }
794                         break;
795                 case LogLevelWarning:
796                         error_alert_button.set_custom_led_color(0xccaa00ff); // yellow
797                         break;
798                 case LogLevelInfo:
799                         error_alert_button.set_custom_led_color(0x88cc00ff); // lime green
800                         break;
801                 default:
802                         error_alert_button.set_custom_led_color(0x333333ff); // gray
803                         break;
804         }
805 }
806 void
807 ARDOUR_UI::set_transport_sensitivity (bool yn)
808 {
809         ActionManager::set_sensitive (ActionManager::transport_sensitive_actions, yn);
810         shuttle_box.set_sensitive (yn);
811 }
812
813 void
814 ARDOUR_UI::editor_realized ()
815 {
816         boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
817         Config->map_parameters (pc);
818
819         UIConfiguration::instance().reset_dpi ();
820 }
821
822 void
823 ARDOUR_UI::maximise_editing_space ()
824 {
825         if (editor) {
826                 editor->maximise_editing_space ();
827         }
828 }
829
830 void
831 ARDOUR_UI::restore_editing_space ()
832 {
833         if (editor) {
834                 editor->restore_editing_space ();
835         }
836 }
837
838 void
839 ARDOUR_UI::show_ui_prefs ()
840 {
841         if (rc_option_editor) {
842                 show_tabbable (rc_option_editor);
843                 rc_option_editor->set_current_page (_("Appearance"));
844         }
845 }
846
847 bool
848 ARDOUR_UI::click_button_clicked (GdkEventButton* ev)
849 {
850         if (ev->button != 3) {
851                 /* this handler is just for button-3 clicks */
852                 return false;
853         }
854
855         show_tabbable (rc_option_editor);
856         rc_option_editor->set_current_page (_("Metronome"));
857         return true;
858 }
859
860 bool
861 ARDOUR_UI::sync_button_clicked (GdkEventButton* ev)
862 {
863         if (ev->button != 3) {
864                 /* this handler is just for button-3 clicks */
865                 return false;
866         }
867
868         show_tabbable (rc_option_editor);
869         rc_option_editor->set_current_page (_("Sync"));
870         return true;
871 }
872
873 void
874 ARDOUR_UI::toggle_follow_edits ()
875 {
876         RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Transport"), X_("ToggleFollowEdits"));
877         UIConfiguration::instance().set_follow_edits (tact->get_active ());
878 }
879
880 void
881 ARDOUR_UI::update_title ()
882 {
883         if (_session) {
884                 bool dirty = _session->dirty();
885
886                 string session_name;
887
888                 if (_session->snap_name() != _session->name()) {
889                         session_name = _session->snap_name();
890                 } else {
891                         session_name = _session->name();
892                 }
893
894                 if (dirty) {
895                         session_name = "*" + session_name;
896                 }
897
898                 WindowTitle title (session_name);
899                 title += Glib::get_application_name();
900                 _main_window.set_title (title.get_string());
901         } else {
902                 WindowTitle title (Glib::get_application_name());
903                 _main_window.set_title (title.get_string());
904         }
905
906 }
907