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