Add UI to set global track layered mode
[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 "theme_manager.h"
56 #include "midi_tracer.h"
57 #include "shuttle_control.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
73 void
74 ARDOUR_UI::setup_tooltips ()
75 {
76         ArdourCanvas::Canvas::set_tooltip_timeout (Gtk::Settings::get_default()->property_gtk_tooltip_timeout ());
77
78         set_tip (roll_button, _("Play from playhead"));
79         set_tip (stop_button, _("Stop playback"));
80         set_tip (rec_button, _("Toggle record"));
81         set_tip (play_selection_button, _("Play range/selection"));
82         set_tip (goto_start_button, _("Go to start of session"));
83         set_tip (goto_end_button, _("Go to end of session"));
84         set_tip (auto_loop_button, _("Play loop range"));
85         set_tip (midi_panic_button, _("MIDI Panic\nSend note off and reset controller messages on all MIDI channels"));
86         set_tip (auto_return_button, _("Return to last playback start when stopped"));
87         set_tip (follow_edits_button, _("Playhead follows range selections and edits"));
88         set_tip (auto_input_button, _("Be sensible about input monitoring"));
89         set_tip (click_button, _("Enable/Disable audio click"));
90         set_tip (solo_alert_button, _("When active, something is soloed.\nClick to de-solo everything"));
91         set_tip (auditioning_alert_button, _("When active, auditioning is taking place.\nClick to stop the audition"));
92         set_tip (feedback_alert_button, _("When active, there is a feedback loop."));
93         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"));
94         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"));
95         set_tip (editor_meter_peak_display, _("Reset All Peak Indicators"));
96         set_tip (error_alert_button, _("Show Error Log and acknowledge warnings"));
97
98         synchronize_sync_source_and_video_pullup ();
99
100         editor->setup_tooltips ();
101 }
102
103 bool
104 ARDOUR_UI::status_bar_button_press (GdkEventButton* ev)
105 {
106         bool handled = false;
107
108         switch (ev->button) {
109         case 1:
110                 status_bar_label.set_text ("");
111                 handled = true;
112                 break;
113         default:
114                 break;
115         }
116
117         return handled;
118 }
119
120 void
121 ARDOUR_UI::display_message (const char *prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
122 {
123         string text;
124
125         UI::display_message (prefix, prefix_len, ptag, mtag, msg);
126
127         ArdourLogLevel ll = LogLevelNone;
128
129         if (strcmp (prefix, _("[ERROR]: ")) == 0) {
130                 text = "<span color=\"red\" weight=\"bold\">";
131                 ll = LogLevelError;
132         } else if (strcmp (prefix, _("[WARNING]: ")) == 0) {
133                 text = "<span color=\"yellow\" weight=\"bold\">";
134                 ll = LogLevelWarning;
135         } else if (strcmp (prefix, _("[INFO]: ")) == 0) {
136                 text = "<span color=\"green\" weight=\"bold\">";
137                 ll = LogLevelInfo;
138         } else {
139                 text = "<span color=\"white\" weight=\"bold\">???";
140         }
141
142         _log_not_acknowledged = std::max(_log_not_acknowledged, ll);
143
144 #ifdef TOP_MENUBAR
145         text += prefix;
146         text += "</span>";
147         text += msg;
148
149         status_bar_label.set_markup (text);
150 #endif
151 }
152
153 XMLNode*
154 ARDOUR_UI::tearoff_settings (const char* name) const
155 {
156         XMLNode* ui_node = Config->extra_xml(X_("UI"));
157
158         if (ui_node) {
159                 XMLNode* tearoff_node = ui_node->child (X_("Tearoffs"));
160                 if (tearoff_node) {
161                         XMLNode* mnode = tearoff_node->child (name);
162                         return mnode;
163                 }
164         }
165
166         return 0;
167 }
168
169 #define PX_SCALE(px) std::max((float)px, rintf((float)px * UIConfiguration::instance().get_ui_scale()))
170
171 static
172 bool drag_failed (const Glib::RefPtr<Gdk::DragContext>& context, DragResult result, Tabbable* tab)
173 {
174         if (result == Gtk::DRAG_RESULT_NO_TARGET) {
175                 tab->detach ();
176                 return true;
177         }
178         return false;
179 }
180
181 bool
182 ARDOUR_UI::transport_expose (GdkEventExpose* ev)
183 {
184         int x0, y0;
185         Gtk::Widget* window_parent;
186         Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (transport_table, &window_parent);
187         Glib::RefPtr<Gtk::Style> style = transport_table.get_style();
188         if (!win || !style) {
189                 return false;
190         }
191
192         Cairo::RefPtr<Cairo::Context> cr = transport_table.get_window()->create_cairo_context ();
193
194         cr->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
195         cr->clip ();
196
197         transport_table.translate_coordinates (*window_parent, 0, 0, x0, y0);
198
199         cr->rectangle (x0, y0, transport_table.get_width(), transport_table.get_height());
200         Gdk::Color bg (style->get_bg (transport_table.get_state()));
201         cr->set_source_rgb (bg.get_red_p(), bg.get_green_p(), bg.get_blue_p());
202         cr->fill ();
203
204         static const int xmargin = 2;
205         static const int ymargin = 1;
206
207         /* draw box around record-options */
208         int xx, ww, hh, uu;
209
210         punch_label.translate_coordinates (transport_table, -xmargin, 0, xx, uu); // left
211         punch_out_button.translate_coordinates (transport_table, xmargin, 0, ww, uu); // right
212         ww += punch_out_button.get_width () - xx; // width
213         hh = transport_table.get_height() - 1;
214
215         Gtkmm2ext::rounded_rectangle (cr->cobj(), x0 + xx - 0.5, y0 + 0.5, ww + 1, hh, 6);
216         cr->set_source_rgb (0, 0, 0);
217         cr->set_line_width (1.0);
218         cr->stroke ();
219
220         /* line to rec-enable */
221         int rx;
222         rec_button.translate_coordinates (transport_table, -xmargin, 0, rx, uu); // top
223         int dx = rx + rec_button.get_width() - xx;
224
225         cr->move_to (x0 + xx, 1.5 + y0 + ymargin + round (punch_in_button.get_height () * .5));
226         cr->rel_line_to (dx, 0);
227         cr->stroke ();
228
229         /* alert box */
230         gint ax;
231         solo_alert_button.translate_coordinates (transport_table, -xmargin, 0, ax, uu); // left
232         ww = solo_alert_button.get_width () + 2 * xmargin;
233         Gtkmm2ext::rounded_rectangle (cr->cobj(), x0 + ax - 0.5, y0 + 0.5, ww + 1, hh, 6);
234         cr->stroke ();
235
236         return false;
237 }
238
239 void
240 ARDOUR_UI::setup_transport ()
241 {
242         RefPtr<Action> act;
243         /* setup actions */
244
245         act = ActionManager::get_action ("Transport", "ToggleClick");
246         click_button.set_related_action (act);
247         click_button.signal_button_press_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::click_button_clicked), false);
248
249         act = ActionManager::get_action (X_("Transport"), X_("Stop"));
250         stop_button.set_related_action (act);
251         act = ActionManager::get_action (X_("Transport"), X_("Roll"));
252         roll_button.set_related_action (act);
253         act = ActionManager::get_action (X_("Transport"), X_("Record"));
254         rec_button.set_related_action (act);
255         act = ActionManager::get_action (X_("Transport"), X_("GotoStart"));
256         goto_start_button.set_related_action (act);
257         act = ActionManager::get_action (X_("Transport"), X_("GotoEnd"));
258         goto_end_button.set_related_action (act);
259         act = ActionManager::get_action (X_("Transport"), X_("Loop"));
260         auto_loop_button.set_related_action (act);
261         act = ActionManager::get_action (X_("Transport"), X_("PlaySelection"));
262         play_selection_button.set_related_action (act);
263         act = ActionManager::get_action (X_("MIDI"), X_("panic"));
264         midi_panic_button.set_related_action (act);
265         act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
266         sync_button.set_related_action (act);
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 Edits"));
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 (_("Mode:"));
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
400         /* and now the layout... */
401
402         /* top level packing */
403         transport_table.set_spacings (0);
404         transport_frame.add (transport_table);
405         transport_frame.set_name ("BaseFrame");
406
407         transport_table.signal_expose_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::transport_expose), false);
408
409         /* transport controls sub-group */
410         click_button.set_size_request (PX_SCALE(20), PX_SCALE(20));
411
412         HBox* tbox = manage (new HBox);
413         tbox->set_spacing (PX_SCALE(1));
414
415         tbox->pack_start (midi_panic_button, true, true, 0);
416         tbox->pack_start (click_button, true, true, 0);
417         tbox->pack_start (goto_start_button, true, true);
418         tbox->pack_start (goto_end_button, true, true);
419         tbox->pack_start (auto_loop_button, true, true);
420         tbox->pack_start (play_selection_button, true, true);
421
422         tbox->pack_start (roll_button, true, true);
423         tbox->pack_start (stop_button, true, true);
424         tbox->pack_start (rec_button, true, true, 3);
425
426         /* alert box sub-group */
427         VBox* alert_box = manage (new VBox);
428         alert_box->set_homogeneous (true);
429         alert_box->set_spacing (1);
430         alert_box->set_border_width (2);
431         alert_box->pack_start (solo_alert_button, true, false, 0);
432         alert_box->pack_start (auditioning_alert_button, true, false, 0);
433         alert_box->pack_start (feedback_alert_button, true, false, 0);
434
435         /* clock button size groups */
436         Glib::RefPtr<SizeGroup> button_height_size_group = SizeGroup::create (Gtk::SIZE_GROUP_VERTICAL);
437         button_height_size_group->add_widget (follow_edits_button);
438         button_height_size_group->add_widget (*primary_clock->left_btn());
439         button_height_size_group->add_widget (*primary_clock->right_btn());
440         button_height_size_group->add_widget (*secondary_clock->left_btn());
441         button_height_size_group->add_widget (*secondary_clock->right_btn());
442
443         Glib::RefPtr<SizeGroup> clock1_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
444         clock1_size_group->add_widget (*primary_clock->left_btn());
445         clock1_size_group->add_widget (*primary_clock->right_btn());
446
447         Glib::RefPtr<SizeGroup> clock2_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
448         clock2_size_group->add_widget (*secondary_clock->left_btn());
449         clock2_size_group->add_widget (*secondary_clock->right_btn());
450
451         /* and the main table layout */
452
453         transport_table.attach (*tbox, 0, 2, 0, 1 , SHRINK, SHRINK, 3, 0);
454         transport_table.attach (sync_button, 0, 1, 1, 2 , FILL, SHRINK, 0, 0);
455         transport_table.attach (*shuttle_box, 1, 2, 1, 2 , FILL, SHRINK, 3, 0);
456
457         transport_table.attach (punch_label, 2, 3, 0, 1 , FILL, SHRINK, 3, 0);
458         transport_table.attach (layered_label, 2, 3, 1, 2 , FILL, SHRINK, 3, 0);
459
460         transport_table.attach (punch_in_button, 3, 4, 0, 1 , FILL, SHRINK, 1, 2);
461         transport_table.attach (punch_out_button, 4, 5, 0, 1 , FILL, SHRINK, 1, 2);
462         transport_table.attach (layered_button, 3, 5, 1, 2 , FILL, SHRINK, 0, 2);
463
464         // some extra space here (accomodate for the record-option box)
465         transport_table.attach (*(manage (new Label (""))), 5, 6, 0, 2 , FILL, SHRINK, 2, 0);
466
467         transport_table.attach (follow_edits_button, 6, 7, 0, 1 , FILL, SHRINK, 2, 0);
468         transport_table.attach (auto_return_button, 6, 7, 1, 2 , FILL, SHRINK, 2, 0);
469
470         transport_table.attach (*primary_clock, 7, 9, 0, 1 , FILL, SHRINK, 1, 0);
471         transport_table.attach (*primary_clock->left_btn(), 7, 8, 1, 2 , FILL, SHRINK, 1, 0);
472         transport_table.attach (*primary_clock->right_btn(), 8, 9, 1, 2 , FILL, SHRINK, 1, 0);
473
474         if (!ARDOUR::Profile->get_small_screen()) {
475                 transport_table.attach (*secondary_clock, 9, 11, 0, 1 , FILL, SHRINK, 1, 0);
476                 transport_table.attach (*secondary_clock->left_btn(), 9, 10, 1, 2 , FILL, SHRINK, 1, 0);
477                 transport_table.attach (*secondary_clock->right_btn(), 10, 11, 1, 2 , FILL, SHRINK, 1, 0);
478         }
479
480         transport_table.attach (*alert_box, 11, 12, 0, 2, SHRINK, SHRINK, 2, 0);
481
482         /* editor-meter is in transport_hbox */
483         transport_hbox.set_spacing (PX_SCALE(1));
484         transport_table.attach (transport_hbox, 12, 13, 0, 2, SHRINK, EXPAND|FILL, 3, 0);
485
486         /* lua script action buttons */
487         transport_table.attach (action_script_table, 13, 14, 0, 2, SHRINK, EXPAND|FILL, 1, 0);
488
489         transport_table.attach (editor_visibility_button, 14, 15, 0, 1 , FILL, SHRINK, 1, 0);
490         transport_table.attach (mixer_visibility_button, 14, 15, 1, 2 , FILL, SHRINK, 1, 0);
491
492         /* desensitize */
493
494         feedback_alert_button.set_sensitive (false);
495         feedback_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
496         auditioning_alert_button.set_sensitive (false);
497         auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
498
499         stop_button.set_active (true);
500         set_transport_sensitivity (false);
501 }
502 #undef PX_SCALE
503
504 void
505 ARDOUR_UI::soloing_changed (bool onoff)
506 {
507         if (solo_alert_button.get_active() != onoff) {
508                 solo_alert_button.set_active (onoff);
509         }
510 }
511
512 void
513 ARDOUR_UI::_auditioning_changed (bool onoff)
514 {
515         auditioning_alert_button.set_active (onoff);
516         auditioning_alert_button.set_sensitive (onoff);
517         if (!onoff) {
518                 auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
519         }
520         set_transport_sensitivity (!onoff);
521 }
522
523 void
524 ARDOUR_UI::auditioning_changed (bool onoff)
525 {
526         UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::_auditioning_changed, this, onoff));
527 }
528
529 void
530 ARDOUR_UI::audition_alert_clicked ()
531 {
532         if (_session) {
533                 _session->cancel_audition();
534         }
535 }
536
537 bool
538 ARDOUR_UI::error_alert_press (GdkEventButton* ev)
539 {
540         bool do_toggle = true;
541         if (ev->button == 1) {
542                 if (_log_not_acknowledged == LogLevelError) {
543                         // just acknowledge the error, don't hide the log if it's already visible
544                         RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
545                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
546                         if (tact && tact->get_active()) {
547                                 do_toggle = false;
548                         }
549                 }
550                 _log_not_acknowledged = LogLevelNone;
551                 error_blink (false); // immediate acknowledge
552         }
553         // maybe fall through to to button toggle
554         return !do_toggle;
555 }
556
557 void
558 ARDOUR_UI::layered_button_clicked ()
559 {
560         if (_session) {
561                 _session->config.set_layered_record_mode (!_session->config.get_layered_record_mode ());
562         }
563 }
564
565 void
566 ARDOUR_UI::solo_blink (bool onoff)
567 {
568         if (_session == 0) {
569                 return;
570         }
571
572         if (_session->soloing() || _session->listening()) {
573                 if (onoff) {
574                         solo_alert_button.set_active (true);
575                 } else {
576                         solo_alert_button.set_active (false);
577                 }
578         } else {
579                 solo_alert_button.set_active (false);
580         }
581 }
582
583 void
584 ARDOUR_UI::sync_blink (bool onoff)
585 {
586         if (_session == 0 || !_session->config.get_external_sync()) {
587                 /* internal sync */
588                 sync_button.set_active (false);
589                 return;
590         }
591
592         if (!_session->transport_locked()) {
593                 /* not locked, so blink on and off according to the onoff argument */
594
595                 if (onoff) {
596                         sync_button.set_active (true);
597                 } else {
598                         sync_button.set_active (false);
599                 }
600         } else {
601                 /* locked */
602                 sync_button.set_active (true);
603         }
604 }
605
606 void
607 ARDOUR_UI::audition_blink (bool onoff)
608 {
609         if (_session == 0) {
610                 return;
611         }
612
613         if (_session->is_auditioning()) {
614                 if (onoff) {
615                         auditioning_alert_button.set_active (true);
616                 } else {
617                         auditioning_alert_button.set_active (false);
618                 }
619         } else {
620                 auditioning_alert_button.set_active (false);
621         }
622 }
623
624 void
625 ARDOUR_UI::feedback_blink (bool onoff)
626 {
627         if (_feedback_exists) {
628                 if (onoff) {
629                         feedback_alert_button.set_active (true);
630                 } else {
631                         feedback_alert_button.set_active (false);
632                 }
633         } else {
634                 feedback_alert_button.set_active (false);
635         }
636 }
637
638 void
639 ARDOUR_UI::error_blink (bool onoff)
640 {
641         switch (_log_not_acknowledged) {
642                 case LogLevelError:
643                         // blink
644                         if (onoff) {
645                                 error_alert_button.set_custom_led_color(0xff0000ff); // bright red
646                         } else {
647                                 error_alert_button.set_custom_led_color(0x880000ff); // dark red
648                         }
649                         break;
650                 case LogLevelWarning:
651                         error_alert_button.set_custom_led_color(0xccaa00ff); // yellow
652                         break;
653                 case LogLevelInfo:
654                         error_alert_button.set_custom_led_color(0x88cc00ff); // lime green
655                         break;
656                 default:
657                         error_alert_button.set_custom_led_color(0x333333ff); // gray
658                         break;
659         }
660 }
661
662
663
664 void
665 ARDOUR_UI::set_transport_sensitivity (bool yn)
666 {
667         ActionManager::set_sensitive (ActionManager::transport_sensitive_actions, yn);
668         shuttle_box->set_sensitive (yn);
669 }
670
671 void
672 ARDOUR_UI::editor_realized ()
673 {
674         boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
675         Config->map_parameters (pc);
676
677         UIConfiguration::instance().reset_dpi ();
678 }
679
680 void
681 ARDOUR_UI::maximise_editing_space ()
682 {
683         if (editor) {
684                 editor->maximise_editing_space ();
685         }
686 }
687
688 void
689 ARDOUR_UI::restore_editing_space ()
690 {
691         if (editor) {
692                 editor->restore_editing_space ();
693         }
694 }
695
696 void
697 ARDOUR_UI::show_ui_prefs ()
698 {
699         if (rc_option_editor) {
700                 show_tabbable (rc_option_editor);
701                 rc_option_editor->set_current_page (_("GUI"));
702         }
703 }
704
705 bool
706 ARDOUR_UI::click_button_clicked (GdkEventButton* ev)
707 {
708         if (ev->button != 3) {
709                 /* this handler is just for button-3 clicks */
710                 return false;
711         }
712
713         show_tabbable (rc_option_editor);
714         rc_option_editor->set_current_page (_("Misc/Click"));
715         return true;
716 }
717
718 void
719 ARDOUR_UI::toggle_follow_edits ()
720 {
721         RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
722         assert (act);
723
724         RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
725         assert (tact);
726
727         UIConfiguration::instance().set_follow_edits (tact->get_active ());
728 }
729
730 void
731 ARDOUR_UI::update_title ()
732 {
733         if (_session) {
734                 bool dirty = _session->dirty();
735
736                 string session_name;
737
738                 if (_session->snap_name() != _session->name()) {
739                         session_name = _session->snap_name();
740                 } else {
741                         session_name = _session->name();
742                 }
743
744                 if (dirty) {
745                         session_name = "*" + session_name;
746                 }
747
748                 WindowTitle title (session_name);
749                 title += Glib::get_application_name();
750                 _main_window.set_title (title.get_string());
751         } else {
752                 WindowTitle title (Glib::get_application_name());
753                 _main_window.set_title (title.get_string());
754         }
755
756 }