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