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