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