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