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.
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"
43 #include "public_editor.h"
44 #include "audio_clock.h"
47 #include "theme_manager.h"
48 #include "midi_tracer.h"
49 #include "global_port_matrix.h"
50 #include "location_ui.h"
55 using namespace ARDOUR;
57 using namespace Gtkmm2ext;
62 ARDOUR_UI::setup_windows ()
64 if (create_editor ()) {
65 error << _("UI: cannot setup editor") << endmsg;
69 if (create_mixer ()) {
70 error << _("UI: cannot setup mixer") << endmsg;
74 /* all other dialogs are created conditionally */
76 we_have_dependents ();
78 theme_manager->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleThemeManager")));
81 HBox* status_bar_packer = manage (new HBox);
82 EventBox* status_bar_event_box = manage (new EventBox);
84 status_bar_event_box->add (status_bar_label);
85 status_bar_event_box->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
86 status_bar_label.set_size_request (300, -1);
87 status_bar_packer->pack_start (*status_bar_event_box, true, true, 6);
88 status_bar_packer->pack_start (error_log_button, false, false);
90 status_bar_label.show ();
91 status_bar_event_box->show ();
92 status_bar_packer->show ();
93 error_log_button.show ();
95 error_log_button.signal_clicked().connect (mem_fun (*this, &UI::toggle_errors));
96 status_bar_event_box->signal_button_press_event().connect (mem_fun (*this, &ARDOUR_UI::status_bar_button_press));
98 editor->get_status_bar_packer().pack_start (*status_bar_packer, true, true);
99 editor->get_status_bar_packer().pack_start (menu_bar_base, false, false, 6);
101 top_packer.pack_start (menu_bar_base, false, false);
104 top_packer.pack_start (transport_frame, false, false);
106 editor->add_toplevel_controls (top_packer);
117 ARDOUR_UI::setup_tooltips ()
119 set_tip (roll_button, _("Play from playhead"));
120 set_tip (stop_button, _("Stop playback"));
121 set_tip (rec_button, _("Toggle record"));
122 set_tip (play_selection_button, _("Play range/selection"));
123 set_tip (join_play_range_button, _("Always play range/selection"));
124 set_tip (goto_start_button, _("Go to start of session"));
125 set_tip (goto_end_button, _("Go to end of session"));
126 set_tip (auto_loop_button, _("Play loop range"));
128 set_tip (auto_return_button, _("Return to last playback start when stopped"));
129 set_tip (auto_play_button, _("Start playback after any locate"));
130 set_tip (auto_input_button, _("Be sensible about input monitoring"));
131 set_tip (punch_in_button, _("Start recording at auto-punch start"));
132 set_tip (punch_out_button, _("Stop recording at auto-punch end"));
133 set_tip (click_button, _("Enable/Disable audio click"));
134 set_tip (time_master_button, string_compose (_("Does %1 control the time?"), PROGRAM_NAME));
135 set_tip (shuttle_box, _("Shuttle speed control"));
136 set_tip (shuttle_units_button, _("Select semitones or %%-age for speed display"));
137 set_tip (speed_display_box, _("Current transport speed"));
138 set_tip (solo_alert_button, _("When active, something is soloed.\nClick to de-solo everything"));
139 set_tip (auditioning_alert_button, _("When active, auditioning is taking place\nClick to stop the audition"));
140 set_tip (primary_clock, _("Primary Clock"));
141 set_tip (secondary_clock, _("Secondary Clock"));
143 synchronize_sync_source_and_video_pullup ();
145 editor->setup_tooltips ();
149 ARDOUR_UI::status_bar_button_press (GdkEventButton* ev)
151 bool handled = false;
153 switch (ev->button) {
155 status_bar_label.set_text ("");
166 ARDOUR_UI::display_message (const char *prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
170 UI::display_message (prefix, prefix_len, ptag, mtag, msg);
173 if (strcmp (prefix, _("[ERROR]: ")) == 0) {
174 text = "<span color=\"red\" weight=\"bold\">";
175 } else if (strcmp (prefix, _("[WARNING]: ")) == 0) {
176 text = "<span color=\"yellow\" weight=\"bold\">";
177 } else if (strcmp (prefix, _("[INFO]: ")) == 0) {
178 text = "<span color=\"green\" weight=\"bold\">";
180 text = "<span color=\"white\" weight=\"bold\">???";
187 status_bar_label.set_markup (text);
192 ARDOUR_UI::tearoff_settings (const char* name) const
194 XMLNode* ui_node = Config->extra_xml(X_("UI"));
197 XMLNode* tearoff_node = ui_node->child (X_("Tearoffs"));
199 XMLNode* mnode = tearoff_node->child (name);
208 ARDOUR_UI::setup_transport ()
210 transport_tearoff = manage (new TearOff (transport_tearoff_hbox));
211 transport_tearoff->set_name ("TransportBase");
212 transport_tearoff->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), &transport_tearoff->tearoff_window()), false);
214 if (Profile->get_sae()) {
215 transport_tearoff->set_can_be_torn_off (false);
218 transport_hbox.pack_start (*transport_tearoff, true, false);
220 transport_base.set_name ("TransportBase");
221 transport_base.add (transport_hbox);
223 transport_frame.set_shadow_type (SHADOW_OUT);
224 transport_frame.set_name ("BaseFrame");
225 transport_frame.add (transport_base);
227 transport_tearoff->Detach.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::detach_tearoff), static_cast<Box*>(&top_packer),
228 static_cast<Widget*>(&transport_frame)));
229 transport_tearoff->Attach.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::reattach_tearoff), static_cast<Box*> (&top_packer),
230 static_cast<Widget*> (&transport_frame), 1));
231 transport_tearoff->Hidden.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::detach_tearoff), static_cast<Box*>(&top_packer),
232 static_cast<Widget*>(&transport_frame)));
233 transport_tearoff->Visible.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::reattach_tearoff), static_cast<Box*> (&top_packer),
234 static_cast<Widget*> (&transport_frame), 1));
236 shuttle_box.set_name ("TransportButton");
237 goto_start_button.set_name ("TransportButton");
238 goto_end_button.set_name ("TransportButton");
239 roll_button.set_name ("TransportButton");
240 stop_button.set_name ("TransportButton");
241 play_selection_button.set_name ("TransportButton");
242 rec_button.set_name ("TransportRecButton");
243 auto_loop_button.set_name ("TransportButton");
244 join_play_range_button.set_name ("TransportButton");
246 auto_return_button.set_name ("TransportButton");
247 auto_play_button.set_name ("TransportButton");
248 auto_input_button.set_name ("TransportButton");
249 punch_in_button.set_name ("TransportButton");
250 punch_out_button.set_name ("TransportButton");
251 click_button.set_name ("TransportButton");
252 time_master_button.set_name ("TransportButton");
253 sync_button.set_name ("TransportSyncButton");
255 stop_button.set_size_request(29, -1);
256 roll_button.set_size_request(29, -1);
257 auto_loop_button.set_size_request(29, -1);
258 play_selection_button.set_size_request(29, -1);
259 goto_start_button.set_size_request(29, -1);
260 goto_end_button.set_size_request(29, -1);
261 rec_button.set_size_request(29, -1);
265 stop_button.set_visual_state (1);
267 w = manage (new Image (get_icon (X_("transport_start"))));
269 goto_start_button.add (*w);
270 w = manage (new Image (get_icon (X_("transport_end"))));
272 goto_end_button.add (*w);
273 w = manage (new Image (get_icon (X_("transport_play"))));
275 roll_button.add (*w);
276 w = manage (new Image (get_icon (X_("transport_stop"))));
278 stop_button.add (*w);
279 w = manage (new Image (get_icon (X_("transport_range"))));
281 play_selection_button.add (*w);
282 w = manage (new Image (get_icon (X_("transport_record"))));
285 w = manage (new Image (get_icon (X_("transport_loop"))));
287 auto_loop_button.add (*w);
288 w = manage (new Image (get_icon (X_("join_tools"))));
290 join_play_range_button.add (*w);
294 act = ActionManager::get_action (X_("Transport"), X_("Stop"));
295 act->connect_proxy (stop_button);
296 act = ActionManager::get_action (X_("Transport"), X_("Roll"));
297 act->connect_proxy (roll_button);
298 act = ActionManager::get_action (X_("Transport"), X_("Record"));
299 act->connect_proxy (rec_button);
300 act = ActionManager::get_action (X_("Transport"), X_("GotoStart"));
301 act->connect_proxy (goto_start_button);
302 act = ActionManager::get_action (X_("Transport"), X_("GotoEnd"));
303 act->connect_proxy (goto_end_button);
304 act = ActionManager::get_action (X_("Transport"), X_("Loop"));
305 act->connect_proxy (auto_loop_button);
306 act = ActionManager::get_action (X_("Transport"), X_("PlaySelection"));
307 act->connect_proxy (play_selection_button);
308 act = ActionManager::get_action (X_("Transport"), X_("ToggleTimeMaster"));
309 act->connect_proxy (time_master_button);
310 act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
311 act->connect_proxy (sync_button);
313 shuttle_box.set_flags (CAN_FOCUS);
314 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);
315 shuttle_box.set_size_request (100, 15);
317 shuttle_box.signal_button_press_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_button_press));
318 shuttle_box.signal_button_release_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_button_release));
319 shuttle_box.signal_scroll_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_scroll));
320 shuttle_box.signal_motion_notify_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_motion));
321 shuttle_box.signal_expose_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_expose));
325 ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (primary_clock, &AudioClock::set), 'p'));
326 ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (secondary_clock, &AudioClock::set), 's'));
328 primary_clock.ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::primary_clock_value_changed));
329 secondary_clock.ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::secondary_clock_value_changed));
330 big_clock.ValueChanged.connect (sigc::mem_fun(*this, &ARDOUR_UI::big_clock_value_changed));
332 ActionManager::get_action ("Transport", "ToggleAutoReturn")->connect_proxy (auto_return_button);
333 ActionManager::get_action ("Transport", "ToggleAutoPlay")->connect_proxy (auto_play_button);
334 ActionManager::get_action ("Transport", "ToggleAutoInput")->connect_proxy (auto_input_button);
335 ActionManager::get_action ("Transport", "ToggleClick")->connect_proxy (click_button);
336 ActionManager::get_action ("Transport", "TogglePunchIn")->connect_proxy (punch_in_button);
337 ActionManager::get_action ("Transport", "TogglePunchOut")->connect_proxy (punch_out_button);
339 preroll_button.set_name ("TransportButton");
340 postroll_button.set_name ("TransportButton");
342 preroll_clock.set_mode (AudioClock::MinSec);
343 preroll_clock.set_name ("TransportClockDisplay");
344 postroll_clock.set_mode (AudioClock::MinSec);
345 postroll_clock.set_name ("TransportClockDisplay");
349 /* CANNOT sigc::bind these to clicked or toggled, must use pressed or released */
351 solo_alert_button.set_name ("TransportSoloAlert");
352 solo_alert_button.signal_button_press_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::solo_alert_press), false);
353 auditioning_alert_button.set_name ("TransportAuditioningAlert");
354 auditioning_alert_button.signal_button_press_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::audition_alert_press), false);
356 alert_box.pack_start (solo_alert_button, false, false);
357 alert_box.pack_start (auditioning_alert_button, false, false);
359 transport_tearoff_hbox.set_border_width (3);
361 transport_tearoff_hbox.pack_start (goto_start_button, false, false);
362 transport_tearoff_hbox.pack_start (goto_end_button, false, false);
364 Frame* sframe = manage (new Frame);
365 VBox* svbox = manage (new VBox);
366 HBox* shbox = manage (new HBox);
368 sframe->set_shadow_type (SHADOW_IN);
369 sframe->add (shuttle_box);
371 shuttle_box.set_name (X_("ShuttleControl"));
373 speed_display_box.add (speed_display_label);
374 speed_display_box.set_name (X_("ShuttleDisplay"));
375 set_size_request_to_display_given_text (speed_display_label, X_("> 24.0"), 2, 2);
377 shuttle_units_button.set_name (X_("ShuttleButton"));
378 shuttle_units_button.signal_clicked().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_unit_clicked));
380 shuttle_style_button.set_name (X_("ShuttleStyleButton"));
382 vector<string> shuttle_strings;
383 shuttle_strings.push_back (_("sprung"));
384 shuttle_strings.push_back (_("wheel"));
385 set_popdown_strings (shuttle_style_button, shuttle_strings, true);
386 shuttle_style_button.signal_changed().connect (sigc::mem_fun (*this, &ARDOUR_UI::shuttle_style_changed));
388 Frame* sdframe = manage (new Frame);
390 sdframe->set_shadow_type (SHADOW_IN);
391 sdframe->add (speed_display_box);
393 /* translators: Egternal is "External" with a descender character */
394 set_size_request_to_display_given_text (sync_button, X_("Egternal"), 4, 10);
396 shbox->pack_start (*sdframe, false, false);
397 shbox->pack_start (shuttle_units_button, true, true);
398 shbox->pack_start (shuttle_style_button, false, false);
400 svbox->pack_start (*sframe, false, false);
401 svbox->pack_start (*shbox, false, false);
403 transport_tearoff_hbox.pack_start (*svbox, false, false, 3);
405 if (Profile->get_sae()) {
406 transport_tearoff_hbox.pack_start (auto_loop_button);
407 transport_tearoff_hbox.pack_start (roll_button);
409 transport_tearoff_hbox.pack_start (auto_loop_button, false, false);
410 play_range_hbox.pack_start (play_selection_button, false, false);
411 play_range_hbox.pack_start (roll_button, false, false);
412 play_range_vbox.pack_start (play_range_hbox, false, false);
413 play_range_vbox.pack_start (join_play_range_button, false, false);
414 transport_tearoff_hbox.pack_start (play_range_vbox, false, false);
416 transport_tearoff_hbox.pack_start (stop_button, false, false);
417 transport_tearoff_hbox.pack_start (rec_button, false, false, 6);
419 HBox* clock_box = manage (new HBox);
420 clock_box->pack_start (primary_clock, false, false);
421 if (!ARDOUR::Profile->get_small_screen()) {
422 clock_box->pack_start (secondary_clock, false, false);
425 if (!Profile->get_sae()) {
426 VBox* time_controls_box = manage (new VBox);
427 time_controls_box->pack_start (sync_button, false, false);
428 time_controls_box->pack_start (time_master_button, false, false);
429 clock_box->pack_start (*time_controls_box, false, false, 1);
432 transport_tearoff_hbox.pack_start (*clock_box, false, false, 0);
434 HBox* toggle_box = manage(new HBox);
436 VBox* punch_box = manage (new VBox);
437 punch_box->pack_start (punch_in_button, false, false);
438 punch_box->pack_start (punch_out_button, false, false);
439 toggle_box->pack_start (*punch_box, false, false);
441 VBox* auto_box = manage (new VBox);
442 auto_box->pack_start (auto_play_button, false, false);
443 auto_box->pack_start (auto_return_button, false, false);
444 toggle_box->pack_start (*auto_box, false, false);
446 VBox* io_box = manage (new VBox);
447 io_box->pack_start (auto_input_button, false, false);
448 io_box->pack_start (click_button, false, false);
449 toggle_box->pack_start (*io_box, false, false);
453 set_transport_sensitivity (false);
455 // toggle_box->pack_start (preroll_button, false, false);
456 // toggle_box->pack_start (preroll_clock, false, false);
458 // toggle_box->pack_start (postroll_button, false, false);
459 // toggle_box->pack_start (postroll_clock, false, false);
461 transport_tearoff_hbox.pack_start (*toggle_box, false, false, 4);
462 transport_tearoff_hbox.pack_start (alert_box, false, false);
464 if (Profile->get_sae()) {
465 Image* img = manage (new Image ((::get_icon (X_("sae")))));
466 transport_tearoff_hbox.pack_end (*img, false, false, 6);
469 XMLNode* tnode = tearoff_settings ("transport");
471 transport_tearoff->set_state (*tnode);
476 ARDOUR_UI::manage_window (Window& win)
478 win.signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), &win));
479 win.signal_enter_notify_event().connect (sigc::bind (sigc::mem_fun (Keyboard::the_keyboard(), &Keyboard::enter_window), &win));
480 win.signal_leave_notify_event().connect (sigc::bind (sigc::mem_fun (Keyboard::the_keyboard(), &Keyboard::leave_window), &win));
484 ARDOUR_UI::detach_tearoff (Box* b, Widget* w)
486 // editor->ensure_float (transport_tearoff->tearoff_window());
491 ARDOUR_UI::reattach_tearoff (Box* b, Widget* w, int32_t n)
494 b->reorder_child (*w, n);
498 ARDOUR_UI::soloing_changed (bool onoff)
500 if (solo_alert_button.get_active() != onoff) {
501 solo_alert_button.set_active (onoff);
506 ARDOUR_UI::_auditioning_changed (bool onoff)
508 if (auditioning_alert_button.get_active() != onoff) {
509 auditioning_alert_button.set_active (onoff);
510 set_transport_sensitivity (!onoff);
515 ARDOUR_UI::auditioning_changed (bool onoff)
517 UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::_auditioning_changed, this, onoff));
521 ARDOUR_UI::audition_alert_press (GdkEventButton*)
524 _session->cancel_audition();
530 ARDOUR_UI::solo_alert_press (GdkEventButton*)
533 if (_session->soloing()) {
534 _session->set_solo (_session->get_routes(), false);
535 } else if (_session->listening()) {
536 _session->set_listen (_session->get_routes(), false);
543 ARDOUR_UI::solo_blink (bool onoff)
549 if (_session->soloing() || _session->listening()) {
551 solo_alert_button.set_state (STATE_ACTIVE);
553 solo_alert_button.set_state (STATE_NORMAL);
556 solo_alert_button.set_active (false);
557 solo_alert_button.set_state (STATE_NORMAL);
562 ARDOUR_UI::sync_blink (bool onoff)
564 if (_session == 0 || !_session->config.get_external_sync()) {
566 sync_button.set_visual_state (0);
570 if (!_session->transport_locked()) {
571 /* not locked, so blink on and off according to the onoff argument */
574 sync_button.set_visual_state (1); // "-active"
576 sync_button.set_visual_state (0); // normal
580 sync_button.set_visual_state (1); // "-active"
585 ARDOUR_UI::audition_blink (bool onoff)
591 if (_session->is_auditioning()) {
593 auditioning_alert_button.set_state (STATE_ACTIVE);
595 auditioning_alert_button.set_state (STATE_NORMAL);
598 auditioning_alert_button.set_active (false);
599 auditioning_alert_button.set_state (STATE_NORMAL);
604 ARDOUR_UI::build_shuttle_context_menu ()
606 using namespace Menu_Helpers;
608 shuttle_context_menu = new Menu();
609 MenuList& items = shuttle_context_menu->items();
611 Menu* speed_menu = manage (new Menu());
612 MenuList& speed_items = speed_menu->items();
614 RadioMenuItem::Group group;
616 speed_items.push_back (RadioMenuElem (group, "8", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 8.0f)));
617 if (shuttle_max_speed == 8.0) {
618 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
620 speed_items.push_back (RadioMenuElem (group, "6", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 6.0f)));
621 if (shuttle_max_speed == 6.0) {
622 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
624 speed_items.push_back (RadioMenuElem (group, "4", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 4.0f)));
625 if (shuttle_max_speed == 4.0) {
626 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
628 speed_items.push_back (RadioMenuElem (group, "3", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 3.0f)));
629 if (shuttle_max_speed == 3.0) {
630 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
632 speed_items.push_back (RadioMenuElem (group, "2", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 2.0f)));
633 if (shuttle_max_speed == 2.0) {
634 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
636 speed_items.push_back (RadioMenuElem (group, "1.5", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 1.5f)));
637 if (shuttle_max_speed == 1.5) {
638 static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();
641 items.push_back (MenuElem (_("Maximum speed"), *speed_menu));
645 ARDOUR_UI::show_shuttle_context_menu ()
647 if (shuttle_context_menu == 0) {
648 build_shuttle_context_menu ();
651 shuttle_context_menu->popup (1, gtk_get_current_event_time());
655 ARDOUR_UI::set_shuttle_max_speed (float speed)
657 shuttle_max_speed = speed;
661 ARDOUR_UI::shuttle_box_button_press (GdkEventButton* ev)
667 if (shuttle_controller_binding_proxy.button_press_handler (ev)) {
671 if (Keyboard::is_context_menu_event (ev)) {
672 show_shuttle_context_menu ();
676 switch (ev->button) {
678 shuttle_box.add_modal_grab ();
679 shuttle_grabbed = true;
680 mouse_shuttle (ev->x, true);
693 ARDOUR_UI::shuttle_box_button_release (GdkEventButton* ev)
699 switch (ev->button) {
701 mouse_shuttle (ev->x, true);
702 shuttle_grabbed = false;
703 shuttle_box.remove_modal_grab ();
704 if (Config->get_shuttle_behaviour() == Sprung) {
705 if (_session->config.get_auto_play() || roll_button.get_visual_state()) {
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);
712 _session->request_transport_speed (0.0);
714 shuttle_box.queue_draw ();
719 if (_session->transport_rolling()) {
720 shuttle_fract = SHUTTLE_FRACT_SPEED1;
721 _session->request_transport_speed (1.0);
722 stop_button.set_visual_state (0);
723 roll_button.set_visual_state (1);
727 shuttle_box.queue_draw ();
736 use_shuttle_fract (true);
742 ARDOUR_UI::shuttle_box_scroll (GdkEventScroll* ev)
748 switch (ev->direction) {
751 shuttle_fract += 0.005;
753 case GDK_SCROLL_DOWN:
754 shuttle_fract -= 0.005;
757 /* scroll left/right */
761 use_shuttle_fract (true);
767 ARDOUR_UI::shuttle_box_motion (GdkEventMotion* ev)
769 if (!_session || !shuttle_grabbed) {
773 return mouse_shuttle (ev->x, false);
777 ARDOUR_UI::mouse_shuttle (double x, bool force)
779 double half_width = shuttle_box.get_width() / 2.0;
780 double distance = x - half_width;
783 distance = min (distance, half_width);
785 distance = max (distance, -half_width);
788 shuttle_fract = distance / half_width;
789 use_shuttle_fract (force);
794 ARDOUR_UI::set_shuttle_fract (double f)
797 use_shuttle_fract (false);
801 ARDOUR_UI::use_shuttle_fract (bool force)
803 microseconds_t now = get_microseconds();
805 /* do not attempt to submit a motion-driven transport speed request
806 more than once per process cycle.
809 if (!force && (last_shuttle_request - now) < (microseconds_t) engine->usecs_per_cycle()) {
813 last_shuttle_request = now;
815 if (Config->get_shuttle_units() == Semitones) {
817 const double step = 1.0 / 24.0; // range is 24 semitones up & down
821 semitones = round (shuttle_fract / step);
822 speed = pow (2.0, (semitones / 12.0));
824 _session->request_transport_speed (speed);
831 neg = (shuttle_fract < 0.0);
833 fract = 1 - sqrt (1 - (shuttle_fract * shuttle_fract)); // Formula A1
839 _session->request_transport_speed (shuttle_max_speed * fract);
842 shuttle_box.queue_draw ();
846 ARDOUR_UI::shuttle_box_expose (GdkEventExpose* event)
849 Glib::RefPtr<Gdk::Window> win (shuttle_box.get_window());
851 /* redraw the background */
853 win->draw_rectangle (shuttle_box.get_style()->get_bg_gc (shuttle_box.get_state()),
855 event->area.x, event->area.y,
856 event->area.width, event->area.height);
859 x = (gint) floor ((shuttle_box.get_width() / 2.0) + (0.5 * (shuttle_box.get_width() * shuttle_fract)));
863 win->draw_line (shuttle_box.get_style()->get_fg_gc (shuttle_box.get_state()),
867 shuttle_box.get_height());
872 ARDOUR_UI::shuttle_unit_clicked ()
874 if (shuttle_unit_menu == 0) {
875 shuttle_unit_menu = dynamic_cast<Menu*> (ActionManager::get_widget ("/ShuttleUnitPopup"));
877 shuttle_unit_menu->popup (1, gtk_get_current_event_time());
881 ARDOUR_UI::shuttle_style_changed ()
883 string str = shuttle_style_button.get_active_text ();
885 if (str == _("sprung")) {
886 Config->set_shuttle_behaviour (Sprung);
887 } else if (str == _("wheel")) {
888 Config->set_shuttle_behaviour (Wheel);
893 ARDOUR_UI::update_speed_display ()
896 if (last_speed_displayed != 0) {
897 speed_display_label.set_text (_("stop"));
898 last_speed_displayed = 0;
904 float x = _session->transport_speed ();
906 if (x != last_speed_displayed) {
909 if (Config->get_shuttle_units() == Percentage) {
910 snprintf (buf, sizeof (buf), "%d", (int) round (x * 100));
914 snprintf (buf, sizeof (buf), "< %d", (int) round (12.0 * fast_log2 (-x)));
916 snprintf (buf, sizeof (buf), "> %d", (int) round (12.0 * fast_log2 (x)));
919 speed_display_label.set_text (buf);
921 speed_display_label.set_text (_("stop"));
924 last_speed_displayed = x;
929 ARDOUR_UI::set_transport_sensitivity (bool yn)
931 ActionManager::set_sensitive (ActionManager::transport_sensitive_actions, yn);
932 shuttle_box.set_sensitive (yn);
936 ARDOUR_UI::editor_realized ()
938 boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
939 Config->map_parameters (pc);
941 set_size_request_to_display_given_text (speed_display_box, _("-0.55"), 2, 2);
946 ARDOUR_UI::maximise_editing_space ()
952 transport_tearoff->set_visible (false);
953 editor->maximise_editing_space ();
954 if (Config->get_keep_tearoffs()) {
955 transport_tearoff->set_visible (true);
960 ARDOUR_UI::restore_editing_space ()
966 transport_tearoff->set_visible (true);
967 editor->restore_editing_space ();