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