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