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