Re-pack dsp_load_indicator next to feedback_indicator et al.
[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 (dsp_load_indicator.get_parent()) {
176                 transport_hbox.remove (dsp_load_indicator);
177         }
178         if (UIConfiguration::instance().get_show_dsp_load_info ()) {
179                 transport_hbox.pack_start (dsp_load_indicator, false, false);
180                 dsp_load_indicator.show();
181         }
182
183         if (disk_space_indicator.get_parent()) {
184                 transport_hbox.remove (disk_space_indicator);
185         }
186         if (UIConfiguration::instance().get_show_disk_space_info ()) {
187                 transport_hbox.pack_start (disk_space_indicator, false, false);
188                 disk_space_indicator.show();
189         }
190
191         if (status_spacer.get_parent()) {
192                 transport_hbox.remove (status_spacer);
193         }
194         transport_hbox.pack_start (status_spacer, false, false, 3);
195
196         if (time_info_box) {
197                 if (time_info_box->get_parent()) {
198                         transport_hbox.remove (*time_info_box);
199                 }
200                 if (UIConfiguration::instance().get_show_toolbar_selclock ()) {
201                         transport_hbox.pack_start (*time_info_box, false, false);
202                         time_info_box->show();
203                 }
204         }
205
206         if (mini_timeline.get_parent()) {
207                 transport_hbox.remove (mini_timeline);
208         }
209         if (UIConfiguration::instance().get_show_mini_timeline ()) {
210                 transport_hbox.pack_start (mini_timeline, true, true);
211                 mini_timeline.show();
212         }
213
214         if (editor_meter) {
215                 if (meter_box.get_parent()) {
216                         transport_hbox.remove (meter_box);
217                         transport_hbox.remove (editor_meter_peak_display);
218                 }
219
220                 if (UIConfiguration::instance().get_show_editor_meter()) {
221                         transport_hbox.pack_end (editor_meter_peak_display, false, false);
222                         transport_hbox.pack_end (meter_box, false, false);
223                         meter_box.show();
224                         editor_meter_peak_display.show();
225                 }
226         }
227
228         bool show_mon = UIConfiguration::instance().get_show_toolbar_monitoring ();
229         if (show_mon) {
230                 monitor_in_button.show ();
231                 monitor_disk_button.show ();
232                 auto_input_button.show ();
233                 monitoring_spacer.show ();
234         } else {
235                 monitor_in_button.hide ();
236                 monitor_disk_button.hide ();
237                 auto_input_button.hide ();
238                 monitoring_spacer.hide ();
239         }
240
241         bool show_rec = UIConfiguration::instance().get_show_toolbar_recpunch ();
242         if (show_rec) {
243                 punch_label.show ();
244                 layered_label.show ();
245                 punch_in_button.show ();
246                 punch_out_button.show ();
247                 layered_button.show ();
248                 recpunch_spacer.show ();
249         } else {
250                 punch_label.hide ();
251                 layered_label.hide ();
252                 punch_in_button.hide ();
253                 punch_out_button.hide ();
254                 layered_button.hide ();
255                 recpunch_spacer.hide ();
256         }
257
258 }
259
260 void
261 ARDOUR_UI::update_clock_visibility ()
262 {
263         if (ARDOUR::Profile->get_small_screen()) {
264                 return;
265         }
266         if (UIConfiguration::instance().get_show_secondary_clock ()) {
267                 secondary_clock->show();
268                 secondary_clock->left_btn()->show();
269                 secondary_clock->right_btn()->show();
270                 if (secondary_clock_spacer) {
271                         secondary_clock_spacer->show();
272                 }
273         } else {
274                 secondary_clock->hide();
275                 secondary_clock->left_btn()->hide();
276                 secondary_clock->right_btn()->hide();
277                 if (secondary_clock_spacer) {
278                         secondary_clock_spacer->hide();
279                 }
280         }
281 }
282
283 void
284 ARDOUR_UI::setup_transport ()
285 {
286         RefPtr<Action> act;
287         /* setup actions */
288
289         act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
290         sync_button.set_related_action (act);
291         sync_button.signal_button_press_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::sync_button_clicked), false);
292
293         sync_button.set_sizing_text (S_("LogestSync|M-Clk"));
294
295         /* CANNOT sigc::bind these to clicked or toggled, must use pressed or released */
296         act = ActionManager::get_action (X_("Main"), X_("cancel-solo"));
297         solo_alert_button.set_related_action (act);
298         auditioning_alert_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::audition_alert_clicked));
299         error_alert_button.signal_button_release_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::error_alert_press), false);
300         act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
301         error_alert_button.set_related_action(act);
302         error_alert_button.set_fallthrough_to_parent(true);
303
304         layered_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::layered_button_clicked));
305
306         editor_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-editor-visibility")));
307         mixer_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-mixer-visibility")));
308         prefs_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-preferences-visibility")));
309
310         act = ActionManager::get_action ("Transport", "ToggleAutoReturn");
311         auto_return_button.set_related_action (act);
312         act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
313         follow_edits_button.set_related_action (act);
314         act = ActionManager::get_action ("Transport", "ToggleAutoInput");
315         auto_input_button.set_related_action (act);
316
317         act = ActionManager::get_action ("Transport", "TogglePunchIn");
318         punch_in_button.set_related_action (act);
319         act = ActionManager::get_action ("Transport", "TogglePunchOut");
320         punch_out_button.set_related_action (act);
321
322         act = ActionManager::get_action ("Transport", "SessionMonitorIn");
323         monitor_in_button.set_related_action (act);
324         act = ActionManager::get_action ("Transport", "SessionMonitorDisk");
325         monitor_disk_button.set_related_action (act);
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         sync_button.set_name ("transport active option button");
376
377         /* and widget text */
378         auto_return_button.set_text(_("Auto Return"));
379         follow_edits_button.set_text(_("Follow Range"));
380         punch_in_button.set_text (_("In"));
381         punch_out_button.set_text (_("Out"));
382         layered_button.set_text (_("Non-Layered"));
383
384         monitor_in_button.set_text (_("All In"));
385         monitor_disk_button.set_text (_("All Disk"));
386         auto_input_button.set_text (_("Auto-Input"));
387
388         punch_label.set_text (_("Punch:"));
389         layered_label.set_text (_("Rec:"));
390
391         /* and tooltips */
392
393         Gtkmm2ext::UI::instance()->set_tip (editor_visibility_button,
394                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
395                                                               "To re-attach the window, use the Window > %1 > Attach menu action"), editor->name()));
396
397         Gtkmm2ext::UI::instance()->set_tip (mixer_visibility_button,
398                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
399                                                               "To re-attach the window, use the Window > %1 > Attach menu action"), mixer->name()));
400
401         Gtkmm2ext::UI::instance()->set_tip (prefs_visibility_button,
402                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
403                                                               "To re-attach the window, use the Window > %1 > Attach menu action"), rc_option_editor->name()));
404
405         Gtkmm2ext::UI::instance()->set_tip (punch_in_button, _("Start recording at auto-punch start"));
406         Gtkmm2ext::UI::instance()->set_tip (punch_out_button, _("Stop recording at auto-punch end"));
407
408         Gtkmm2ext::UI::instance()->set_tip (monitor_in_button, _("Force all tracks to monitor Input, unless they are explicitly set to monitor Disk"));
409         Gtkmm2ext::UI::instance()->set_tip (monitor_disk_button, _("Force all tracks to monitor Disk playback, unless they are explicitly set to Input"));
410
411         /* transport control size-group */
412
413         Glib::RefPtr<SizeGroup> punch_button_size_group = SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
414         punch_button_size_group->add_widget (punch_in_button);
415         punch_button_size_group->add_widget (punch_out_button);
416
417         Glib::RefPtr<SizeGroup> monitor_button_size_group = SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
418         monitor_button_size_group->add_widget (monitor_in_button);
419         monitor_button_size_group->add_widget (monitor_disk_button);
420
421         /* and now the layout... */
422
423         /* top level packing */
424         transport_table.set_spacings (0);
425         transport_table.set_row_spacings (4);
426         transport_table.set_border_width (2);
427
428         transport_frame.set_name ("TransportFrame");
429         transport_frame.set_shadow_type (Gtk::SHADOW_NONE);
430
431         /* An event box to hold the table. We use this because we want specific
432            control over the background color, and without this event box,
433            nothing inside the transport_sample actually draws a background. We
434            would therefore end up seeing the background of the parent widget,
435            which is probably some default color. Adding the EventBox adds a
436            widget that will draw the background, using a style based on
437            the parent, "TransportFrame".
438         */
439         Gtk::EventBox* ebox = manage (new Gtk::EventBox);
440         transport_frame.add (*ebox);
441         ebox->add (transport_table);
442
443         /* alert box sub-group */
444         VBox* alert_box = manage (new VBox);
445         alert_box->set_homogeneous (true);
446         alert_box->set_spacing (1);
447         alert_box->set_border_width (0);
448         alert_box->pack_start (solo_alert_button, true, true);
449         alert_box->pack_start (auditioning_alert_button, true, true);
450         alert_box->pack_start (feedback_alert_button, true, true);
451
452         /* clock button size groups */
453         Glib::RefPtr<SizeGroup> button_height_size_group = SizeGroup::create (Gtk::SIZE_GROUP_VERTICAL);
454         button_height_size_group->add_widget (follow_edits_button);
455         button_height_size_group->add_widget (*primary_clock->left_btn());
456         button_height_size_group->add_widget (*primary_clock->right_btn());
457         button_height_size_group->add_widget (*secondary_clock->left_btn());
458         button_height_size_group->add_widget (*secondary_clock->right_btn());
459
460         button_height_size_group->add_widget (transport_ctrl.size_button ());
461 //      button_height_size_group->add_widget (sync_button);
462         button_height_size_group->add_widget (auto_return_button);
463
464         //tab selections
465         button_height_size_group->add_widget (editor_visibility_button);
466         button_height_size_group->add_widget (mixer_visibility_button);
467
468         //punch section
469         button_height_size_group->add_widget (punch_in_button);
470         button_height_size_group->add_widget (punch_out_button);
471         button_height_size_group->add_widget (layered_button);
472
473         //input monitoring section
474         button_height_size_group->add_widget (monitor_in_button);
475         button_height_size_group->add_widget (monitor_disk_button);
476         button_height_size_group->add_widget (auto_input_button);
477
478         Glib::RefPtr<SizeGroup> clock1_size_group = SizeGroup::create (SIZE_GROUP_HORIZONTAL);
479         clock1_size_group->add_widget (*primary_clock->left_btn());
480         clock1_size_group->add_widget (*primary_clock->right_btn());
481
482         Glib::RefPtr<SizeGroup> clock2_size_group = SizeGroup::create (SIZE_GROUP_HORIZONTAL);
483         clock2_size_group->add_widget (*secondary_clock->left_btn());
484         clock2_size_group->add_widget (*secondary_clock->right_btn());
485
486         /* sub-layout for Sync | Shuttle (grow) */
487         HBox* ssbox = manage (new HBox);
488         ssbox->set_spacing (PX_SCALE(2));
489         ssbox->pack_start (sync_button, false, false, 0);
490         ssbox->pack_start (shuttle_box, true, true, 0);
491         ssbox->pack_start (*shuttle_box.info_button(), false, false, 0);
492
493
494         /* and the main table layout */
495         int vpadding = 1;
496         int hpadding = 2;
497         int col = 0;
498 #define TCOL col, col + 1
499
500         transport_table.attach (transport_ctrl, TCOL, 0, 1 , SHRINK, SHRINK, 0, 0);
501         transport_table.attach (*ssbox, TCOL, 1, 2 , FILL, SHRINK, 0, 0);
502         ++col;
503
504         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
505         ++col;
506
507         transport_table.attach (punch_label, TCOL, 0, 1 , FILL, SHRINK, 3, 0);
508         transport_table.attach (layered_label, TCOL, 1, 2 , FILL, SHRINK, 3, 0);
509         ++col;
510
511         transport_table.attach (punch_in_button,  col,      col + 1, 0, 1 , FILL, SHRINK, hpadding, vpadding);
512         transport_table.attach (punch_space,      col + 1,  col + 2, 0, 1 , FILL, SHRINK, 0, vpadding);
513         transport_table.attach (punch_out_button, col + 2,  col + 3, 0, 1 , FILL, SHRINK, hpadding, vpadding);
514         transport_table.attach (layered_button,   col,      col + 3, 1, 2 , FILL, SHRINK, hpadding, vpadding);
515         col += 3;
516
517         transport_table.attach (recpunch_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
518         ++col;
519
520         transport_table.attach (auto_input_button,   col,     col + 3, 0, 1 , FILL, SHRINK, hpadding, vpadding);
521         transport_table.attach (monitor_in_button,   col,     col + 1, 1, 2 , FILL, SHRINK, hpadding, vpadding);
522         transport_table.attach (mon_space,           col + 1, col + 2, 1, 2 , FILL, SHRINK, 2, vpadding);
523         transport_table.attach (monitor_disk_button, col + 2, col + 3, 1, 2 , FILL, SHRINK, hpadding, vpadding);
524         col += 3;
525
526         transport_table.attach (monitoring_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
527         ++col;
528
529         transport_table.attach (follow_edits_button, TCOL, 0, 1 , FILL, SHRINK, hpadding, vpadding);
530         transport_table.attach (auto_return_button,  TCOL, 1, 2 , FILL, SHRINK, hpadding, vpadding);
531         ++col;
532
533         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
534         ++col;
535
536         transport_table.attach (*primary_clock,              col,     col + 2, 0, 1 , FILL, SHRINK, hpadding, 0);
537         transport_table.attach (*primary_clock->left_btn(),  col,     col + 1, 1, 2 , FILL, SHRINK, hpadding, 0);
538         transport_table.attach (*primary_clock->right_btn(), col + 1, col + 2, 1, 2 , FILL, SHRINK, hpadding, 0);
539         col += 2;
540
541         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
542         ++col;
543
544         if (!ARDOUR::Profile->get_small_screen()) {
545                 transport_table.attach (*secondary_clock,              col,     col + 2, 0, 1 , FILL, SHRINK, hpadding, 0);
546                 transport_table.attach (*secondary_clock->left_btn(),  col,     col + 1, 1, 2 , FILL, SHRINK, hpadding, 0);
547                 transport_table.attach (*secondary_clock->right_btn(), col + 1, col + 2, 1, 2 , FILL, SHRINK, hpadding, 0);
548                 secondary_clock->set_no_show_all (true);
549                 secondary_clock->left_btn()->set_no_show_all (true);
550                 secondary_clock->right_btn()->set_no_show_all (true);
551                 col += 2;
552
553                 secondary_clock_spacer = manage (new ArdourVSpacer ());
554                 transport_table.attach (*secondary_clock_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
555                 ++col;
556         }
557
558         transport_table.attach (*alert_box, TCOL, 0, 2, SHRINK, EXPAND|FILL, hpadding, 0);
559         ++col;
560
561         /* editor-meter, mini-timeline and selection clock are options in the transport_hbox */
562         transport_hbox.set_spacing (3);
563         transport_table.attach (transport_hbox, TCOL, 0, 2, EXPAND|FILL, EXPAND|FILL, hpadding, 0);
564         ++col;
565
566         /* lua script action buttons */
567         transport_table.attach (action_script_table, TCOL, 0, 2, SHRINK, EXPAND|FILL, 1, 0);
568         ++col;
569
570         transport_table.attach (editor_visibility_button, TCOL, 0, 1 , FILL, SHRINK, hpadding, vpadding);
571         transport_table.attach (mixer_visibility_button,  TCOL, 1, 2 , FILL, SHRINK, hpadding, vpadding);
572         ++col;
573
574         repack_transport_hbox ();
575         update_clock_visibility ();
576         /* desensitize */
577
578         feedback_alert_button.set_sensitive (false);
579         feedback_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
580         auditioning_alert_button.set_sensitive (false);
581         auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
582
583         set_transport_sensitivity (false);
584 }
585 #undef PX_SCALE
586 #undef TCOL
587
588 void
589 ARDOUR_UI::soloing_changed (bool onoff)
590 {
591         if (solo_alert_button.get_active() != onoff) {
592                 solo_alert_button.set_active (onoff);
593         }
594 }
595
596 void
597 ARDOUR_UI::_auditioning_changed (bool onoff)
598 {
599         auditioning_alert_button.set_active (onoff);
600         auditioning_alert_button.set_sensitive (onoff);
601         if (!onoff) {
602                 auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
603         }
604         set_transport_sensitivity (!onoff);
605 }
606
607 void
608 ARDOUR_UI::auditioning_changed (bool onoff)
609 {
610         UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::_auditioning_changed, this, onoff));
611 }
612
613 void
614 ARDOUR_UI::audition_alert_clicked ()
615 {
616         if (_session) {
617                 _session->cancel_audition();
618         }
619 }
620
621 bool
622 ARDOUR_UI::error_alert_press (GdkEventButton* ev)
623 {
624         bool do_toggle = true;
625         if (ev->button == 1) {
626                 if (_log_not_acknowledged == LogLevelError) {
627                         // just acknowledge the error, don't hide the log if it's already visible
628                         RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
629                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
630                         if (tact && tact->get_active()) {
631                                 do_toggle = false;
632                         }
633                 }
634                 _log_not_acknowledged = LogLevelNone;
635                 error_blink (false); // immediate acknowledge
636         }
637         // maybe fall through to to button toggle
638         return !do_toggle;
639 }
640
641 void
642 ARDOUR_UI::layered_button_clicked ()
643 {
644         if (_session) {
645                 _session->config.set_layered_record_mode (!_session->config.get_layered_record_mode ());
646         }
647 }
648
649 void
650 ARDOUR_UI::solo_blink (bool onoff)
651 {
652         if (_session == 0) {
653                 return;
654         }
655
656         if (_session->soloing() || _session->listening()) {
657                 if (onoff) {
658                         solo_alert_button.set_active (true);
659                 } else {
660                         solo_alert_button.set_active (false);
661                 }
662         } else {
663                 solo_alert_button.set_active (false);
664         }
665 }
666
667 void
668 ARDOUR_UI::sync_blink (bool onoff)
669 {
670         if (_session == 0 || !_session->config.get_external_sync()) {
671                 /* internal sync */
672                 sync_button.set_active (false);
673                 return;
674         }
675
676         if (!_session->transport_locked()) {
677                 /* not locked, so blink on and off according to the onoff argument */
678
679                 if (onoff) {
680                         sync_button.set_active (true);
681                 } else {
682                         sync_button.set_active (false);
683                 }
684         } else {
685                 /* locked */
686                 sync_button.set_active (true);
687         }
688 }
689
690 void
691 ARDOUR_UI::audition_blink (bool onoff)
692 {
693         if (_session == 0) {
694                 return;
695         }
696
697         if (_session->is_auditioning()) {
698                 if (onoff) {
699                         auditioning_alert_button.set_active (true);
700                 } else {
701                         auditioning_alert_button.set_active (false);
702                 }
703         } else {
704                 auditioning_alert_button.set_active (false);
705         }
706 }
707
708 void
709 ARDOUR_UI::feedback_blink (bool onoff)
710 {
711         if (_feedback_exists) {
712                 if (onoff) {
713                         feedback_alert_button.set_active (true);
714                 } else {
715                         feedback_alert_button.set_active (false);
716                 }
717         } else {
718                 feedback_alert_button.set_active (false);
719         }
720 }
721
722 void
723 ARDOUR_UI::error_blink (bool onoff)
724 {
725         switch (_log_not_acknowledged) {
726                 case LogLevelError:
727                         // blink
728                         if (onoff) {
729                                 error_alert_button.set_custom_led_color(0xff0000ff); // bright red
730                         } else {
731                                 error_alert_button.set_custom_led_color(0x880000ff); // dark red
732                         }
733                         break;
734                 case LogLevelWarning:
735                         error_alert_button.set_custom_led_color(0xccaa00ff); // yellow
736                         break;
737                 case LogLevelInfo:
738                         error_alert_button.set_custom_led_color(0x88cc00ff); // lime green
739                         break;
740                 default:
741                         error_alert_button.set_custom_led_color(0x333333ff); // gray
742                         break;
743         }
744 }
745 void
746 ARDOUR_UI::set_transport_sensitivity (bool yn)
747 {
748         ActionManager::set_sensitive (ActionManager::transport_sensitive_actions, yn);
749         shuttle_box.set_sensitive (yn);
750 }
751
752 void
753 ARDOUR_UI::editor_realized ()
754 {
755         boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
756         Config->map_parameters (pc);
757
758         UIConfiguration::instance().reset_dpi ();
759 }
760
761 void
762 ARDOUR_UI::maximise_editing_space ()
763 {
764         if (editor) {
765                 editor->maximise_editing_space ();
766         }
767 }
768
769 void
770 ARDOUR_UI::restore_editing_space ()
771 {
772         if (editor) {
773                 editor->restore_editing_space ();
774         }
775 }
776
777 void
778 ARDOUR_UI::show_ui_prefs ()
779 {
780         if (rc_option_editor) {
781                 show_tabbable (rc_option_editor);
782                 rc_option_editor->set_current_page (_("Appearance"));
783         }
784 }
785
786 bool
787 ARDOUR_UI::click_button_clicked (GdkEventButton* ev)
788 {
789         if (ev->button != 3) {
790                 /* this handler is just for button-3 clicks */
791                 return false;
792         }
793
794         show_tabbable (rc_option_editor);
795         rc_option_editor->set_current_page (_("Metronome"));
796         return true;
797 }
798
799 bool
800 ARDOUR_UI::sync_button_clicked (GdkEventButton* ev)
801 {
802         if (ev->button != 3) {
803                 /* this handler is just for button-3 clicks */
804                 return false;
805         }
806
807         show_tabbable (rc_option_editor);
808         rc_option_editor->set_current_page (_("Sync"));
809         return true;
810 }
811
812 void
813 ARDOUR_UI::toggle_follow_edits ()
814 {
815         RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
816         assert (act);
817
818         RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
819         assert (tact);
820
821         UIConfiguration::instance().set_follow_edits (tact->get_active ());
822 }
823
824 void
825 ARDOUR_UI::update_title ()
826 {
827         if (_session) {
828                 bool dirty = _session->dirty();
829
830                 string session_name;
831
832                 if (_session->snap_name() != _session->name()) {
833                         session_name = _session->snap_name();
834                 } else {
835                         session_name = _session->name();
836                 }
837
838                 if (dirty) {
839                         session_name = "*" + session_name;
840                 }
841
842                 WindowTitle title (session_name);
843                 title += Glib::get_application_name();
844                 _main_window.set_title (title.get_string());
845         } else {
846                 WindowTitle title (Glib::get_application_name());
847                 _main_window.set_title (title.get_string());
848         }
849
850 }