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