Configurable toolbar rec/punch & monitoring buttons
[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/click_box.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 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         set_tip (click_button, _("Enable/Disable audio click"));
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 bool
270 ARDOUR_UI::transport_expose (GdkEventExpose* ev)
271 {
272 return false;
273         int x0, y0;
274         Gtk::Widget* window_parent;
275         Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (transport_table, &window_parent);
276         Glib::RefPtr<Gtk::Style> style = transport_table.get_style();
277         if (!win || !style) {
278                 return false;
279         }
280
281         Cairo::RefPtr<Cairo::Context> cr = transport_table.get_window()->create_cairo_context ();
282
283         cr->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
284         cr->clip ();
285
286         transport_table.translate_coordinates (*window_parent, 0, 0, x0, y0);
287
288         cr->rectangle (x0, y0, transport_table.get_width(), transport_table.get_height());
289         Gdk::Color bg (style->get_bg (transport_table.get_state()));
290         cr->set_source_rgb (bg.get_red_p(), bg.get_green_p(), bg.get_blue_p());
291         cr->fill ();
292
293         static const int xmargin = 2;
294         static const int ymargin = 1;
295
296         /* draw box around record-options */
297         int xx, ww, hh, uu;
298
299         punch_label.translate_coordinates (transport_table, -xmargin, 0, xx, uu); // left
300         punch_out_button.translate_coordinates (transport_table, xmargin, 0, ww, uu); // right
301         ww += punch_out_button.get_width () - xx; // width
302         hh = transport_table.get_height() - 1;
303
304         Gtkmm2ext::rounded_rectangle (cr->cobj(), x0 + xx - 0.5, y0 + 0.5, ww + 1, hh, 6);
305         cr->set_source_rgb (0, 0, 0);
306         cr->set_line_width (1.0);
307         cr->stroke ();
308
309         /* line to rec-enable */
310         int rx;
311         rec_button.translate_coordinates (transport_table, -xmargin, 0, rx, uu); // top
312         int dx = rx + rec_button.get_width() - xx;
313
314         cr->move_to (x0 + xx, 1.5 + y0 + ymargin + round (punch_in_button.get_height () * .5));
315         cr->rel_line_to (dx, 0);
316         cr->set_line_width (2.0);
317         cr->stroke ();
318
319         return false;
320 }
321
322 void
323 ARDOUR_UI::setup_transport ()
324 {
325         RefPtr<Action> act;
326         /* setup actions */
327
328         act = ActionManager::get_action ("Transport", "ToggleClick");
329         click_button.set_related_action (act);
330         click_button.signal_button_press_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::click_button_clicked), false);
331
332         act = ActionManager::get_action (X_("Transport"), X_("Stop"));
333         stop_button.set_related_action (act);
334         act = ActionManager::get_action (X_("Transport"), X_("Roll"));
335         roll_button.set_related_action (act);
336         act = ActionManager::get_action (X_("Transport"), X_("Record"));
337         rec_button.set_related_action (act);
338         act = ActionManager::get_action (X_("Transport"), X_("GotoStart"));
339         goto_start_button.set_related_action (act);
340         act = ActionManager::get_action (X_("Transport"), X_("GotoEnd"));
341         goto_end_button.set_related_action (act);
342         act = ActionManager::get_action (X_("Transport"), X_("Loop"));
343         auto_loop_button.set_related_action (act);
344         act = ActionManager::get_action (X_("Transport"), X_("PlaySelection"));
345         play_selection_button.set_related_action (act);
346         act = ActionManager::get_action (X_("MIDI"), X_("panic"));
347         midi_panic_button.set_related_action (act);
348         act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
349
350         sync_button.set_related_action (act);
351         sync_button.signal_button_press_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::sync_button_clicked), false);
352
353         sync_button.set_sizing_text (S_("LogestSync|M-Clk"));
354
355         /* CANNOT sigc::bind these to clicked or toggled, must use pressed or released */
356         act = ActionManager::get_action (X_("Main"), X_("cancel-solo"));
357         solo_alert_button.set_related_action (act);
358         auditioning_alert_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::audition_alert_clicked));
359         error_alert_button.signal_button_release_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::error_alert_press), false);
360         act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
361         error_alert_button.set_related_action(act);
362         error_alert_button.set_fallthrough_to_parent(true);
363
364         layered_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::layered_button_clicked));
365
366         editor_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-editor-visibility")));
367         mixer_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-mixer-visibility")));
368         prefs_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-preferences-visibility")));
369
370         act = ActionManager::get_action ("Transport", "ToggleAutoReturn");
371         auto_return_button.set_related_action (act);
372         act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
373         follow_edits_button.set_related_action (act);
374         act = ActionManager::get_action ("Transport", "ToggleAutoInput");
375         auto_input_button.set_related_action (act);
376
377         act = ActionManager::get_action ("Transport", "TogglePunchIn");
378         punch_in_button.set_related_action (act);
379         act = ActionManager::get_action ("Transport", "TogglePunchOut");
380         punch_out_button.set_related_action (act);
381
382         act = ActionManager::get_action ("Transport", "SessionMonitorIn");
383         monitor_in_button.set_related_action (act);
384         act = ActionManager::get_action ("Transport", "SessionMonitorDisk");
385         monitor_disk_button.set_related_action (act);
386
387         /* connect signals */
388         ARDOUR_UI::Clock.connect (sigc::mem_fun (primary_clock, &AudioClock::set));
389         ARDOUR_UI::Clock.connect (sigc::mem_fun (secondary_clock, &AudioClock::set));
390
391         primary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::primary_clock_value_changed));
392         secondary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::secondary_clock_value_changed));
393         big_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::big_clock_value_changed));
394
395         editor_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), editor));
396         mixer_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), mixer));
397         prefs_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), rc_option_editor));
398
399         /* catch context clicks so that we can show a menu on these buttons */
400
401         editor_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("editor")), false);
402         mixer_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("mixer")), false);
403         prefs_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("preferences")), false);
404
405         /* setup widget style/name */
406
407         auto_return_button.set_name ("transport option button");
408         follow_edits_button.set_name ("transport option button");
409
410         solo_alert_button.set_name ("rude solo");
411         auditioning_alert_button.set_name ("rude audition");
412         feedback_alert_button.set_name ("feedback alert");
413         error_alert_button.set_name ("error alert");
414
415         solo_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
416         auditioning_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
417         feedback_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
418
419         solo_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
420         auditioning_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
421         feedback_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
422
423         editor_visibility_button.set_name (X_("page switch button"));
424         mixer_visibility_button.set_name (X_("page switch button"));
425         prefs_visibility_button.set_name (X_("page switch button"));
426
427         punch_in_button.set_name ("punch button");
428         punch_out_button.set_name ("punch button");
429         layered_button.set_name (("layered button"));
430
431         monitor_in_button.set_name ("punch button"); // XXX
432         monitor_disk_button.set_name ("punch button"); // XXX
433         auto_input_button.set_name ("transport option button");
434
435         click_button.set_name ("transport button");
436         sync_button.set_name ("transport active option button");
437
438         /* and widget text */
439         auto_return_button.set_text(_("Auto Return"));
440         follow_edits_button.set_text(_("Follow Range"));
441         punch_in_button.set_text (_("In"));
442         punch_out_button.set_text (_("Out"));
443         layered_button.set_text (_("Non-Layered"));
444
445         monitor_in_button.set_text (_("All In"));
446         monitor_disk_button.set_text (_("All Disk"));
447         auto_input_button.set_text (_("Auto-Input"));
448
449         punch_label.set_text (_("Punch:"));
450         layered_label.set_text (_("Rec:"));
451
452         /* and tooltips */
453
454         Gtkmm2ext::UI::instance()->set_tip (editor_visibility_button,
455                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
456                                                               "To put the window back, use the Window > %1 > Attach menu action"), editor->name()));
457
458         Gtkmm2ext::UI::instance()->set_tip (mixer_visibility_button,
459                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
460                                                               "To put the window back, use the Window > %1 > Attach menu action"), mixer->name()));
461
462         Gtkmm2ext::UI::instance()->set_tip (prefs_visibility_button,
463                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
464                                                               "To put the window back, use the Window > %1 > Attach menu action"), rc_option_editor->name()));
465
466         Gtkmm2ext::UI::instance()->set_tip (punch_in_button, _("Start recording at auto-punch start"));
467         Gtkmm2ext::UI::instance()->set_tip (punch_out_button, _("Stop recording at auto-punch end"));
468
469         Gtkmm2ext::UI::instance()->set_tip (monitor_in_button, _("Force all implicit monitoed tracks to monitor input"));
470         Gtkmm2ext::UI::instance()->set_tip (monitor_disk_button, _("Force all implicit monitored tracks to disk-monitoring"));
471
472         /* setup icons */
473
474         click_button.set_icon (ArdourIcon::TransportMetronom);
475         goto_start_button.set_icon (ArdourIcon::TransportStart);
476         goto_end_button.set_icon (ArdourIcon::TransportEnd);
477         roll_button.set_icon (ArdourIcon::TransportPlay);
478         stop_button.set_icon (ArdourIcon::TransportStop);
479         play_selection_button.set_icon (ArdourIcon::TransportRange);
480         auto_loop_button.set_icon (ArdourIcon::TransportLoop);
481         rec_button.set_icon (ArdourIcon::RecButton);
482         midi_panic_button.set_icon (ArdourIcon::TransportPanic);
483
484         /* transport control size-group */
485
486         Glib::RefPtr<SizeGroup> transport_button_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
487         transport_button_size_group->add_widget (goto_start_button);
488         transport_button_size_group->add_widget (goto_end_button);
489         transport_button_size_group->add_widget (auto_loop_button);
490         transport_button_size_group->add_widget (rec_button);
491         transport_button_size_group->add_widget (play_selection_button);
492         transport_button_size_group->add_widget (roll_button);
493         transport_button_size_group->add_widget (stop_button);
494
495         Glib::RefPtr<SizeGroup> punch_button_size_group = SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
496         punch_button_size_group->add_widget (punch_in_button);
497         punch_button_size_group->add_widget (punch_out_button);
498
499         Glib::RefPtr<SizeGroup> monitor_button_size_group = SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
500         monitor_button_size_group->add_widget (monitor_in_button);
501         monitor_button_size_group->add_widget (monitor_disk_button);
502
503         /* and now the layout... */
504
505         /* top level packing */
506         transport_table.set_spacings (0);
507         transport_table.set_row_spacings (4);
508         transport_table.set_border_width (2);
509
510         transport_frame.set_name ("TransportFrame");
511         transport_frame.set_shadow_type (Gtk::SHADOW_NONE);
512
513         /* An event box to hold the table. We use this because we want specific
514            control over the background color, and without this event box,
515            nothing inside the transport_frame actually draws a background. We
516            would therefore end up seeing the background of the parent widget,
517            which is probably some default color. Adding the EventBox adds a
518            widget that will draw the background, using a style based on 
519            the parent, "TransportFrame".
520         */
521         Gtk::EventBox* ebox = manage (new Gtk::EventBox);
522         transport_frame.add (*ebox);
523         ebox->add (transport_table);
524
525         transport_table.signal_expose_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::transport_expose), false);
526
527         /* transport controls sub-group */
528         click_button.set_size_request (PX_SCALE(20), PX_SCALE(20));
529
530         HBox* tbox = manage (new HBox);
531         tbox->set_spacing (PX_SCALE(2));
532
533         tbox->pack_start (midi_panic_button, true, true, 0);
534         tbox->pack_start (click_button, true, true, 0);
535         tbox->pack_start (goto_start_button, true, true);
536         tbox->pack_start (goto_end_button, true, true);
537         tbox->pack_start (auto_loop_button, true, true);
538         tbox->pack_start (play_selection_button, true, true);
539
540         tbox->pack_start (roll_button, true, true);
541         tbox->pack_start (stop_button, true, true);
542         tbox->pack_start (rec_button, true, true, 3);
543
544         /* alert box sub-group */
545         VBox* alert_box = manage (new VBox);
546         alert_box->set_homogeneous (true);
547         alert_box->set_spacing (1);
548         alert_box->set_border_width (0);
549         alert_box->pack_start (solo_alert_button, true, false, 0);
550         alert_box->pack_start (auditioning_alert_button, true, false, 0);
551         alert_box->pack_start (feedback_alert_button, true, false, 0);
552
553         /* clock button size groups */
554         Glib::RefPtr<SizeGroup> button_height_size_group = SizeGroup::create (Gtk::SIZE_GROUP_VERTICAL);
555         button_height_size_group->add_widget (follow_edits_button);
556         button_height_size_group->add_widget (*primary_clock->left_btn());
557         button_height_size_group->add_widget (*primary_clock->right_btn());
558         button_height_size_group->add_widget (*secondary_clock->left_btn());
559         button_height_size_group->add_widget (*secondary_clock->right_btn());
560
561         button_height_size_group->add_widget (stop_button);
562 //      button_height_size_group->add_widget (sync_button);
563 //      button_height_size_group->add_widget (layered_button);
564         button_height_size_group->add_widget (auto_return_button);
565         button_height_size_group->add_widget (editor_visibility_button);
566         button_height_size_group->add_widget (mixer_visibility_button);
567
568         Glib::RefPtr<SizeGroup> clock1_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
569         clock1_size_group->add_widget (*primary_clock->left_btn());
570         clock1_size_group->add_widget (*primary_clock->right_btn());
571
572         Glib::RefPtr<SizeGroup> clock2_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
573         clock2_size_group->add_widget (*secondary_clock->left_btn());
574         clock2_size_group->add_widget (*secondary_clock->right_btn());
575
576         /* sub-layout for Sync | Shuttle (grow) */
577         HBox* ssbox = manage (new HBox);
578         ssbox->set_spacing (PX_SCALE(2));
579         ssbox->pack_start (sync_button, false, false, 0);
580         ssbox->pack_start (shuttle_box, true, true, 0);
581         ssbox->pack_start (*shuttle_box.info_button(), false, false, 0);
582
583
584         /* and the main table layout */
585
586         int col = 0;
587 #define TCOL col, col + 1
588
589         transport_table.attach (*tbox, TCOL, 0, 1 , SHRINK, SHRINK, 0, 0);
590         transport_table.attach (*ssbox, TCOL, 1, 2 , FILL, SHRINK, 0, 0);
591         ++col;
592
593         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
594         ++col;
595
596         transport_table.attach (punch_label, TCOL, 0, 1 , FILL, SHRINK, 3, 0);
597         transport_table.attach (layered_label, TCOL, 1, 2 , FILL, SHRINK, 3, 0);
598         ++col;
599
600         transport_table.attach (punch_in_button,  col,      col + 1, 0, 1 , FILL, SHRINK, 0, 2);
601         transport_table.attach (punch_space,      col + 1,  col + 2, 0, 1 , FILL, SHRINK, 2, 2);
602         transport_table.attach (punch_out_button, col + 2,  col + 3, 0, 1 , FILL, SHRINK, 0, 2);
603         transport_table.attach (layered_button,   col,      col + 3, 1, 2 , FILL, SHRINK, 0, 2);
604         col += 3;
605
606         transport_table.attach (recpunch_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
607         ++col;
608
609         transport_table.attach (monitor_in_button,   col,     col + 1, 0, 1 , FILL, SHRINK, 0, 2);
610         transport_table.attach (mon_space,           col + 1, col + 2, 0, 1 , FILL, SHRINK, 2, 2);
611         transport_table.attach (monitor_disk_button, col + 2, col + 3, 0, 1 , FILL, SHRINK, 0, 2);
612         transport_table.attach (auto_input_button,   col,     col + 3, 1, 2 , FILL, SHRINK, 0, 2);
613         col += 3;
614
615         transport_table.attach (monitoring_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
616         ++col;
617
618         transport_table.attach (follow_edits_button, TCOL, 0, 1 , FILL, SHRINK, 2, 0);
619         transport_table.attach (auto_return_button,  TCOL, 1, 2 , FILL, SHRINK, 2, 0);
620         ++col;
621
622         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
623         ++col;
624
625         transport_table.attach (*primary_clock,              col,     col + 2, 0, 1 , FILL, SHRINK, 2, 0);
626         transport_table.attach (*primary_clock->left_btn(),  col,     col + 1, 1, 2 , FILL, SHRINK, 2, 0);
627         transport_table.attach (*primary_clock->right_btn(), col + 1, col + 2, 1, 2 , FILL, SHRINK, 2, 0);
628         col += 2;
629
630         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
631         ++col;
632
633         if (!ARDOUR::Profile->get_small_screen()) {
634                 transport_table.attach (*secondary_clock,              col,     col + 2, 0, 1 , FILL, SHRINK, 2, 0);
635                 transport_table.attach (*secondary_clock->left_btn(),  col,     col + 1, 1, 2 , FILL, SHRINK, 2, 0);
636                 transport_table.attach (*secondary_clock->right_btn(), col + 1, col + 2, 1, 2 , FILL, SHRINK, 2, 0);
637                 secondary_clock->set_no_show_all (true);
638                 secondary_clock->left_btn()->set_no_show_all (true);
639                 secondary_clock->right_btn()->set_no_show_all (true);
640                 col += 2;
641
642                 secondary_clock_spacer = manage (new ArdourVSpacer ());
643                 transport_table.attach (*secondary_clock_spacer, TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
644                 ++col;
645         }
646
647         transport_table.attach (*alert_box, TCOL, 0, 2, SHRINK, EXPAND|FILL, 2, 0);
648         ++col;
649
650         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
651         ++col;
652
653         /* editor-meter, mini-timeline and selection clock are options in the transport_hbox */
654         transport_hbox.set_spacing (3);
655         transport_table.attach (transport_hbox, TCOL, 0, 2, EXPAND|FILL, EXPAND|FILL, 2, 0);
656         ++col;
657
658         /* lua script action buttons */
659         transport_table.attach (action_script_table, TCOL, 0, 2, SHRINK, EXPAND|FILL, 1, 0);
660         ++col;
661
662         transport_table.attach (editor_visibility_button, TCOL, 0, 1 , FILL, SHRINK, 2, 0);
663         transport_table.attach (mixer_visibility_button,  TCOL, 1, 2 , FILL, SHRINK, 2, 0);
664         ++col;
665
666         repack_transport_hbox ();
667         update_clock_visibility ();
668         /* desensitize */
669
670         feedback_alert_button.set_sensitive (false);
671         feedback_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
672         auditioning_alert_button.set_sensitive (false);
673         auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
674
675         stop_button.set_active (true);
676         set_transport_sensitivity (false);
677 }
678 #undef PX_SCALE
679 #undef TCOL
680
681 void
682 ARDOUR_UI::soloing_changed (bool onoff)
683 {
684         if (solo_alert_button.get_active() != onoff) {
685                 solo_alert_button.set_active (onoff);
686         }
687 }
688
689 void
690 ARDOUR_UI::_auditioning_changed (bool onoff)
691 {
692         auditioning_alert_button.set_active (onoff);
693         auditioning_alert_button.set_sensitive (onoff);
694         if (!onoff) {
695                 auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
696         }
697         set_transport_sensitivity (!onoff);
698 }
699
700 void
701 ARDOUR_UI::auditioning_changed (bool onoff)
702 {
703         UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::_auditioning_changed, this, onoff));
704 }
705
706 void
707 ARDOUR_UI::audition_alert_clicked ()
708 {
709         if (_session) {
710                 _session->cancel_audition();
711         }
712 }
713
714 bool
715 ARDOUR_UI::error_alert_press (GdkEventButton* ev)
716 {
717         bool do_toggle = true;
718         if (ev->button == 1) {
719                 if (_log_not_acknowledged == LogLevelError) {
720                         // just acknowledge the error, don't hide the log if it's already visible
721                         RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
722                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
723                         if (tact && tact->get_active()) {
724                                 do_toggle = false;
725                         }
726                 }
727                 _log_not_acknowledged = LogLevelNone;
728                 error_blink (false); // immediate acknowledge
729         }
730         // maybe fall through to to button toggle
731         return !do_toggle;
732 }
733
734 void
735 ARDOUR_UI::layered_button_clicked ()
736 {
737         if (_session) {
738                 _session->config.set_layered_record_mode (!_session->config.get_layered_record_mode ());
739         }
740 }
741
742 void
743 ARDOUR_UI::solo_blink (bool onoff)
744 {
745         if (_session == 0) {
746                 return;
747         }
748
749         if (_session->soloing() || _session->listening()) {
750                 if (onoff) {
751                         solo_alert_button.set_active (true);
752                 } else {
753                         solo_alert_button.set_active (false);
754                 }
755         } else {
756                 solo_alert_button.set_active (false);
757         }
758 }
759
760 void
761 ARDOUR_UI::sync_blink (bool onoff)
762 {
763         if (_session == 0 || !_session->config.get_external_sync()) {
764                 /* internal sync */
765                 sync_button.set_active (false);
766                 return;
767         }
768
769         if (!_session->transport_locked()) {
770                 /* not locked, so blink on and off according to the onoff argument */
771
772                 if (onoff) {
773                         sync_button.set_active (true);
774                 } else {
775                         sync_button.set_active (false);
776                 }
777         } else {
778                 /* locked */
779                 sync_button.set_active (true);
780         }
781 }
782
783 void
784 ARDOUR_UI::audition_blink (bool onoff)
785 {
786         if (_session == 0) {
787                 return;
788         }
789
790         if (_session->is_auditioning()) {
791                 if (onoff) {
792                         auditioning_alert_button.set_active (true);
793                 } else {
794                         auditioning_alert_button.set_active (false);
795                 }
796         } else {
797                 auditioning_alert_button.set_active (false);
798         }
799 }
800
801 void
802 ARDOUR_UI::feedback_blink (bool onoff)
803 {
804         if (_feedback_exists) {
805                 if (onoff) {
806                         feedback_alert_button.set_active (true);
807                 } else {
808                         feedback_alert_button.set_active (false);
809                 }
810         } else {
811                 feedback_alert_button.set_active (false);
812         }
813 }
814
815 void
816 ARDOUR_UI::error_blink (bool onoff)
817 {
818         switch (_log_not_acknowledged) {
819                 case LogLevelError:
820                         // blink
821                         if (onoff) {
822                                 error_alert_button.set_custom_led_color(0xff0000ff); // bright red
823                         } else {
824                                 error_alert_button.set_custom_led_color(0x880000ff); // dark red
825                         }
826                         break;
827                 case LogLevelWarning:
828                         error_alert_button.set_custom_led_color(0xccaa00ff); // yellow
829                         break;
830                 case LogLevelInfo:
831                         error_alert_button.set_custom_led_color(0x88cc00ff); // lime green
832                         break;
833                 default:
834                         error_alert_button.set_custom_led_color(0x333333ff); // gray
835                         break;
836         }
837 }
838
839
840
841 void
842 ARDOUR_UI::set_transport_sensitivity (bool yn)
843 {
844         ActionManager::set_sensitive (ActionManager::transport_sensitive_actions, yn);
845         shuttle_box.set_sensitive (yn);
846 }
847
848 void
849 ARDOUR_UI::editor_realized ()
850 {
851         boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
852         Config->map_parameters (pc);
853
854         UIConfiguration::instance().reset_dpi ();
855 }
856
857 void
858 ARDOUR_UI::maximise_editing_space ()
859 {
860         if (editor) {
861                 editor->maximise_editing_space ();
862         }
863 }
864
865 void
866 ARDOUR_UI::restore_editing_space ()
867 {
868         if (editor) {
869                 editor->restore_editing_space ();
870         }
871 }
872
873 void
874 ARDOUR_UI::show_ui_prefs ()
875 {
876         if (rc_option_editor) {
877                 show_tabbable (rc_option_editor);
878                 rc_option_editor->set_current_page (_("Appearance"));
879         }
880 }
881
882 bool
883 ARDOUR_UI::click_button_clicked (GdkEventButton* ev)
884 {
885         if (ev->button != 3) {
886                 /* this handler is just for button-3 clicks */
887                 return false;
888         }
889
890         show_tabbable (rc_option_editor);
891         rc_option_editor->set_current_page (_("Metronome"));
892         return true;
893 }
894
895 bool
896 ARDOUR_UI::sync_button_clicked (GdkEventButton* ev)
897 {
898         if (ev->button != 3) {
899                 /* this handler is just for button-3 clicks */
900                 return false;
901         }
902
903         show_tabbable (rc_option_editor);
904         rc_option_editor->set_current_page (_("Sync"));
905         return true;
906 }
907
908 void
909 ARDOUR_UI::toggle_follow_edits ()
910 {
911         RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
912         assert (act);
913
914         RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
915         assert (tact);
916
917         UIConfiguration::instance().set_follow_edits (tact->get_active ());
918 }
919
920 void
921 ARDOUR_UI::update_title ()
922 {
923         if (_session) {
924                 bool dirty = _session->dirty();
925
926                 string session_name;
927
928                 if (_session->snap_name() != _session->name()) {
929                         session_name = _session->snap_name();
930                 } else {
931                         session_name = _session->name();
932                 }
933
934                 if (dirty) {
935                         session_name = "*" + session_name;
936                 }
937
938                 WindowTitle title (session_name);
939                 title += Glib::get_application_name();
940                 _main_window.set_title (title.get_string());
941         } else {
942                 WindowTitle title (Glib::get_application_name());
943                 _main_window.set_title (title.get_string());
944         }
945
946 }