Follow Edits => Follow Range
[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 "theme_manager.h"
57 #include "midi_tracer.h"
58 #include "mini_timeline.h"
59 #include "shuttle_control.h"
60 #include "global_port_matrix.h"
61 #include "location_ui.h"
62 #include "rc_option_editor.h"
63
64 #include "pbd/i18n.h"
65
66 using namespace std;
67 using namespace ARDOUR;
68 using namespace PBD;
69 using namespace Gtkmm2ext;
70 using namespace Gtk;
71 using namespace Glib;
72 using namespace ARDOUR_UI_UTILS;
73
74 void
75 ARDOUR_UI::setup_tooltips ()
76 {
77         ArdourCanvas::Canvas::set_tooltip_timeout (Gtk::Settings::get_default()->property_gtk_tooltip_timeout ());
78
79         set_tip (roll_button, _("Play from playhead"));
80         set_tip (stop_button, _("Stop playback"));
81         set_tip (rec_button, _("Toggle record"));
82         set_tip (play_selection_button, _("Play range/selection"));
83         set_tip (goto_start_button, _("Go to start of session"));
84         set_tip (goto_end_button, _("Go to end of session"));
85         set_tip (auto_loop_button, _("Play loop range"));
86         set_tip (midi_panic_button, _("MIDI Panic\nSend note off and reset controller messages on all MIDI channels"));
87         set_tip (auto_return_button, _("Return to last playback start when stopped"));
88         set_tip (follow_edits_button, _("Playhead follows Range tool clicks, and Range selections"));
89         set_tip (auto_input_button, _("Be sensible about input monitoring"));
90         set_tip (click_button, _("Enable/Disable audio click"));
91         set_tip (solo_alert_button, _("When active, something is soloed.\nClick to de-solo everything"));
92         set_tip (auditioning_alert_button, _("When active, auditioning is taking place.\nClick to stop the audition"));
93         set_tip (feedback_alert_button, _("When active, there is a feedback loop."));
94         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"));
95         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"));
96         set_tip (editor_meter_peak_display, _("Reset All Peak Indicators"));
97         set_tip (error_alert_button, _("Show Error Log and acknowledge warnings"));
98
99         synchronize_sync_source_and_video_pullup ();
100
101         editor->setup_tooltips ();
102 }
103
104 bool
105 ARDOUR_UI::status_bar_button_press (GdkEventButton* ev)
106 {
107         bool handled = false;
108
109         switch (ev->button) {
110         case 1:
111                 status_bar_label.set_text ("");
112                 handled = true;
113                 break;
114         default:
115                 break;
116         }
117
118         return handled;
119 }
120
121 void
122 ARDOUR_UI::display_message (const char *prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
123 {
124         string text;
125
126         UI::display_message (prefix, prefix_len, ptag, mtag, msg);
127
128         ArdourLogLevel ll = LogLevelNone;
129
130         if (strcmp (prefix, _("[ERROR]: ")) == 0) {
131                 text = "<span color=\"red\" weight=\"bold\">";
132                 ll = LogLevelError;
133         } else if (strcmp (prefix, _("[WARNING]: ")) == 0) {
134                 text = "<span color=\"yellow\" weight=\"bold\">";
135                 ll = LogLevelWarning;
136         } else if (strcmp (prefix, _("[INFO]: ")) == 0) {
137                 text = "<span color=\"green\" weight=\"bold\">";
138                 ll = LogLevelInfo;
139         } else {
140                 text = "<span color=\"white\" weight=\"bold\">???";
141         }
142
143         _log_not_acknowledged = std::max(_log_not_acknowledged, ll);
144
145 #ifdef TOP_MENUBAR
146         text += prefix;
147         text += "</span>";
148         text += msg;
149
150         status_bar_label.set_markup (text);
151 #endif
152 }
153
154 XMLNode*
155 ARDOUR_UI::tearoff_settings (const char* name) const
156 {
157         XMLNode* ui_node = Config->extra_xml(X_("UI"));
158
159         if (ui_node) {
160                 XMLNode* tearoff_node = ui_node->child (X_("Tearoffs"));
161                 if (tearoff_node) {
162                         XMLNode* mnode = tearoff_node->child (name);
163                         return mnode;
164                 }
165         }
166
167         return 0;
168 }
169
170 #define PX_SCALE(px) std::max((float)px, rintf((float)px * UIConfiguration::instance().get_ui_scale()))
171
172 static
173 bool drag_failed (const Glib::RefPtr<Gdk::DragContext>& context, DragResult result, Tabbable* tab)
174 {
175         if (result == Gtk::DRAG_RESULT_NO_TARGET) {
176                 tab->detach ();
177                 return true;
178         }
179         return false;
180 }
181
182 bool
183 ARDOUR_UI::transport_expose (GdkEventExpose* ev)
184 {
185 return false;
186         int x0, y0;
187         Gtk::Widget* window_parent;
188         Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (transport_table, &window_parent);
189         Glib::RefPtr<Gtk::Style> style = transport_table.get_style();
190         if (!win || !style) {
191                 return false;
192         }
193
194         Cairo::RefPtr<Cairo::Context> cr = transport_table.get_window()->create_cairo_context ();
195
196         cr->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
197         cr->clip ();
198
199         transport_table.translate_coordinates (*window_parent, 0, 0, x0, y0);
200
201         cr->rectangle (x0, y0, transport_table.get_width(), transport_table.get_height());
202         Gdk::Color bg (style->get_bg (transport_table.get_state()));
203         cr->set_source_rgb (bg.get_red_p(), bg.get_green_p(), bg.get_blue_p());
204         cr->fill ();
205
206         static const int xmargin = 2;
207         static const int ymargin = 1;
208
209         /* draw box around record-options */
210         int xx, ww, hh, uu;
211
212         punch_label.translate_coordinates (transport_table, -xmargin, 0, xx, uu); // left
213         punch_out_button.translate_coordinates (transport_table, xmargin, 0, ww, uu); // right
214         ww += punch_out_button.get_width () - xx; // width
215         hh = transport_table.get_height() - 1;
216
217         Gtkmm2ext::rounded_rectangle (cr->cobj(), x0 + xx - 0.5, y0 + 0.5, ww + 1, hh, 6);
218         cr->set_source_rgb (0, 0, 0);
219         cr->set_line_width (1.0);
220         cr->stroke ();
221
222         /* line to rec-enable */
223         int rx;
224         rec_button.translate_coordinates (transport_table, -xmargin, 0, rx, uu); // top
225         int dx = rx + rec_button.get_width() - xx;
226
227         cr->move_to (x0 + xx, 1.5 + y0 + ymargin + round (punch_in_button.get_height () * .5));
228         cr->rel_line_to (dx, 0);
229         cr->set_line_width (2.0);
230         cr->stroke ();
231
232         return false;
233 }
234
235 void
236 ARDOUR_UI::setup_transport ()
237 {
238         RefPtr<Action> act;
239         /* setup actions */
240
241         act = ActionManager::get_action ("Transport", "ToggleClick");
242         click_button.set_related_action (act);
243         click_button.signal_button_press_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::click_button_clicked), false);
244
245         act = ActionManager::get_action (X_("Transport"), X_("Stop"));
246         stop_button.set_related_action (act);
247         act = ActionManager::get_action (X_("Transport"), X_("Roll"));
248         roll_button.set_related_action (act);
249         act = ActionManager::get_action (X_("Transport"), X_("Record"));
250         rec_button.set_related_action (act);
251         act = ActionManager::get_action (X_("Transport"), X_("GotoStart"));
252         goto_start_button.set_related_action (act);
253         act = ActionManager::get_action (X_("Transport"), X_("GotoEnd"));
254         goto_end_button.set_related_action (act);
255         act = ActionManager::get_action (X_("Transport"), X_("Loop"));
256         auto_loop_button.set_related_action (act);
257         act = ActionManager::get_action (X_("Transport"), X_("PlaySelection"));
258         play_selection_button.set_related_action (act);
259         act = ActionManager::get_action (X_("MIDI"), X_("panic"));
260         midi_panic_button.set_related_action (act);
261         act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
262
263         sync_button.set_related_action (act);
264         sync_button.signal_button_press_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::sync_button_clicked), false);
265
266         sync_button.set_sizing_text (S_("LogestSync|M-Clk"));
267
268         /* CANNOT sigc::bind these to clicked or toggled, must use pressed or released */
269         act = ActionManager::get_action (X_("Main"), X_("cancel-solo"));
270         solo_alert_button.set_related_action (act);
271         auditioning_alert_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::audition_alert_clicked));
272         error_alert_button.signal_button_release_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::error_alert_press), false);
273         act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
274         error_alert_button.set_related_action(act);
275         error_alert_button.set_fallthrough_to_parent(true);
276
277         layered_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::layered_button_clicked));
278
279         editor_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-editor-visibility")));
280         mixer_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-mixer-visibility")));
281         prefs_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-preferences-visibility")));
282
283         act = ActionManager::get_action ("Transport", "ToggleAutoReturn");
284         auto_return_button.set_related_action (act);
285         act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
286         follow_edits_button.set_related_action (act);
287         act = ActionManager::get_action ("Transport", "ToggleAutoInput");
288         auto_input_button.set_related_action (act);
289
290         act = ActionManager::get_action ("Transport", "TogglePunchIn");
291         punch_in_button.set_related_action (act);
292         act = ActionManager::get_action ("Transport", "TogglePunchOut");
293         punch_out_button.set_related_action (act);
294
295         /* connect signals */
296         ARDOUR_UI::Clock.connect (sigc::mem_fun (primary_clock, &AudioClock::set));
297         ARDOUR_UI::Clock.connect (sigc::mem_fun (secondary_clock, &AudioClock::set));
298
299         primary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::primary_clock_value_changed));
300         secondary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::secondary_clock_value_changed));
301         big_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::big_clock_value_changed));
302
303         editor_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), editor));
304         mixer_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), mixer));
305         prefs_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), rc_option_editor));
306
307         /* catch context clicks so that we can show a menu on these buttons */
308
309         editor_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("editor")), false);
310         mixer_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("mixer")), false);
311         prefs_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("preferences")), false);
312
313         /* setup widget style/name */
314
315         auto_return_button.set_name ("transport option button");
316         follow_edits_button.set_name ("transport option button");
317         auto_input_button.set_name ("transport option button");
318
319         solo_alert_button.set_name ("rude solo");
320         auditioning_alert_button.set_name ("rude audition");
321         feedback_alert_button.set_name ("feedback alert");
322         error_alert_button.set_name ("error alert");
323
324         solo_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
325         auditioning_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
326         feedback_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
327
328         solo_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
329         auditioning_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
330         feedback_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
331
332         editor_visibility_button.set_name (X_("page switch button"));
333         mixer_visibility_button.set_name (X_("page switch button"));
334         prefs_visibility_button.set_name (X_("page switch button"));
335
336         punch_in_button.set_name ("punch button");
337         punch_out_button.set_name ("punch button");
338         layered_button.set_name (("layered button"));
339
340         click_button.set_name ("transport button");
341         sync_button.set_name ("transport active option button");
342
343         /* and widget text */
344         auto_return_button.set_text(_("Auto Return"));
345         follow_edits_button.set_text(_("Follow Range"));
346         //auto_input_button.set_text (_("Auto Input"));
347         punch_in_button.set_text (_("In"));
348         punch_out_button.set_text (_("Out"));
349         layered_button.set_text (_("Non-Layered"));
350
351         punch_label.set_text (_("Punch:"));
352         layered_label.set_text (_("Rec:"));
353
354         /* and tooltips */
355
356         Gtkmm2ext::UI::instance()->set_tip (editor_visibility_button,
357                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
358                                                               "To put the window back, use the Window > %1 > Attach menu action"), editor->name()));
359
360         Gtkmm2ext::UI::instance()->set_tip (mixer_visibility_button,
361                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
362                                                               "To put the window back, use the Window > %1 > Attach menu action"), mixer->name()));
363
364         Gtkmm2ext::UI::instance()->set_tip (prefs_visibility_button,
365                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
366                                                               "To put the window back, use the Window > %1 > Attach menu action"), rc_option_editor->name()));
367
368         Gtkmm2ext::UI::instance()->set_tip (punch_in_button, _("Start recording at auto-punch start"));
369         Gtkmm2ext::UI::instance()->set_tip (punch_out_button, _("Stop recording at auto-punch end"));
370
371         /* setup icons */
372
373         click_button.set_icon (ArdourIcon::TransportMetronom);
374         goto_start_button.set_icon (ArdourIcon::TransportStart);
375         goto_end_button.set_icon (ArdourIcon::TransportEnd);
376         roll_button.set_icon (ArdourIcon::TransportPlay);
377         stop_button.set_icon (ArdourIcon::TransportStop);
378         play_selection_button.set_icon (ArdourIcon::TransportRange);
379         auto_loop_button.set_icon (ArdourIcon::TransportLoop);
380         rec_button.set_icon (ArdourIcon::RecButton);
381         midi_panic_button.set_icon (ArdourIcon::TransportPanic);
382
383         /* transport control size-group */
384
385         Glib::RefPtr<SizeGroup> transport_button_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
386         transport_button_size_group->add_widget (goto_start_button);
387         transport_button_size_group->add_widget (goto_end_button);
388         transport_button_size_group->add_widget (auto_loop_button);
389         transport_button_size_group->add_widget (rec_button);
390         transport_button_size_group->add_widget (play_selection_button);
391         transport_button_size_group->add_widget (roll_button);
392         transport_button_size_group->add_widget (stop_button);
393
394         Glib::RefPtr<SizeGroup> punch_button_size_group = SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
395         punch_button_size_group->add_widget (punch_in_button);
396         punch_button_size_group->add_widget (punch_out_button);
397
398         shuttle_box = manage (new ShuttleControl);
399         mini_timeline = manage (new MiniTimeline);
400
401         /* and now the layout... */
402
403         /* top level packing */
404         transport_table.set_spacings (0);
405         transport_table.set_row_spacings (4);
406         transport_table.set_border_width (2);
407         transport_frame.add (transport_table);
408         transport_frame.set_name ("BaseFrame");
409         transport_frame.set_shadow_type (Gtk::SHADOW_NONE);
410
411         transport_table.signal_expose_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::transport_expose), false);
412
413         /* transport controls sub-group */
414         click_button.set_size_request (PX_SCALE(20), PX_SCALE(20));
415
416         HBox* tbox = manage (new HBox);
417         tbox->set_spacing (PX_SCALE(2));
418
419         tbox->pack_start (midi_panic_button, true, true, 0);
420         tbox->pack_start (click_button, true, true, 0);
421         tbox->pack_start (goto_start_button, true, true);
422         tbox->pack_start (goto_end_button, true, true);
423         tbox->pack_start (auto_loop_button, true, true);
424         tbox->pack_start (play_selection_button, true, true);
425
426         tbox->pack_start (roll_button, true, true);
427         tbox->pack_start (stop_button, true, true);
428         tbox->pack_start (rec_button, true, true, 3);
429
430         /* alert box sub-group */
431         VBox* alert_box = manage (new VBox);
432         alert_box->set_homogeneous (true);
433         alert_box->set_spacing (1);
434         alert_box->set_border_width (0);
435         alert_box->pack_start (solo_alert_button, true, false, 0);
436         alert_box->pack_start (auditioning_alert_button, true, false, 0);
437         alert_box->pack_start (feedback_alert_button, true, false, 0);
438
439         /* clock button size groups */
440         Glib::RefPtr<SizeGroup> button_height_size_group = SizeGroup::create (Gtk::SIZE_GROUP_VERTICAL);
441         button_height_size_group->add_widget (follow_edits_button);
442         button_height_size_group->add_widget (*primary_clock->left_btn());
443         button_height_size_group->add_widget (*primary_clock->right_btn());
444         button_height_size_group->add_widget (*secondary_clock->left_btn());
445         button_height_size_group->add_widget (*secondary_clock->right_btn());
446
447         button_height_size_group->add_widget (stop_button);
448 //      button_height_size_group->add_widget (sync_button);
449 //      button_height_size_group->add_widget (layered_button);
450         button_height_size_group->add_widget (auto_return_button);
451         button_height_size_group->add_widget (editor_visibility_button);
452         button_height_size_group->add_widget (mixer_visibility_button);
453
454         Glib::RefPtr<SizeGroup> clock1_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
455         clock1_size_group->add_widget (*primary_clock->left_btn());
456         clock1_size_group->add_widget (*primary_clock->right_btn());
457
458         Glib::RefPtr<SizeGroup> clock2_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
459         clock2_size_group->add_widget (*secondary_clock->left_btn());
460         clock2_size_group->add_widget (*secondary_clock->right_btn());
461
462         /* sub-layout for Sync | Shuttle (grow) */
463         HBox* ssbox = manage (new HBox);
464         ssbox->set_spacing (PX_SCALE(2));
465         ssbox->pack_start (sync_button, false, false, 0);
466         ssbox->pack_start (*shuttle_box, true, true, 3);
467
468
469         /* and the main table layout */
470
471         int col = 0;
472 #define TCOL col, col + 1
473
474         transport_table.attach (*tbox, TCOL, 0, 1 , SHRINK, SHRINK, 0, 0);
475         transport_table.attach (*ssbox, TCOL, 1, 2 , FILL, SHRINK, 0, 0);
476         ++col;
477
478         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
479         ++col;
480
481         transport_table.attach (punch_label, TCOL, 0, 1 , FILL, SHRINK, 3, 0);
482         transport_table.attach (layered_label, TCOL, 1, 2 , FILL, SHRINK, 3, 0);
483         ++col;
484
485         transport_table.attach (punch_in_button,  col,     col + 1, 0, 1 , FILL, SHRINK, 0, 2);
486         transport_table.attach (*(manage (new Label (""))), col + 1, col + 2, 0, 1 , FILL, SHRINK, 2, 2);
487         transport_table.attach (punch_out_button, col + 2, col + 3, 0, 1 , FILL, SHRINK, 0, 2);
488         transport_table.attach (layered_button,   col,     col + 3, 1, 2 , FILL, SHRINK, 0, 2);
489         col += 3;
490
491         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
492         ++col;
493
494         transport_table.attach (follow_edits_button, TCOL, 0, 1 , FILL, SHRINK, 2, 0);
495         transport_table.attach (auto_return_button,  TCOL, 1, 2 , FILL, SHRINK, 2, 0);
496         ++col;
497
498         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
499         ++col;
500
501         transport_table.attach (*primary_clock,              col,     col + 2, 0, 1 , FILL, SHRINK, 2, 0);
502         transport_table.attach (*primary_clock->left_btn(),  col,     col + 1, 1, 2 , FILL, SHRINK, 2, 0);
503         transport_table.attach (*primary_clock->right_btn(), col + 1, col + 2, 1, 2 , FILL, SHRINK, 2, 0);
504         col += 2;
505
506         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
507         ++col;
508
509         if (!ARDOUR::Profile->get_small_screen()) {
510                 transport_table.attach (*secondary_clock,              col,     col + 2, 0, 1 , FILL, SHRINK, 2, 0);
511                 transport_table.attach (*secondary_clock->left_btn(),  col,     col + 1, 1, 2 , FILL, SHRINK, 2, 0);
512                 transport_table.attach (*secondary_clock->right_btn(), col + 1, col + 2, 1, 2 , FILL, SHRINK, 2, 0);
513                 col += 2;
514         }
515
516         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
517         ++col;
518
519         transport_table.attach (*alert_box, TCOL, 0, 2, SHRINK, EXPAND|FILL, 2, 0);
520         ++col;
521
522         transport_table.attach (*(manage (new ArdourVSpacer ())), TCOL, 0, 2 , SHRINK, EXPAND|FILL, 3, 0);
523         ++col;
524
525         /* editor-meter is in transport_hbox */
526         transport_hbox.set_spacing (PX_SCALE(1));
527         transport_table.attach (transport_hbox, TCOL, 0, 2, SHRINK, EXPAND|FILL, 2, 0);
528         ++col;
529
530         transport_table.attach (*mini_timeline, TCOL, 0, 2, EXPAND|FILL, EXPAND|FILL, 1, 0);
531         ++col;
532
533         /* lua script action buttons */
534         transport_table.attach (action_script_table, TCOL, 0, 2, SHRINK, EXPAND|FILL, 1, 0);
535         ++col;
536
537         transport_table.attach (editor_visibility_button, TCOL, 0, 1 , FILL, SHRINK, 2, 0);
538         transport_table.attach (mixer_visibility_button,  TCOL, 1, 2 , FILL, SHRINK, 2, 0);
539         ++col;
540
541         /* desensitize */
542
543         feedback_alert_button.set_sensitive (false);
544         feedback_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
545         auditioning_alert_button.set_sensitive (false);
546         auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
547
548         stop_button.set_active (true);
549         set_transport_sensitivity (false);
550 }
551 #undef PX_SCALE
552 #undef TCOL
553
554 void
555 ARDOUR_UI::soloing_changed (bool onoff)
556 {
557         if (solo_alert_button.get_active() != onoff) {
558                 solo_alert_button.set_active (onoff);
559         }
560 }
561
562 void
563 ARDOUR_UI::_auditioning_changed (bool onoff)
564 {
565         auditioning_alert_button.set_active (onoff);
566         auditioning_alert_button.set_sensitive (onoff);
567         if (!onoff) {
568                 auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
569         }
570         set_transport_sensitivity (!onoff);
571 }
572
573 void
574 ARDOUR_UI::auditioning_changed (bool onoff)
575 {
576         UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::_auditioning_changed, this, onoff));
577 }
578
579 void
580 ARDOUR_UI::audition_alert_clicked ()
581 {
582         if (_session) {
583                 _session->cancel_audition();
584         }
585 }
586
587 bool
588 ARDOUR_UI::error_alert_press (GdkEventButton* ev)
589 {
590         bool do_toggle = true;
591         if (ev->button == 1) {
592                 if (_log_not_acknowledged == LogLevelError) {
593                         // just acknowledge the error, don't hide the log if it's already visible
594                         RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
595                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
596                         if (tact && tact->get_active()) {
597                                 do_toggle = false;
598                         }
599                 }
600                 _log_not_acknowledged = LogLevelNone;
601                 error_blink (false); // immediate acknowledge
602         }
603         // maybe fall through to to button toggle
604         return !do_toggle;
605 }
606
607 void
608 ARDOUR_UI::layered_button_clicked ()
609 {
610         if (_session) {
611                 _session->config.set_layered_record_mode (!_session->config.get_layered_record_mode ());
612         }
613 }
614
615 void
616 ARDOUR_UI::solo_blink (bool onoff)
617 {
618         if (_session == 0) {
619                 return;
620         }
621
622         if (_session->soloing() || _session->listening()) {
623                 if (onoff) {
624                         solo_alert_button.set_active (true);
625                 } else {
626                         solo_alert_button.set_active (false);
627                 }
628         } else {
629                 solo_alert_button.set_active (false);
630         }
631 }
632
633 void
634 ARDOUR_UI::sync_blink (bool onoff)
635 {
636         if (_session == 0 || !_session->config.get_external_sync()) {
637                 /* internal sync */
638                 sync_button.set_active (false);
639                 return;
640         }
641
642         if (!_session->transport_locked()) {
643                 /* not locked, so blink on and off according to the onoff argument */
644
645                 if (onoff) {
646                         sync_button.set_active (true);
647                 } else {
648                         sync_button.set_active (false);
649                 }
650         } else {
651                 /* locked */
652                 sync_button.set_active (true);
653         }
654 }
655
656 void
657 ARDOUR_UI::audition_blink (bool onoff)
658 {
659         if (_session == 0) {
660                 return;
661         }
662
663         if (_session->is_auditioning()) {
664                 if (onoff) {
665                         auditioning_alert_button.set_active (true);
666                 } else {
667                         auditioning_alert_button.set_active (false);
668                 }
669         } else {
670                 auditioning_alert_button.set_active (false);
671         }
672 }
673
674 void
675 ARDOUR_UI::feedback_blink (bool onoff)
676 {
677         if (_feedback_exists) {
678                 if (onoff) {
679                         feedback_alert_button.set_active (true);
680                 } else {
681                         feedback_alert_button.set_active (false);
682                 }
683         } else {
684                 feedback_alert_button.set_active (false);
685         }
686 }
687
688 void
689 ARDOUR_UI::error_blink (bool onoff)
690 {
691         switch (_log_not_acknowledged) {
692                 case LogLevelError:
693                         // blink
694                         if (onoff) {
695                                 error_alert_button.set_custom_led_color(0xff0000ff); // bright red
696                         } else {
697                                 error_alert_button.set_custom_led_color(0x880000ff); // dark red
698                         }
699                         break;
700                 case LogLevelWarning:
701                         error_alert_button.set_custom_led_color(0xccaa00ff); // yellow
702                         break;
703                 case LogLevelInfo:
704                         error_alert_button.set_custom_led_color(0x88cc00ff); // lime green
705                         break;
706                 default:
707                         error_alert_button.set_custom_led_color(0x333333ff); // gray
708                         break;
709         }
710 }
711
712
713
714 void
715 ARDOUR_UI::set_transport_sensitivity (bool yn)
716 {
717         ActionManager::set_sensitive (ActionManager::transport_sensitive_actions, yn);
718         shuttle_box->set_sensitive (yn);
719 }
720
721 void
722 ARDOUR_UI::editor_realized ()
723 {
724         boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
725         Config->map_parameters (pc);
726
727         UIConfiguration::instance().reset_dpi ();
728 }
729
730 void
731 ARDOUR_UI::maximise_editing_space ()
732 {
733         if (editor) {
734                 editor->maximise_editing_space ();
735         }
736 }
737
738 void
739 ARDOUR_UI::restore_editing_space ()
740 {
741         if (editor) {
742                 editor->restore_editing_space ();
743         }
744 }
745
746 void
747 ARDOUR_UI::show_ui_prefs ()
748 {
749         if (rc_option_editor) {
750                 show_tabbable (rc_option_editor);
751                 rc_option_editor->set_current_page (_("GUI"));
752         }
753 }
754
755 bool
756 ARDOUR_UI::click_button_clicked (GdkEventButton* ev)
757 {
758         if (ev->button != 3) {
759                 /* this handler is just for button-3 clicks */
760                 return false;
761         }
762
763         show_tabbable (rc_option_editor);
764         rc_option_editor->set_current_page (_("Misc/Click"));
765         return true;
766 }
767
768 bool
769 ARDOUR_UI::sync_button_clicked (GdkEventButton* ev)
770 {
771         if (ev->button != 3) {
772                 /* this handler is just for button-3 clicks */
773                 return false;
774         }
775
776         show_tabbable (rc_option_editor);
777         rc_option_editor->set_current_page (_("Transport/Sync"));
778         return true;
779 }
780
781 void
782 ARDOUR_UI::toggle_follow_edits ()
783 {
784         RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
785         assert (act);
786
787         RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
788         assert (tact);
789
790         UIConfiguration::instance().set_follow_edits (tact->get_active ());
791 }
792
793 void
794 ARDOUR_UI::update_title ()
795 {
796         if (_session) {
797                 bool dirty = _session->dirty();
798
799                 string session_name;
800
801                 if (_session->snap_name() != _session->name()) {
802                         session_name = _session->snap_name();
803                 } else {
804                         session_name = _session->name();
805                 }
806
807                 if (dirty) {
808                         session_name = "*" + session_name;
809                 }
810
811                 WindowTitle title (session_name);
812                 title += Glib::get_application_name();
813                 _main_window.set_title (title.get_string());
814         } else {
815                 WindowTitle title (Glib::get_application_name());
816                 _main_window.set_title (title.get_string());
817         }
818
819 }