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