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