put the issue of using a monitor section into ~/.config/ardour.rc, not the session...
[ardour2.git] / gtk2_ardour / ardour_ui2.cc
blob6162ef22d9ff87ca98979905e1954262235c22d3
1 /*
2 Copyright (C) 1999 Paul Davis
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.
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.
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.
20 #include <fcntl.h>
21 #include <signal.h>
22 #include <unistd.h>
23 #include <cerrno>
24 #include <iostream>
25 #include <cmath>
27 #include <sigc++/bind.h>
28 #include "pbd/error.h"
29 #include "pbd/basename.h"
30 #include "pbd/fastlog.h"
31 #include <gtkmm2ext/utils.h>
32 #include <gtkmm2ext/click_box.h>
33 #include <gtkmm2ext/tearoff.h>
35 #include "ardour/session.h"
36 #include "ardour/audioengine.h"
37 #include "ardour/ardour.h"
38 #include "ardour/profile.h"
39 #include "ardour/route.h"
41 #include "ardour_ui.h"
42 #include "keyboard.h"
43 #include "public_editor.h"
44 #include "audio_clock.h"
45 #include "actions.h"
46 #include "utils.h"
47 #include "theme_manager.h"
49 #include "i18n.h"
51 using namespace std;
52 using namespace ARDOUR;
53 using namespace PBD;
54 using namespace Gtkmm2ext;
55 using namespace Gtk;
56 using namespace Glib;
58 int
59 ARDOUR_UI::setup_windows ()
61 if (create_editor ()) {
62 error << _("UI: cannot setup editor") << endmsg;
63 return -1;
66 if (create_mixer ()) {
67 error << _("UI: cannot setup mixer") << endmsg;
68 return -1;
71 /* all other dialogs are created conditionally */
73 we_have_dependents ();
75 theme_manager->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleThemeManager")));
77 #ifdef TOP_MENUBAR
78 HBox* status_bar_packer = manage (new HBox);
80 status_bar_label.set_size_request (300, -1);
81 status_bar_packer->pack_start (status_bar_label, true, true, 6);
82 status_bar_packer->pack_start (error_log_button, false, false);
84 error_log_button.signal_clicked().connect (sigc::mem_fun (*this, &UI::toggle_errors));
86 editor->get_status_bar_packer().pack_start (*status_bar_packer, true, true);
87 editor->get_status_bar_packer().pack_start (menu_bar_base, false, false, 6);
88 #else
89 top_packer.pack_start (menu_bar_base, false, false);
90 #endif
92 top_packer.pack_start (transport_frame, false, false);
94 editor->add_toplevel_controls (top_packer);
96 setup_clock ();
97 setup_transport();
98 build_menu_bar ();
100 setup_tooltips ();
102 return 0;
105 void
106 ARDOUR_UI::setup_tooltips ()
108 set_tip (roll_button, _("Play from playhead"));
109 set_tip (stop_button, _("Stop playback"));
110 set_tip (rec_button, _("Toggle record"));
111 set_tip (play_selection_button, _("Play range/selection"));
112 set_tip (join_play_range_button, _("Always play range/selection"));
113 set_tip (goto_start_button, _("Go to start of session"));
114 set_tip (goto_end_button, _("Go to end of session"));
115 set_tip (auto_loop_button, _("Play loop range"));
117 set_tip (auto_return_button, _("Return to last playback start when stopped"));
118 set_tip (auto_play_button, _("Start playback after any locate"));
119 set_tip (auto_input_button, _("Be sensible about input monitoring"));
120 set_tip (punch_in_button, _("Start recording at auto-punch start"));
121 set_tip (punch_out_button, _("Stop recording at auto-punch end"));
122 set_tip (click_button, _("Enable/Disable audio click"));
123 set_tip (sync_button, _("Enable/Disable external positional sync"));
124 set_tip (time_master_button, string_compose (_("Does %1 control the time?"), PROGRAM_NAME));
125 set_tip (shuttle_box, _("Shuttle speed control"));
126 set_tip (shuttle_units_button, _("Select semitones or %%-age for speed display"));
127 set_tip (speed_display_box, _("Current transport speed"));
128 set_tip (solo_alert_button, _("When active, something is soloed.\nClick to de-solo everything"));
129 set_tip (auditioning_alert_button, _("When active, auditioning is taking place\nClick to stop the audition"));
130 set_tip (primary_clock, _("Primary clock"));
131 set_tip (secondary_clock, _("secondary clock"));
133 editor->setup_tooltips ();
136 void
137 ARDOUR_UI::display_message (const char *prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
139 ustring text;
141 UI::display_message (prefix, prefix_len, ptag, mtag, msg);
142 #ifdef TOP_MENUBAR
144 if (strcmp (prefix, _("[ERROR]: ")) == 0) {
145 text = "<span color=\"red\" weight=\"bold\">";
146 } else if (strcmp (prefix, _("[WARNING]: ")) == 0) {
147 text = "<span color=\"yellow\" weight=\"bold\">";
148 } else if (strcmp (prefix, _("[INFO]: ")) == 0) {
149 text = "<span color=\"green\" weight=\"bold\">";
150 } else {
151 text = "<span color=\"white\" weight=\"bold\">???";
154 text += prefix;
155 text += "</span>";
156 text += msg;
158 status_bar_label.set_markup (text);
159 #endif
162 #if 0
163 static bool
164 null_crossing (GdkEventCrossing* /* ignored */)
166 return true;
169 static void
170 block_prelight (Gtk::Widget& w)
172 w.signal_enter_notify_event().connect (sigc::ptr_fun (null_crossing), false);
173 w.signal_leave_notify_event().connect (sigc::ptr_fun (null_crossing), false);
175 #endif
177 XMLNode*
178 ARDOUR_UI::tearoff_settings (const char* name) const
180 XMLNode* ui_node = Config->extra_xml(X_("UI"));
182 if (ui_node) {
183 XMLNode* tearoff_node = ui_node->child (X_("Tearoffs"));
184 if (tearoff_node) {
185 XMLNode* mnode = tearoff_node->child (name);
186 return mnode;
190 return 0;
193 void
194 ARDOUR_UI::setup_transport ()
196 transport_tearoff = manage (new TearOff (transport_tearoff_hbox));
197 transport_tearoff->set_name ("TransportBase");
198 transport_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &transport_tearoff->tearoff_window()), false);
200 if (Profile->get_sae()) {
201 transport_tearoff->set_can_be_torn_off (false);
204 transport_hbox.pack_start (*transport_tearoff, true, false);
206 transport_base.set_name ("TransportBase");
207 transport_base.add (transport_hbox);
209 transport_frame.set_shadow_type (SHADOW_OUT);
210 transport_frame.set_name ("BaseFrame");
211 transport_frame.add (transport_base);
213 transport_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::detach_tearoff), static_cast<Box*>(&top_packer),
214 static_cast<Widget*>(&transport_frame)));
215 transport_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::reattach_tearoff), static_cast<Box*> (&top_packer),
216 static_cast<Widget*> (&transport_frame), 1));
217 transport_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::detach_tearoff), static_cast<Box*>(&top_packer),
218 static_cast<Widget*>(&transport_frame)));
219 transport_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::reattach_tearoff), static_cast<Box*> (&top_packer),
220 static_cast<Widget*> (&transport_frame), 1));
222 shuttle_box.set_name ("TransportButton");
223 goto_start_button.set_name ("TransportButton");
224 goto_end_button.set_name ("TransportButton");
225 roll_button.set_name ("TransportButton");
226 stop_button.set_name ("TransportButton");
227 play_selection_button.set_name ("TransportButton");
228 rec_button.set_name ("TransportRecButton");
229 auto_loop_button.set_name ("TransportButton");
230 join_play_range_button.set_name ("TransportButton");
232 auto_return_button.set_name ("TransportButton");
233 auto_play_button.set_name ("TransportButton");
234 auto_input_button.set_name ("TransportButton");
235 punch_in_button.set_name ("TransportButton");
236 punch_out_button.set_name ("TransportButton");
237 click_button.set_name ("TransportButton");
238 time_master_button.set_name ("TransportButton");
239 sync_button.set_name ("TransportSyncButton");
241 stop_button.set_size_request(29, -1);
242 roll_button.set_size_request(29, -1);
243 auto_loop_button.set_size_request(29, -1);
244 play_selection_button.set_size_request(29, -1);
245 goto_start_button.set_size_request(29, -1);
246 goto_end_button.set_size_request(29, -1);
247 rec_button.set_size_request(29, -1);
249 Widget* w;
251 stop_button.set_visual_state (1);
253 w = manage (new Image (get_icon (X_("transport_start"))));
254 w->show();
255 goto_start_button.add (*w);
256 w = manage (new Image (get_icon (X_("transport_end"))));
257 w->show();
258 goto_end_button.add (*w);
259 w = manage (new Image (get_icon (X_("transport_play"))));
260 w->show();
261 roll_button.add (*w);
262 w = manage (new Image (get_icon (X_("transport_stop"))));
263 w->show();
264 stop_button.add (*w);
265 w = manage (new Image (get_icon (X_("transport_range"))));
266 w->show();
267 play_selection_button.add (*w);
268 w = manage (new Image (get_icon (X_("transport_record"))));
269 w->show();
270 rec_button.add (*w);
271 w = manage (new Image (get_icon (X_("transport_loop"))));
272 w->show();
273 auto_loop_button.add (*w);
274 w = manage (new Image (get_icon (X_("join_tools"))));
275 w->show ();
276 join_play_range_button.add (*w);
278 RefPtr<Action> act;
280 act = ActionManager::get_action (X_("Transport"), X_("Stop"));
281 act->connect_proxy (stop_button);
282 act = ActionManager::get_action (X_("Transport"), X_("Roll"));
283 act->connect_proxy (roll_button);
284 act = ActionManager::get_action (X_("Transport"), X_("Record"));
285 act->connect_proxy (rec_button);
286 act = ActionManager::get_action (X_("Transport"), X_("GotoStart"));
287 act->connect_proxy (goto_start_button);
288 act = ActionManager::get_action (X_("Transport"), X_("GotoEnd"));
289 act->connect_proxy (goto_end_button);
290 act = ActionManager::get_action (X_("Transport"), X_("Loop"));
291 act->connect_proxy (auto_loop_button);
292 act = ActionManager::get_action (X_("Transport"), X_("PlaySelection"));
293 act->connect_proxy (play_selection_button);
294 act = ActionManager::get_action (X_("Transport"), X_("ToggleTimeMaster"));
295 act->connect_proxy (time_master_button);
296 act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
297 act->connect_proxy (sync_button);
299 shuttle_box.set_flags (CAN_FOCUS);
300 shuttle_box.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::POINTER_MOTION_MASK|Gdk::SCROLL_MASK);
301 shuttle_box.set_size_request (100, 15);
303 shuttle_box.signal_button_press_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_button_press));
304 shuttle_box.signal_button_release_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_button_release));
305 shuttle_box.signal_scroll_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_scroll));
306 shuttle_box.signal_motion_notify_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_motion));
307 shuttle_box.signal_expose_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_expose));
309 /* clocks, etc. */
311 ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (primary_clock, &AudioClock::set), 'p'));
312 ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (secondary_clock, &AudioClock::set), 's'));
314 primary_clock.ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::primary_clock_value_changed));
315 secondary_clock.ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::secondary_clock_value_changed));
316 big_clock.ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::big_clock_value_changed));
318 ActionManager::get_action ("Transport", "ToggleAutoReturn")->connect_proxy (auto_return_button);
319 ActionManager::get_action ("Transport", "ToggleAutoPlay")->connect_proxy (auto_play_button);
320 ActionManager::get_action ("Transport", "ToggleAutoInput")->connect_proxy (auto_input_button);
321 ActionManager::get_action ("Transport", "ToggleClick")->connect_proxy (click_button);
322 ActionManager::get_action ("Transport", "TogglePunchIn")->connect_proxy (punch_in_button);
323 ActionManager::get_action ("Transport", "TogglePunchOut")->connect_proxy (punch_out_button);
325 preroll_button.set_name ("TransportButton");
326 postroll_button.set_name ("TransportButton");
328 preroll_clock.set_mode (AudioClock::MinSec);
329 preroll_clock.set_name ("TransportClockDisplay");
330 postroll_clock.set_mode (AudioClock::MinSec);
331 postroll_clock.set_name ("TransportClockDisplay");
333 /* alerts */
335 /* CANNOT sigc::bind these to clicked or toggled, must use pressed or released */
337 solo_alert_button.set_name ("TransportSoloAlert");
338 solo_alert_button.signal_button_press_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::solo_alert_press), false);
339 auditioning_alert_button.set_name ("TransportAuditioningAlert");
340 auditioning_alert_button.signal_button_press_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::audition_alert_press), false);
342 alert_box.pack_start (solo_alert_button, false, false);
343 alert_box.pack_start (auditioning_alert_button, false, false);
345 transport_tearoff_hbox.set_border_width (3);
347 transport_tearoff_hbox.pack_start (goto_start_button, false, false);
348 transport_tearoff_hbox.pack_start (goto_end_button, false, false);
350 Frame* sframe = manage (new Frame);
351 VBox* svbox = manage (new VBox);
352 HBox* shbox = manage (new HBox);
354 sframe->set_shadow_type (SHADOW_IN);
355 sframe->add (shuttle_box);
357 shuttle_box.set_name (X_("ShuttleControl"));
359 speed_display_box.add (speed_display_label);
360 speed_display_box.set_name (X_("ShuttleDisplay"));
361 set_size_request_to_display_given_text (speed_display_label, X_("> 24.0"), 2, 2);
363 shuttle_units_button.set_name (X_("ShuttleButton"));
364 shuttle_units_button.signal_clicked().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_unit_clicked));
366 shuttle_style_button.set_name (X_("ShuttleStyleButton"));
368 vector<string> shuttle_strings;
369 shuttle_strings.push_back (_("sprung"));
370 shuttle_strings.push_back (_("wheel"));
371 set_popdown_strings (shuttle_style_button, shuttle_strings, true);
372 shuttle_style_button.signal_changed().connect (sigc::mem_fun (*this, &ARDOUR_UI::shuttle_style_changed));
374 Frame* sdframe = manage (new Frame);
376 sdframe->set_shadow_type (SHADOW_IN);
377 sdframe->add (speed_display_box);
379 /* translators: Egternal is "External" with a descender character */
380 set_size_request_to_display_given_text (sync_button, X_("Egternal"), 4, 10);
382 shbox->pack_start (*sdframe, false, false);
383 shbox->pack_start (shuttle_units_button, true, true);
384 shbox->pack_start (shuttle_style_button, false, false);
386 svbox->pack_start (*sframe, false, false);
387 svbox->pack_start (*shbox, false, false);
389 transport_tearoff_hbox.pack_start (*svbox, false, false, 3);
391 if (Profile->get_sae()) {
392 transport_tearoff_hbox.pack_start (auto_loop_button);
393 transport_tearoff_hbox.pack_start (roll_button);
394 } else {
395 transport_tearoff_hbox.pack_start (auto_loop_button, false, false);
396 play_range_hbox.pack_start (play_selection_button, false, false);
397 play_range_hbox.pack_start (roll_button, false, false);
398 play_range_vbox.pack_start (play_range_hbox, false, false);
399 play_range_vbox.pack_start (join_play_range_button, false, false);
400 transport_tearoff_hbox.pack_start (play_range_vbox, false, false);
402 transport_tearoff_hbox.pack_start (stop_button, false, false);
403 transport_tearoff_hbox.pack_start (rec_button, false, false, 6);
405 HBox* clock_box = manage (new HBox);
406 clock_box->pack_start (primary_clock, false, false);
407 if (!ARDOUR::Profile->get_small_screen()) {
408 clock_box->pack_start (secondary_clock, false, false);
411 if (!Profile->get_sae()) {
412 VBox* time_controls_box = manage (new VBox);
413 time_controls_box->pack_start (sync_button, false, false);
414 time_controls_box->pack_start (time_master_button, false, false);
415 clock_box->pack_start (*time_controls_box, false, false, 1);
418 transport_tearoff_hbox.pack_start (*clock_box, false, false, 0);
420 HBox* toggle_box = manage(new HBox);
422 VBox* punch_box = manage (new VBox);
423 punch_box->pack_start (punch_in_button, false, false);
424 punch_box->pack_start (punch_out_button, false, false);
425 toggle_box->pack_start (*punch_box, false, false);
427 VBox* auto_box = manage (new VBox);
428 auto_box->pack_start (auto_play_button, false, false);
429 auto_box->pack_start (auto_return_button, false, false);
430 toggle_box->pack_start (*auto_box, false, false);
432 VBox* io_box = manage (new VBox);
433 io_box->pack_start (auto_input_button, false, false);
434 io_box->pack_start (click_button, false, false);
435 toggle_box->pack_start (*io_box, false, false);
437 /* desensitize */
439 set_transport_sensitivity (false);
441 // toggle_box->pack_start (preroll_button, false, false);
442 // toggle_box->pack_start (preroll_clock, false, false);
444 // toggle_box->pack_start (postroll_button, false, false);
445 // toggle_box->pack_start (postroll_clock, false, false);
447 transport_tearoff_hbox.pack_start (*toggle_box, false, false, 4);
448 transport_tearoff_hbox.pack_start (alert_box, false, false);
450 if (Profile->get_sae()) {
451 Image* img = manage (new Image ((::get_icon (X_("sae")))));
452 transport_tearoff_hbox.pack_end (*img, false, false, 6);
455 XMLNode* tnode = tearoff_settings ("transport");
456 if (tnode) {
457 transport_tearoff->set_state (*tnode);
461 void
462 ARDOUR_UI::manage_window (Window& win)
464 win.signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), &win));
465 win.signal_enter_notify_event().connect (sigc::bind (sigc::mem_fun (Keyboard::the_keyboard(), &Keyboard::enter_window), &win));
466 win.signal_leave_notify_event().connect (sigc::bind (sigc::mem_fun (Keyboard::the_keyboard(), &Keyboard::leave_window), &win));
469 void
470 ARDOUR_UI::detach_tearoff (Box* b, Widget* w)
472 // editor->ensure_float (transport_tearoff->tearoff_window());
473 b->remove (*w);
476 void
477 ARDOUR_UI::reattach_tearoff (Box* b, Widget* w, int32_t n)
479 b->pack_start (*w);
480 b->reorder_child (*w, n);
483 void
484 ARDOUR_UI::soloing_changed (bool onoff)
486 if (solo_alert_button.get_active() != onoff) {
487 solo_alert_button.set_active (onoff);
491 void
492 ARDOUR_UI::_auditioning_changed (bool onoff)
494 if (auditioning_alert_button.get_active() != onoff) {
495 auditioning_alert_button.set_active (onoff);
496 set_transport_sensitivity (!onoff);
500 void
501 ARDOUR_UI::auditioning_changed (bool onoff)
503 UI::instance()->call_slot (boost::bind (&ARDOUR_UI::_auditioning_changed, this, onoff));
506 bool
507 ARDOUR_UI::audition_alert_press (GdkEventButton* ev)
509 if (_session) {
510 _session->cancel_audition();
512 return true;
515 bool
516 ARDOUR_UI::solo_alert_press (GdkEventButton* ev)
518 if (_session) {
519 if (_session->soloing()) {
520 _session->set_solo (_session->get_routes(), false);
521 } else if (_session->listening()) {
522 _session->set_listen (_session->get_routes(), false);
525 return true;
528 void
529 ARDOUR_UI::solo_blink (bool onoff)
531 if (_session == 0) {
532 return;
535 if (_session->soloing() || _session->listening()) {
536 if (onoff) {
537 solo_alert_button.set_state (STATE_ACTIVE);
538 } else {
539 solo_alert_button.set_state (STATE_NORMAL);
541 } else {
542 solo_alert_button.set_active (false);
543 solo_alert_button.set_state (STATE_NORMAL);
547 void
548 ARDOUR_UI::sync_blink (bool onoff)
550 if (_session == 0 || !_session->config.get_external_sync()) {
551 /* internal sync */
552 sync_button.set_visual_state (0);
553 return;
556 if (!_session->transport_locked()) {
557 /* not locked, so blink on and off according to the onoff argument */
559 if (onoff) {
560 sync_button.set_visual_state (1); // "-active"
561 } else {
562 sync_button.set_visual_state (0); // normal
564 } else {
565 /* locked */
566 sync_button.set_visual_state (1); // "-active"
570 void
571 ARDOUR_UI::audition_blink (bool onoff)
573 if (_session == 0) {
574 return;
577 if (_session->is_auditioning()) {
578 if (onoff) {
579 auditioning_alert_button.set_state (STATE_ACTIVE);
580 } else {
581 auditioning_alert_button.set_state (STATE_NORMAL);
583 } else {
584 auditioning_alert_button.set_active (false);
585 auditioning_alert_button.set_state (STATE_NORMAL);
589 void
590 ARDOUR_UI::build_shuttle_context_menu ()
592 using namespace Menu_Helpers;
594 shuttle_context_menu = new Menu();
595 MenuList& items = shuttle_context_menu->items();
597 Menu* speed_menu = manage (new Menu());
598 MenuList& speed_items = speed_menu->items();
600 RadioMenuItem::Group group;
602 speed_items.push_back (RadioMenuElem (group, "8", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 8.0f)));
603 if (shuttle_max_speed == 8.0) {
604 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
606 speed_items.push_back (RadioMenuElem (group, "6", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 6.0f)));
607 if (shuttle_max_speed == 6.0) {
608 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
610 speed_items.push_back (RadioMenuElem (group, "4", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 4.0f)));
611 if (shuttle_max_speed == 4.0) {
612 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
614 speed_items.push_back (RadioMenuElem (group, "3", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 3.0f)));
615 if (shuttle_max_speed == 3.0) {
616 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
618 speed_items.push_back (RadioMenuElem (group, "2", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 2.0f)));
619 if (shuttle_max_speed == 2.0) {
620 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
622 speed_items.push_back (RadioMenuElem (group, "1.5", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 1.5f)));
623 if (shuttle_max_speed == 1.5) {
624 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
627 items.push_back (MenuElem (_("Maximum speed"), *speed_menu));
630 void
631 ARDOUR_UI::show_shuttle_context_menu ()
633 if (shuttle_context_menu == 0) {
634 build_shuttle_context_menu ();
637 shuttle_context_menu->popup (1, gtk_get_current_event_time());
640 void
641 ARDOUR_UI::set_shuttle_max_speed (float speed)
643 shuttle_max_speed = speed;
646 gint
647 ARDOUR_UI::shuttle_box_button_press (GdkEventButton* ev)
649 if (!_session) {
650 return true;
653 if (shuttle_controller_binding_proxy.button_press_handler (ev)) {
654 return true;
657 if (Keyboard::is_context_menu_event (ev)) {
658 show_shuttle_context_menu ();
659 return true;
662 switch (ev->button) {
663 case 1:
664 shuttle_box.add_modal_grab ();
665 shuttle_grabbed = true;
666 mouse_shuttle (ev->x, true);
667 break;
669 case 2:
670 case 3:
671 return true;
672 break;
675 return true;
678 gint
679 ARDOUR_UI::shuttle_box_button_release (GdkEventButton* ev)
681 if (!_session) {
682 return true;
685 switch (ev->button) {
686 case 1:
687 mouse_shuttle (ev->x, true);
688 shuttle_grabbed = false;
689 shuttle_box.remove_modal_grab ();
690 if (Config->get_shuttle_behaviour() == Sprung) {
691 if (_session->config.get_auto_play() || roll_button.get_visual_state()) {
692 shuttle_fract = SHUTTLE_FRACT_SPEED1;
693 _session->request_transport_speed (1.0);
694 stop_button.set_visual_state (0);
695 roll_button.set_visual_state (1);
696 } else {
697 shuttle_fract = 0;
698 _session->request_transport_speed (0.0);
700 shuttle_box.queue_draw ();
702 return true;
704 case 2:
705 if (_session->transport_rolling()) {
706 shuttle_fract = SHUTTLE_FRACT_SPEED1;
707 _session->request_transport_speed (1.0);
708 stop_button.set_visual_state (0);
709 roll_button.set_visual_state (1);
710 } else {
711 shuttle_fract = 0;
713 shuttle_box.queue_draw ();
714 return true;
716 case 3:
717 default:
718 return true;
722 use_shuttle_fract (true);
724 return true;
727 gint
728 ARDOUR_UI::shuttle_box_scroll (GdkEventScroll* ev)
730 if (!_session) {
731 return true;
734 switch (ev->direction) {
736 case GDK_SCROLL_UP:
737 shuttle_fract += 0.005;
738 break;
739 case GDK_SCROLL_DOWN:
740 shuttle_fract -= 0.005;
741 break;
742 default:
743 /* scroll left/right */
744 return false;
747 use_shuttle_fract (true);
749 return true;
752 gint
753 ARDOUR_UI::shuttle_box_motion (GdkEventMotion* ev)
755 if (!_session || !shuttle_grabbed) {
756 return true;
759 return mouse_shuttle (ev->x, false);
762 gint
763 ARDOUR_UI::mouse_shuttle (double x, bool force)
765 double half_width = shuttle_box.get_width() / 2.0;
766 double distance = x - half_width;
768 if (distance > 0) {
769 distance = min (distance, half_width);
770 } else {
771 distance = max (distance, -half_width);
774 shuttle_fract = distance / half_width;
775 use_shuttle_fract (force);
776 return true;
779 void
780 ARDOUR_UI::set_shuttle_fract (double f)
782 shuttle_fract = f;
783 use_shuttle_fract (false);
786 void
787 ARDOUR_UI::use_shuttle_fract (bool force)
789 microseconds_t now = get_microseconds();
791 /* do not attempt to submit a motion-driven transport speed request
792 more than once per process cycle.
795 if (!force && (last_shuttle_request - now) < (microseconds_t) engine->usecs_per_cycle()) {
796 return;
799 last_shuttle_request = now;
801 if (Config->get_shuttle_units() == Semitones) {
803 const double step = 1.0 / 24.0; // range is 24 semitones up & down
804 double semitones;
805 double speed;
807 semitones = round (shuttle_fract / step);
808 speed = pow (2.0, (semitones / 12.0));
810 _session->request_transport_speed (speed);
812 } else {
814 bool neg;
815 double fract;
817 neg = (shuttle_fract < 0.0);
819 fract = 1 - sqrt (1 - (shuttle_fract * shuttle_fract)); // Formula A1
821 if (neg) {
822 fract = -fract;
825 _session->request_transport_speed (shuttle_max_speed * fract);
828 shuttle_box.queue_draw ();
831 gint
832 ARDOUR_UI::shuttle_box_expose (GdkEventExpose* event)
834 gint x;
835 Glib::RefPtr<Gdk::Window> win (shuttle_box.get_window());
837 /* redraw the background */
839 win->draw_rectangle (shuttle_box.get_style()->get_bg_gc (shuttle_box.get_state()),
840 true,
841 event->area.x, event->area.y,
842 event->area.width, event->area.height);
845 x = (gint) floor ((shuttle_box.get_width() / 2.0) + (0.5 * (shuttle_box.get_width() * shuttle_fract)));
847 /* draw line */
849 win->draw_line (shuttle_box.get_style()->get_fg_gc (shuttle_box.get_state()),
853 shuttle_box.get_height());
854 return true;
857 void
858 ARDOUR_UI::shuttle_unit_clicked ()
860 if (shuttle_unit_menu == 0) {
861 shuttle_unit_menu = dynamic_cast<Menu*> (ActionManager::get_widget ("/ShuttleUnitPopup"));
863 shuttle_unit_menu->popup (1, gtk_get_current_event_time());
866 void
867 ARDOUR_UI::shuttle_style_changed ()
869 ustring str = shuttle_style_button.get_active_text ();
871 if (str == _("sprung")) {
872 Config->set_shuttle_behaviour (Sprung);
873 } else if (str == _("wheel")) {
874 Config->set_shuttle_behaviour (Wheel);
878 void
879 ARDOUR_UI::update_speed_display ()
881 if (!_session) {
882 if (last_speed_displayed != 0) {
883 speed_display_label.set_text (_("stop"));
884 last_speed_displayed = 0;
886 return;
889 char buf[32];
890 float x = _session->transport_speed ();
892 if (x != last_speed_displayed) {
894 if (x != 0) {
895 if (Config->get_shuttle_units() == Percentage) {
896 snprintf (buf, sizeof (buf), "%.2f", x);
897 } else {
899 if (x < 0) {
900 snprintf (buf, sizeof (buf), "< %d", (int) round (12.0 * fast_log2 (-x)));
901 } else {
902 snprintf (buf, sizeof (buf), "> %d", (int) round (12.0 * fast_log2 (x)));
905 speed_display_label.set_text (buf);
906 } else {
907 speed_display_label.set_text (_("stop"));
910 last_speed_displayed = x;
914 void
915 ARDOUR_UI::set_transport_sensitivity (bool yn)
917 ActionManager::set_sensitive (ActionManager::transport_sensitive_actions, yn);
918 shuttle_box.set_sensitive (yn);
921 void
922 ARDOUR_UI::editor_realized ()
924 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
925 Config->map_parameters (pc);
927 set_size_request_to_display_given_text (speed_display_box, _("-0.55"), 2, 2);
928 reset_dpi ();
931 void
932 ARDOUR_UI::maximise_editing_space ()
934 if (!editor) {
935 return;
938 transport_tearoff->set_visible (false);
939 editor->maximise_editing_space ();
942 void
943 ARDOUR_UI::restore_editing_space ()
945 if (!editor) {
946 return;
949 transport_tearoff->set_visible (true);
950 editor->restore_editing_space ();