Prepare mini-timeline widget for toolbar
[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 "mini_timeline.h"
58 #include "shuttle_control.h"
59 #include "global_port_matrix.h"
60 #include "location_ui.h"
61 #include "rc_option_editor.h"
62
63 #include "pbd/i18n.h"
64
65 using namespace std;
66 using namespace ARDOUR;
67 using namespace PBD;
68 using namespace Gtkmm2ext;
69 using namespace Gtk;
70 using namespace Glib;
71 using namespace ARDOUR_UI_UTILS;
72
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 selections and edits"));
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         int x0, y0;
186         Gtk::Widget* window_parent;
187         Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (transport_table, &window_parent);
188         Glib::RefPtr<Gtk::Style> style = transport_table.get_style();
189         if (!win || !style) {
190                 return false;
191         }
192
193         Cairo::RefPtr<Cairo::Context> cr = transport_table.get_window()->create_cairo_context ();
194
195         cr->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
196         cr->clip ();
197
198         transport_table.translate_coordinates (*window_parent, 0, 0, x0, y0);
199
200         cr->rectangle (x0, y0, transport_table.get_width(), transport_table.get_height());
201         Gdk::Color bg (style->get_bg (transport_table.get_state()));
202         cr->set_source_rgb (bg.get_red_p(), bg.get_green_p(), bg.get_blue_p());
203         cr->fill ();
204
205         static const int xmargin = 2;
206         static const int ymargin = 1;
207
208         /* draw box around record-options */
209         int xx, ww, hh, uu;
210
211         punch_label.translate_coordinates (transport_table, -xmargin, 0, xx, uu); // left
212         punch_out_button.translate_coordinates (transport_table, xmargin, 0, ww, uu); // right
213         ww += punch_out_button.get_width () - xx; // width
214         hh = transport_table.get_height() - 1;
215
216         Gtkmm2ext::rounded_rectangle (cr->cobj(), x0 + xx - 0.5, y0 + 0.5, ww + 1, hh, 6);
217         cr->set_source_rgb (0, 0, 0);
218         cr->set_line_width (1.0);
219         cr->stroke ();
220
221         /* line to rec-enable */
222         int rx;
223         rec_button.translate_coordinates (transport_table, -xmargin, 0, rx, uu); // top
224         int dx = rx + rec_button.get_width() - xx;
225
226         cr->move_to (x0 + xx, 1.5 + y0 + ymargin + round (punch_in_button.get_height () * .5));
227         cr->rel_line_to (dx, 0);
228         cr->stroke ();
229
230         /* alert box */
231         gint ax;
232         solo_alert_button.translate_coordinates (transport_table, -xmargin, 0, ax, uu); // left
233         ww = solo_alert_button.get_width () + 2 * xmargin;
234         Gtkmm2ext::rounded_rectangle (cr->cobj(), x0 + ax - 0.5, y0 + 0.5, ww + 1, hh, 6);
235         cr->stroke ();
236
237         return false;
238 }
239
240 void
241 ARDOUR_UI::setup_transport ()
242 {
243         RefPtr<Action> act;
244         /* setup actions */
245
246         act = ActionManager::get_action ("Transport", "ToggleClick");
247         click_button.set_related_action (act);
248         click_button.signal_button_press_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::click_button_clicked), false);
249
250         act = ActionManager::get_action (X_("Transport"), X_("Stop"));
251         stop_button.set_related_action (act);
252         act = ActionManager::get_action (X_("Transport"), X_("Roll"));
253         roll_button.set_related_action (act);
254         act = ActionManager::get_action (X_("Transport"), X_("Record"));
255         rec_button.set_related_action (act);
256         act = ActionManager::get_action (X_("Transport"), X_("GotoStart"));
257         goto_start_button.set_related_action (act);
258         act = ActionManager::get_action (X_("Transport"), X_("GotoEnd"));
259         goto_end_button.set_related_action (act);
260         act = ActionManager::get_action (X_("Transport"), X_("Loop"));
261         auto_loop_button.set_related_action (act);
262         act = ActionManager::get_action (X_("Transport"), X_("PlaySelection"));
263         play_selection_button.set_related_action (act);
264         act = ActionManager::get_action (X_("MIDI"), X_("panic"));
265         midi_panic_button.set_related_action (act);
266         act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
267         sync_button.set_related_action (act);
268
269         /* CANNOT sigc::bind these to clicked or toggled, must use pressed or released */
270         act = ActionManager::get_action (X_("Main"), X_("cancel-solo"));
271         solo_alert_button.set_related_action (act);
272         auditioning_alert_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::audition_alert_clicked));
273         error_alert_button.signal_button_release_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::error_alert_press), false);
274         act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
275         error_alert_button.set_related_action(act);
276         error_alert_button.set_fallthrough_to_parent(true);
277
278         layered_button.signal_clicked.connect (sigc::mem_fun(*this,&ARDOUR_UI::layered_button_clicked));
279
280         editor_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-editor-visibility")));
281         mixer_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-mixer-visibility")));
282         prefs_visibility_button.set_related_action (ActionManager::get_action (X_("Common"), X_("change-preferences-visibility")));
283
284         act = ActionManager::get_action ("Transport", "ToggleAutoReturn");
285         auto_return_button.set_related_action (act);
286         act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
287         follow_edits_button.set_related_action (act);
288         act = ActionManager::get_action ("Transport", "ToggleAutoInput");
289         auto_input_button.set_related_action (act);
290
291         act = ActionManager::get_action ("Transport", "TogglePunchIn");
292         punch_in_button.set_related_action (act);
293         act = ActionManager::get_action ("Transport", "TogglePunchOut");
294         punch_out_button.set_related_action (act);
295
296         /* connect signals */
297         ARDOUR_UI::Clock.connect (sigc::mem_fun (primary_clock, &AudioClock::set));
298         ARDOUR_UI::Clock.connect (sigc::mem_fun (secondary_clock, &AudioClock::set));
299
300         primary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::primary_clock_value_changed));
301         secondary_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::secondary_clock_value_changed));
302         big_clock->ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::big_clock_value_changed));
303
304         editor_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), editor));
305         mixer_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), mixer));
306         prefs_visibility_button.signal_drag_failed().connect (sigc::bind (sigc::ptr_fun (drag_failed), rc_option_editor));
307
308         /* catch context clicks so that we can show a menu on these buttons */
309
310         editor_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("editor")), false);
311         mixer_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("mixer")), false);
312         prefs_visibility_button.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_visibility_button_press), X_("preferences")), false);
313
314         /* setup widget style/name */
315
316         auto_return_button.set_name ("transport option button");
317         follow_edits_button.set_name ("transport option button");
318         auto_input_button.set_name ("transport option button");
319
320         solo_alert_button.set_name ("rude solo");
321         auditioning_alert_button.set_name ("rude audition");
322         feedback_alert_button.set_name ("feedback alert");
323         error_alert_button.set_name ("error alert");
324
325         solo_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
326         auditioning_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
327         feedback_alert_button.set_elements (ArdourButton::Element(ArdourButton::Body|ArdourButton::Text));
328
329         solo_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
330         auditioning_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
331         feedback_alert_button.set_layout_font (UIConfiguration::instance().get_SmallerFont());
332
333         editor_visibility_button.set_name (X_("page switch button"));
334         mixer_visibility_button.set_name (X_("page switch button"));
335         prefs_visibility_button.set_name (X_("page switch button"));
336
337         punch_in_button.set_name ("punch button");
338         punch_out_button.set_name ("punch button");
339         layered_button.set_name (("layered button"));
340
341         click_button.set_name ("transport button");
342         sync_button.set_name ("transport active option button");
343
344         /* and widget text */
345         auto_return_button.set_text(_("Auto Return"));
346         follow_edits_button.set_text(_("Follow Edits"));
347         //auto_input_button.set_text (_("Auto Input"));
348         punch_in_button.set_text (_("In"));
349         punch_out_button.set_text (_("Out"));
350         layered_button.set_text (_("Non-Layered"));
351
352         punch_label.set_text (_("Punch:"));
353         layered_label.set_text (_("Mode:"));
354
355         /* and tooltips */
356
357         Gtkmm2ext::UI::instance()->set_tip (editor_visibility_button,
358                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
359                                                               "To put the window back, use the Window > %1 > Attach menu action"), editor->name()));
360
361         Gtkmm2ext::UI::instance()->set_tip (mixer_visibility_button,
362                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
363                                                               "To put the window back, use the Window > %1 > Attach menu action"), mixer->name()));
364
365         Gtkmm2ext::UI::instance()->set_tip (prefs_visibility_button,
366                                             string_compose (_("Drag this tab to the desktop to show %1 in its own window\n\n"
367                                                               "To put the window back, use the Window > %1 > Attach menu action"), rc_option_editor->name()));
368
369         Gtkmm2ext::UI::instance()->set_tip (punch_in_button, _("Start recording at auto-punch start"));
370         Gtkmm2ext::UI::instance()->set_tip (punch_out_button, _("Stop recording at auto-punch end"));
371
372         /* setup icons */
373
374         click_button.set_icon (ArdourIcon::TransportMetronom);
375         goto_start_button.set_icon (ArdourIcon::TransportStart);
376         goto_end_button.set_icon (ArdourIcon::TransportEnd);
377         roll_button.set_icon (ArdourIcon::TransportPlay);
378         stop_button.set_icon (ArdourIcon::TransportStop);
379         play_selection_button.set_icon (ArdourIcon::TransportRange);
380         auto_loop_button.set_icon (ArdourIcon::TransportLoop);
381         rec_button.set_icon (ArdourIcon::RecButton);
382         midi_panic_button.set_icon (ArdourIcon::TransportPanic);
383
384         /* transport control size-group */
385
386         Glib::RefPtr<SizeGroup> transport_button_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
387         transport_button_size_group->add_widget (goto_start_button);
388         transport_button_size_group->add_widget (goto_end_button);
389         transport_button_size_group->add_widget (auto_loop_button);
390         transport_button_size_group->add_widget (rec_button);
391         transport_button_size_group->add_widget (play_selection_button);
392         transport_button_size_group->add_widget (roll_button);
393         transport_button_size_group->add_widget (stop_button);
394
395         Glib::RefPtr<SizeGroup> punch_button_size_group = SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
396         punch_button_size_group->add_widget (punch_in_button);
397         punch_button_size_group->add_widget (punch_out_button);
398
399         shuttle_box = manage (new ShuttleControl);
400         mini_timeline = manage (new MiniTimeline);
401
402         /* and now the layout... */
403
404         /* top level packing */
405         transport_table.set_spacings (0);
406         transport_frame.add (transport_table);
407         transport_frame.set_name ("BaseFrame");
408
409         transport_table.signal_expose_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::transport_expose), false);
410
411         /* transport controls sub-group */
412         click_button.set_size_request (PX_SCALE(20), PX_SCALE(20));
413
414         HBox* tbox = manage (new HBox);
415         tbox->set_spacing (PX_SCALE(1));
416
417         tbox->pack_start (midi_panic_button, true, true, 0);
418         tbox->pack_start (click_button, true, true, 0);
419         tbox->pack_start (goto_start_button, true, true);
420         tbox->pack_start (goto_end_button, true, true);
421         tbox->pack_start (auto_loop_button, true, true);
422         tbox->pack_start (play_selection_button, true, true);
423
424         tbox->pack_start (roll_button, true, true);
425         tbox->pack_start (stop_button, true, true);
426         tbox->pack_start (rec_button, true, true, 3);
427
428         /* alert box sub-group */
429         VBox* alert_box = manage (new VBox);
430         alert_box->set_homogeneous (true);
431         alert_box->set_spacing (1);
432         alert_box->set_border_width (2);
433         alert_box->pack_start (solo_alert_button, true, false, 0);
434         alert_box->pack_start (auditioning_alert_button, true, false, 0);
435         alert_box->pack_start (feedback_alert_button, true, false, 0);
436
437         /* clock button size groups */
438         Glib::RefPtr<SizeGroup> button_height_size_group = SizeGroup::create (Gtk::SIZE_GROUP_VERTICAL);
439         button_height_size_group->add_widget (follow_edits_button);
440         button_height_size_group->add_widget (*primary_clock->left_btn());
441         button_height_size_group->add_widget (*primary_clock->right_btn());
442         button_height_size_group->add_widget (*secondary_clock->left_btn());
443         button_height_size_group->add_widget (*secondary_clock->right_btn());
444
445         Glib::RefPtr<SizeGroup> clock1_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
446         clock1_size_group->add_widget (*primary_clock->left_btn());
447         clock1_size_group->add_widget (*primary_clock->right_btn());
448
449         Glib::RefPtr<SizeGroup> clock2_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
450         clock2_size_group->add_widget (*secondary_clock->left_btn());
451         clock2_size_group->add_widget (*secondary_clock->right_btn());
452
453         /* and the main table layout */
454
455         transport_table.attach (*tbox, 0, 2, 0, 1 , SHRINK, SHRINK, 3, 0);
456         transport_table.attach (sync_button, 0, 1, 1, 2 , FILL, SHRINK, 0, 0);
457         transport_table.attach (*shuttle_box, 1, 2, 1, 2 , FILL, SHRINK, 3, 0);
458
459         transport_table.attach (punch_label, 2, 3, 0, 1 , FILL, SHRINK, 3, 0);
460         transport_table.attach (layered_label, 2, 3, 1, 2 , FILL, SHRINK, 3, 0);
461
462         transport_table.attach (punch_in_button, 3, 4, 0, 1 , FILL, SHRINK, 1, 2);
463         transport_table.attach (punch_out_button, 4, 5, 0, 1 , FILL, SHRINK, 1, 2);
464         transport_table.attach (layered_button, 3, 5, 1, 2 , FILL, SHRINK, 0, 2);
465
466         // some extra space here (accomodate for the record-option box)
467         transport_table.attach (*(manage (new Label (""))), 5, 6, 0, 2 , FILL, SHRINK, 2, 0);
468
469         transport_table.attach (follow_edits_button, 6, 7, 0, 1 , FILL, SHRINK, 2, 0);
470         transport_table.attach (auto_return_button, 6, 7, 1, 2 , FILL, SHRINK, 2, 0);
471
472         transport_table.attach (*primary_clock, 7, 9, 0, 1 , FILL, SHRINK, 1, 0);
473         transport_table.attach (*primary_clock->left_btn(), 7, 8, 1, 2 , FILL, SHRINK, 1, 0);
474         transport_table.attach (*primary_clock->right_btn(), 8, 9, 1, 2 , FILL, SHRINK, 1, 0);
475
476         if (!ARDOUR::Profile->get_small_screen()) {
477                 transport_table.attach (*secondary_clock, 9, 11, 0, 1 , FILL, SHRINK, 1, 0);
478                 transport_table.attach (*secondary_clock->left_btn(), 9, 10, 1, 2 , FILL, SHRINK, 1, 0);
479                 transport_table.attach (*secondary_clock->right_btn(), 10, 11, 1, 2 , FILL, SHRINK, 1, 0);
480         }
481
482         transport_table.attach (*alert_box, 11, 12, 0, 2, SHRINK, SHRINK, 2, 0);
483
484         /* editor-meter is in transport_hbox */
485         transport_hbox.set_spacing (PX_SCALE(1));
486         transport_table.attach (transport_hbox, 12, 13, 0, 2, SHRINK, EXPAND|FILL, 3, 0);
487
488         /* lua script action buttons */
489         transport_table.attach (action_script_table, 13, 14, 0, 2, SHRINK, EXPAND|FILL, 1, 0);
490
491         transport_table.attach (editor_visibility_button, 14, 15, 0, 1 , FILL, SHRINK, 1, 0);
492         transport_table.attach (mixer_visibility_button, 14, 15, 1, 2 , FILL, SHRINK, 1, 0);
493
494         transport_table.attach (*mini_timeline, 15, 16, 0, 2, EXPAND|FILL, EXPAND|FILL, 2, 0);
495
496         /* desensitize */
497
498         feedback_alert_button.set_sensitive (false);
499         feedback_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
500         auditioning_alert_button.set_sensitive (false);
501         auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
502
503         stop_button.set_active (true);
504         set_transport_sensitivity (false);
505 }
506 #undef PX_SCALE
507
508 void
509 ARDOUR_UI::soloing_changed (bool onoff)
510 {
511         if (solo_alert_button.get_active() != onoff) {
512                 solo_alert_button.set_active (onoff);
513         }
514 }
515
516 void
517 ARDOUR_UI::_auditioning_changed (bool onoff)
518 {
519         auditioning_alert_button.set_active (onoff);
520         auditioning_alert_button.set_sensitive (onoff);
521         if (!onoff) {
522                 auditioning_alert_button.set_visual_state (Gtkmm2ext::NoVisualState);
523         }
524         set_transport_sensitivity (!onoff);
525 }
526
527 void
528 ARDOUR_UI::auditioning_changed (bool onoff)
529 {
530         UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::_auditioning_changed, this, onoff));
531 }
532
533 void
534 ARDOUR_UI::audition_alert_clicked ()
535 {
536         if (_session) {
537                 _session->cancel_audition();
538         }
539 }
540
541 bool
542 ARDOUR_UI::error_alert_press (GdkEventButton* ev)
543 {
544         bool do_toggle = true;
545         if (ev->button == 1) {
546                 if (_log_not_acknowledged == LogLevelError) {
547                         // just acknowledge the error, don't hide the log if it's already visible
548                         RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("toggle-log-window"));
549                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
550                         if (tact && tact->get_active()) {
551                                 do_toggle = false;
552                         }
553                 }
554                 _log_not_acknowledged = LogLevelNone;
555                 error_blink (false); // immediate acknowledge
556         }
557         // maybe fall through to to button toggle
558         return !do_toggle;
559 }
560
561 void
562 ARDOUR_UI::layered_button_clicked ()
563 {
564         if (_session) {
565                 _session->config.set_layered_record_mode (!_session->config.get_layered_record_mode ());
566         }
567 }
568
569 void
570 ARDOUR_UI::solo_blink (bool onoff)
571 {
572         if (_session == 0) {
573                 return;
574         }
575
576         if (_session->soloing() || _session->listening()) {
577                 if (onoff) {
578                         solo_alert_button.set_active (true);
579                 } else {
580                         solo_alert_button.set_active (false);
581                 }
582         } else {
583                 solo_alert_button.set_active (false);
584         }
585 }
586
587 void
588 ARDOUR_UI::sync_blink (bool onoff)
589 {
590         if (_session == 0 || !_session->config.get_external_sync()) {
591                 /* internal sync */
592                 sync_button.set_active (false);
593                 return;
594         }
595
596         if (!_session->transport_locked()) {
597                 /* not locked, so blink on and off according to the onoff argument */
598
599                 if (onoff) {
600                         sync_button.set_active (true);
601                 } else {
602                         sync_button.set_active (false);
603                 }
604         } else {
605                 /* locked */
606                 sync_button.set_active (true);
607         }
608 }
609
610 void
611 ARDOUR_UI::audition_blink (bool onoff)
612 {
613         if (_session == 0) {
614                 return;
615         }
616
617         if (_session->is_auditioning()) {
618                 if (onoff) {
619                         auditioning_alert_button.set_active (true);
620                 } else {
621                         auditioning_alert_button.set_active (false);
622                 }
623         } else {
624                 auditioning_alert_button.set_active (false);
625         }
626 }
627
628 void
629 ARDOUR_UI::feedback_blink (bool onoff)
630 {
631         if (_feedback_exists) {
632                 if (onoff) {
633                         feedback_alert_button.set_active (true);
634                 } else {
635                         feedback_alert_button.set_active (false);
636                 }
637         } else {
638                 feedback_alert_button.set_active (false);
639         }
640 }
641
642 void
643 ARDOUR_UI::error_blink (bool onoff)
644 {
645         switch (_log_not_acknowledged) {
646                 case LogLevelError:
647                         // blink
648                         if (onoff) {
649                                 error_alert_button.set_custom_led_color(0xff0000ff); // bright red
650                         } else {
651                                 error_alert_button.set_custom_led_color(0x880000ff); // dark red
652                         }
653                         break;
654                 case LogLevelWarning:
655                         error_alert_button.set_custom_led_color(0xccaa00ff); // yellow
656                         break;
657                 case LogLevelInfo:
658                         error_alert_button.set_custom_led_color(0x88cc00ff); // lime green
659                         break;
660                 default:
661                         error_alert_button.set_custom_led_color(0x333333ff); // gray
662                         break;
663         }
664 }
665
666
667
668 void
669 ARDOUR_UI::set_transport_sensitivity (bool yn)
670 {
671         ActionManager::set_sensitive (ActionManager::transport_sensitive_actions, yn);
672         shuttle_box->set_sensitive (yn);
673 }
674
675 void
676 ARDOUR_UI::editor_realized ()
677 {
678         boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
679         Config->map_parameters (pc);
680
681         UIConfiguration::instance().reset_dpi ();
682 }
683
684 void
685 ARDOUR_UI::maximise_editing_space ()
686 {
687         if (editor) {
688                 editor->maximise_editing_space ();
689         }
690 }
691
692 void
693 ARDOUR_UI::restore_editing_space ()
694 {
695         if (editor) {
696                 editor->restore_editing_space ();
697         }
698 }
699
700 void
701 ARDOUR_UI::show_ui_prefs ()
702 {
703         if (rc_option_editor) {
704                 show_tabbable (rc_option_editor);
705                 rc_option_editor->set_current_page (_("GUI"));
706         }
707 }
708
709 bool
710 ARDOUR_UI::click_button_clicked (GdkEventButton* ev)
711 {
712         if (ev->button != 3) {
713                 /* this handler is just for button-3 clicks */
714                 return false;
715         }
716
717         show_tabbable (rc_option_editor);
718         rc_option_editor->set_current_page (_("Misc/Click"));
719         return true;
720 }
721
722 void
723 ARDOUR_UI::toggle_follow_edits ()
724 {
725         RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
726         assert (act);
727
728         RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
729         assert (tact);
730
731         UIConfiguration::instance().set_follow_edits (tact->get_active ());
732 }
733
734 void
735 ARDOUR_UI::update_title ()
736 {
737         if (_session) {
738                 bool dirty = _session->dirty();
739
740                 string session_name;
741
742                 if (_session->snap_name() != _session->name()) {
743                         session_name = _session->snap_name();
744                 } else {
745                         session_name = _session->name();
746                 }
747
748                 if (dirty) {
749                         session_name = "*" + session_name;
750                 }
751
752                 WindowTitle title (session_name);
753                 title += Glib::get_application_name();
754                 _main_window.set_title (title.get_string());
755         } else {
756                 WindowTitle title (Glib::get_application_name());
757                 _main_window.set_title (title.get_string());
758         }
759
760 }