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"
53 using namespace ARDOUR
;
55 using namespace Gtkmm2ext
;
60 ARDOUR_UI::setup_windows ()
62 if (create_editor ()) {
63 error
<< _("UI: cannot setup editor") << endmsg
;
67 if (create_mixer ()) {
68 error
<< _("UI: cannot setup mixer") << endmsg
;
72 /* all other dialogs are created conditionally */
74 we_have_dependents ();
76 theme_manager
->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction
), X_("<Actions>/Common/ToggleThemeManager")));
79 HBox
* status_bar_packer
= manage (new HBox
);
80 EventBox
* status_bar_event_box
= manage (new EventBox
);
82 status_bar_event_box
->add (status_bar_label
);
83 status_bar_event_box
->add_events (Gdk::BUTTON_PRESS_MASK
|Gdk::BUTTON_RELEASE_MASK
);
84 status_bar_label
.set_size_request (300, -1);
85 status_bar_packer
->pack_start (*status_bar_event_box
, true, true, 6);
86 status_bar_packer
->pack_start (error_log_button
, false, false);
88 status_bar_label
.show ();
89 status_bar_event_box
->show ();
90 status_bar_packer
->show ();
91 error_log_button
.show ();
93 error_log_button
.signal_clicked().connect (mem_fun (*this, &UI::toggle_errors
));
94 status_bar_event_box
->signal_button_press_event().connect (mem_fun (*this, &ARDOUR_UI::status_bar_button_press
));
96 editor
->get_status_bar_packer().pack_start (*status_bar_packer
, true, true);
97 editor
->get_status_bar_packer().pack_start (menu_bar_base
, false, false, 6);
99 top_packer
.pack_start (menu_bar_base
, false, false);
102 top_packer
.pack_start (transport_frame
, false, false);
104 editor
->add_toplevel_controls (top_packer
);
110 _midi_tracer_window
= new MidiTracer ();
111 manage_window (*_midi_tracer_window
);
119 ARDOUR_UI::setup_tooltips ()
121 set_tip (roll_button
, _("Play from playhead"));
122 set_tip (stop_button
, _("Stop playback"));
123 set_tip (rec_button
, _("Toggle record"));
124 set_tip (play_selection_button
, _("Play range/selection"));
125 set_tip (join_play_range_button
, _("Always play range/selection"));
126 set_tip (goto_start_button
, _("Go to start of session"));
127 set_tip (goto_end_button
, _("Go to end of session"));
128 set_tip (auto_loop_button
, _("Play loop range"));
130 set_tip (auto_return_button
, _("Return to last playback start when stopped"));
131 set_tip (auto_play_button
, _("Start playback after any locate"));
132 set_tip (auto_input_button
, _("Be sensible about input monitoring"));
133 set_tip (punch_in_button
, _("Start recording at auto-punch start"));
134 set_tip (punch_out_button
, _("Stop recording at auto-punch end"));
135 set_tip (click_button
, _("Enable/Disable audio click"));
136 set_tip (sync_button
, _("Enable/Disable external positional sync"));
137 set_tip (time_master_button
, string_compose (_("Does %1 control the time?"), PROGRAM_NAME
));
138 set_tip (shuttle_box
, _("Shuttle speed control"));
139 set_tip (shuttle_units_button
, _("Select semitones or %%-age for speed display"));
140 set_tip (speed_display_box
, _("Current transport speed"));
141 set_tip (solo_alert_button
, _("When active, something is soloed.\nClick to de-solo everything"));
142 set_tip (auditioning_alert_button
, _("When active, auditioning is taking place\nClick to stop the audition"));
143 set_tip (primary_clock
, _("Primary clock"));
144 set_tip (secondary_clock
, _("secondary clock"));
146 editor
->setup_tooltips ();
150 ARDOUR_UI::status_bar_button_press (GdkEventButton
* ev
)
152 bool handled
= false;
154 switch (ev
->button
) {
156 status_bar_label
.set_text ("");
167 ARDOUR_UI::display_message (const char *prefix
, gint prefix_len
, RefPtr
<TextBuffer::Tag
> ptag
, RefPtr
<TextBuffer::Tag
> mtag
, const char *msg
)
171 UI::display_message (prefix
, prefix_len
, ptag
, mtag
, msg
);
174 if (strcmp (prefix
, _("[ERROR]: ")) == 0) {
175 text
= "<span color=\"red\" weight=\"bold\">";
176 } else if (strcmp (prefix
, _("[WARNING]: ")) == 0) {
177 text
= "<span color=\"yellow\" weight=\"bold\">";
178 } else if (strcmp (prefix
, _("[INFO]: ")) == 0) {
179 text
= "<span color=\"green\" weight=\"bold\">";
181 text
= "<span color=\"white\" weight=\"bold\">???";
188 status_bar_label
.set_markup (text
);
193 ARDOUR_UI::tearoff_settings (const char* name
) const
195 XMLNode
* ui_node
= Config
->extra_xml(X_("UI"));
198 XMLNode
* tearoff_node
= ui_node
->child (X_("Tearoffs"));
200 XMLNode
* mnode
= tearoff_node
->child (name
);
209 ARDOUR_UI::setup_transport ()
211 transport_tearoff
= manage (new TearOff (transport_tearoff_hbox
));
212 transport_tearoff
->set_name ("TransportBase");
213 transport_tearoff
->tearoff_window().signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press
), &transport_tearoff
->tearoff_window()), false);
215 if (Profile
->get_sae()) {
216 transport_tearoff
->set_can_be_torn_off (false);
219 transport_hbox
.pack_start (*transport_tearoff
, true, false);
221 transport_base
.set_name ("TransportBase");
222 transport_base
.add (transport_hbox
);
224 transport_frame
.set_shadow_type (SHADOW_OUT
);
225 transport_frame
.set_name ("BaseFrame");
226 transport_frame
.add (transport_base
);
228 transport_tearoff
->Detach
.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::detach_tearoff
), static_cast<Box
*>(&top_packer
),
229 static_cast<Widget
*>(&transport_frame
)));
230 transport_tearoff
->Attach
.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::reattach_tearoff
), static_cast<Box
*> (&top_packer
),
231 static_cast<Widget
*> (&transport_frame
), 1));
232 transport_tearoff
->Hidden
.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::detach_tearoff
), static_cast<Box
*>(&top_packer
),
233 static_cast<Widget
*>(&transport_frame
)));
234 transport_tearoff
->Visible
.connect (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::reattach_tearoff
), static_cast<Box
*> (&top_packer
),
235 static_cast<Widget
*> (&transport_frame
), 1));
237 shuttle_box
.set_name ("TransportButton");
238 goto_start_button
.set_name ("TransportButton");
239 goto_end_button
.set_name ("TransportButton");
240 roll_button
.set_name ("TransportButton");
241 stop_button
.set_name ("TransportButton");
242 play_selection_button
.set_name ("TransportButton");
243 rec_button
.set_name ("TransportRecButton");
244 auto_loop_button
.set_name ("TransportButton");
245 join_play_range_button
.set_name ("TransportButton");
247 auto_return_button
.set_name ("TransportButton");
248 auto_play_button
.set_name ("TransportButton");
249 auto_input_button
.set_name ("TransportButton");
250 punch_in_button
.set_name ("TransportButton");
251 punch_out_button
.set_name ("TransportButton");
252 click_button
.set_name ("TransportButton");
253 time_master_button
.set_name ("TransportButton");
254 sync_button
.set_name ("TransportSyncButton");
256 stop_button
.set_size_request(29, -1);
257 roll_button
.set_size_request(29, -1);
258 auto_loop_button
.set_size_request(29, -1);
259 play_selection_button
.set_size_request(29, -1);
260 goto_start_button
.set_size_request(29, -1);
261 goto_end_button
.set_size_request(29, -1);
262 rec_button
.set_size_request(29, -1);
266 stop_button
.set_visual_state (1);
268 w
= manage (new Image (get_icon (X_("transport_start"))));
270 goto_start_button
.add (*w
);
271 w
= manage (new Image (get_icon (X_("transport_end"))));
273 goto_end_button
.add (*w
);
274 w
= manage (new Image (get_icon (X_("transport_play"))));
276 roll_button
.add (*w
);
277 w
= manage (new Image (get_icon (X_("transport_stop"))));
279 stop_button
.add (*w
);
280 w
= manage (new Image (get_icon (X_("transport_range"))));
282 play_selection_button
.add (*w
);
283 w
= manage (new Image (get_icon (X_("transport_record"))));
286 w
= manage (new Image (get_icon (X_("transport_loop"))));
288 auto_loop_button
.add (*w
);
289 w
= manage (new Image (get_icon (X_("join_tools"))));
291 join_play_range_button
.add (*w
);
295 act
= ActionManager::get_action (X_("Transport"), X_("Stop"));
296 act
->connect_proxy (stop_button
);
297 act
= ActionManager::get_action (X_("Transport"), X_("Roll"));
298 act
->connect_proxy (roll_button
);
299 act
= ActionManager::get_action (X_("Transport"), X_("Record"));
300 act
->connect_proxy (rec_button
);
301 act
= ActionManager::get_action (X_("Transport"), X_("GotoStart"));
302 act
->connect_proxy (goto_start_button
);
303 act
= ActionManager::get_action (X_("Transport"), X_("GotoEnd"));
304 act
->connect_proxy (goto_end_button
);
305 act
= ActionManager::get_action (X_("Transport"), X_("Loop"));
306 act
->connect_proxy (auto_loop_button
);
307 act
= ActionManager::get_action (X_("Transport"), X_("PlaySelection"));
308 act
->connect_proxy (play_selection_button
);
309 act
= ActionManager::get_action (X_("Transport"), X_("ToggleTimeMaster"));
310 act
->connect_proxy (time_master_button
);
311 act
= ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
312 act
->connect_proxy (sync_button
);
314 shuttle_box
.set_flags (CAN_FOCUS
);
315 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
);
316 shuttle_box
.set_size_request (100, 15);
318 shuttle_box
.signal_button_press_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_button_press
));
319 shuttle_box
.signal_button_release_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_button_release
));
320 shuttle_box
.signal_scroll_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_scroll
));
321 shuttle_box
.signal_motion_notify_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_motion
));
322 shuttle_box
.signal_expose_event().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_box_expose
));
326 ARDOUR_UI::Clock
.connect (sigc::bind (sigc::mem_fun (primary_clock
, &AudioClock::set
), 'p'));
327 ARDOUR_UI::Clock
.connect (sigc::bind (sigc::mem_fun (secondary_clock
, &AudioClock::set
), 's'));
329 primary_clock
.ValueChanged
.connect (sigc::mem_fun(*this, &ARDOUR_UI::primary_clock_value_changed
));
330 secondary_clock
.ValueChanged
.connect (sigc::mem_fun(*this, &ARDOUR_UI::secondary_clock_value_changed
));
331 big_clock
.ValueChanged
.connect (sigc::mem_fun(*this, &ARDOUR_UI::big_clock_value_changed
));
333 ActionManager::get_action ("Transport", "ToggleAutoReturn")->connect_proxy (auto_return_button
);
334 ActionManager::get_action ("Transport", "ToggleAutoPlay")->connect_proxy (auto_play_button
);
335 ActionManager::get_action ("Transport", "ToggleAutoInput")->connect_proxy (auto_input_button
);
336 ActionManager::get_action ("Transport", "ToggleClick")->connect_proxy (click_button
);
337 ActionManager::get_action ("Transport", "TogglePunchIn")->connect_proxy (punch_in_button
);
338 ActionManager::get_action ("Transport", "TogglePunchOut")->connect_proxy (punch_out_button
);
340 preroll_button
.set_name ("TransportButton");
341 postroll_button
.set_name ("TransportButton");
343 preroll_clock
.set_mode (AudioClock::MinSec
);
344 preroll_clock
.set_name ("TransportClockDisplay");
345 postroll_clock
.set_mode (AudioClock::MinSec
);
346 postroll_clock
.set_name ("TransportClockDisplay");
350 /* CANNOT sigc::bind these to clicked or toggled, must use pressed or released */
352 solo_alert_button
.set_name ("TransportSoloAlert");
353 solo_alert_button
.signal_button_press_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::solo_alert_press
), false);
354 auditioning_alert_button
.set_name ("TransportAuditioningAlert");
355 auditioning_alert_button
.signal_button_press_event().connect (sigc::mem_fun(*this,&ARDOUR_UI::audition_alert_press
), false);
357 alert_box
.pack_start (solo_alert_button
, false, false);
358 alert_box
.pack_start (auditioning_alert_button
, false, false);
360 transport_tearoff_hbox
.set_border_width (3);
362 transport_tearoff_hbox
.pack_start (goto_start_button
, false, false);
363 transport_tearoff_hbox
.pack_start (goto_end_button
, false, false);
365 Frame
* sframe
= manage (new Frame
);
366 VBox
* svbox
= manage (new VBox
);
367 HBox
* shbox
= manage (new HBox
);
369 sframe
->set_shadow_type (SHADOW_IN
);
370 sframe
->add (shuttle_box
);
372 shuttle_box
.set_name (X_("ShuttleControl"));
374 speed_display_box
.add (speed_display_label
);
375 speed_display_box
.set_name (X_("ShuttleDisplay"));
376 set_size_request_to_display_given_text (speed_display_label
, X_("> 24.0"), 2, 2);
378 shuttle_units_button
.set_name (X_("ShuttleButton"));
379 shuttle_units_button
.signal_clicked().connect (sigc::mem_fun(*this, &ARDOUR_UI::shuttle_unit_clicked
));
381 shuttle_style_button
.set_name (X_("ShuttleStyleButton"));
383 vector
<string
> shuttle_strings
;
384 shuttle_strings
.push_back (_("sprung"));
385 shuttle_strings
.push_back (_("wheel"));
386 set_popdown_strings (shuttle_style_button
, shuttle_strings
, true);
387 shuttle_style_button
.signal_changed().connect (sigc::mem_fun (*this, &ARDOUR_UI::shuttle_style_changed
));
389 Frame
* sdframe
= manage (new Frame
);
391 sdframe
->set_shadow_type (SHADOW_IN
);
392 sdframe
->add (speed_display_box
);
394 /* translators: Egternal is "External" with a descender character */
395 set_size_request_to_display_given_text (sync_button
, X_("Egternal"), 4, 10);
397 shbox
->pack_start (*sdframe
, false, false);
398 shbox
->pack_start (shuttle_units_button
, true, true);
399 shbox
->pack_start (shuttle_style_button
, false, false);
401 svbox
->pack_start (*sframe
, false, false);
402 svbox
->pack_start (*shbox
, false, false);
404 transport_tearoff_hbox
.pack_start (*svbox
, false, false, 3);
406 if (Profile
->get_sae()) {
407 transport_tearoff_hbox
.pack_start (auto_loop_button
);
408 transport_tearoff_hbox
.pack_start (roll_button
);
410 transport_tearoff_hbox
.pack_start (auto_loop_button
, false, false);
411 play_range_hbox
.pack_start (play_selection_button
, false, false);
412 play_range_hbox
.pack_start (roll_button
, false, false);
413 play_range_vbox
.pack_start (play_range_hbox
, false, false);
414 play_range_vbox
.pack_start (join_play_range_button
, false, false);
415 transport_tearoff_hbox
.pack_start (play_range_vbox
, false, false);
417 transport_tearoff_hbox
.pack_start (stop_button
, false, false);
418 transport_tearoff_hbox
.pack_start (rec_button
, false, false, 6);
420 HBox
* clock_box
= manage (new HBox
);
421 clock_box
->pack_start (primary_clock
, false, false);
422 if (!ARDOUR::Profile
->get_small_screen()) {
423 clock_box
->pack_start (secondary_clock
, false, false);
426 if (!Profile
->get_sae()) {
427 VBox
* time_controls_box
= manage (new VBox
);
428 time_controls_box
->pack_start (sync_button
, false, false);
429 time_controls_box
->pack_start (time_master_button
, false, false);
430 clock_box
->pack_start (*time_controls_box
, false, false, 1);
433 transport_tearoff_hbox
.pack_start (*clock_box
, false, false, 0);
435 HBox
* toggle_box
= manage(new HBox
);
437 VBox
* punch_box
= manage (new VBox
);
438 punch_box
->pack_start (punch_in_button
, false, false);
439 punch_box
->pack_start (punch_out_button
, false, false);
440 toggle_box
->pack_start (*punch_box
, false, false);
442 VBox
* auto_box
= manage (new VBox
);
443 auto_box
->pack_start (auto_play_button
, false, false);
444 auto_box
->pack_start (auto_return_button
, false, false);
445 toggle_box
->pack_start (*auto_box
, false, false);
447 VBox
* io_box
= manage (new VBox
);
448 io_box
->pack_start (auto_input_button
, false, false);
449 io_box
->pack_start (click_button
, false, false);
450 toggle_box
->pack_start (*io_box
, false, false);
454 set_transport_sensitivity (false);
456 // toggle_box->pack_start (preroll_button, false, false);
457 // toggle_box->pack_start (preroll_clock, false, false);
459 // toggle_box->pack_start (postroll_button, false, false);
460 // toggle_box->pack_start (postroll_clock, false, false);
462 transport_tearoff_hbox
.pack_start (*toggle_box
, false, false, 4);
463 transport_tearoff_hbox
.pack_start (alert_box
, false, false);
465 if (Profile
->get_sae()) {
466 Image
* img
= manage (new Image ((::get_icon (X_("sae")))));
467 transport_tearoff_hbox
.pack_end (*img
, false, false, 6);
470 XMLNode
* tnode
= tearoff_settings ("transport");
472 transport_tearoff
->set_state (*tnode
);
477 ARDOUR_UI::manage_window (Window
& win
)
479 win
.signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it
), &win
));
480 win
.signal_enter_notify_event().connect (sigc::bind (sigc::mem_fun (Keyboard::the_keyboard(), &Keyboard::enter_window
), &win
));
481 win
.signal_leave_notify_event().connect (sigc::bind (sigc::mem_fun (Keyboard::the_keyboard(), &Keyboard::leave_window
), &win
));
485 ARDOUR_UI::detach_tearoff (Box
* b
, Widget
* w
)
487 // editor->ensure_float (transport_tearoff->tearoff_window());
492 ARDOUR_UI::reattach_tearoff (Box
* b
, Widget
* w
, int32_t n
)
495 b
->reorder_child (*w
, n
);
499 ARDOUR_UI::soloing_changed (bool onoff
)
501 if (solo_alert_button
.get_active() != onoff
) {
502 solo_alert_button
.set_active (onoff
);
507 ARDOUR_UI::_auditioning_changed (bool onoff
)
509 if (auditioning_alert_button
.get_active() != onoff
) {
510 auditioning_alert_button
.set_active (onoff
);
511 set_transport_sensitivity (!onoff
);
516 ARDOUR_UI::auditioning_changed (bool onoff
)
518 UI::instance()->call_slot (MISSING_INVALIDATOR
, boost::bind (&ARDOUR_UI::_auditioning_changed
, this, onoff
));
522 ARDOUR_UI::audition_alert_press (GdkEventButton
* ev
)
525 _session
->cancel_audition();
531 ARDOUR_UI::solo_alert_press (GdkEventButton
* ev
)
534 if (_session
->soloing()) {
535 _session
->set_solo (_session
->get_routes(), false);
536 } else if (_session
->listening()) {
537 _session
->set_listen (_session
->get_routes(), false);
544 ARDOUR_UI::solo_blink (bool onoff
)
550 if (_session
->soloing() || _session
->listening()) {
552 solo_alert_button
.set_state (STATE_ACTIVE
);
554 solo_alert_button
.set_state (STATE_NORMAL
);
557 solo_alert_button
.set_active (false);
558 solo_alert_button
.set_state (STATE_NORMAL
);
563 ARDOUR_UI::sync_blink (bool onoff
)
565 if (_session
== 0 || !_session
->config
.get_external_sync()) {
567 sync_button
.set_visual_state (0);
571 if (!_session
->transport_locked()) {
572 /* not locked, so blink on and off according to the onoff argument */
575 sync_button
.set_visual_state (1); // "-active"
577 sync_button
.set_visual_state (0); // normal
581 sync_button
.set_visual_state (1); // "-active"
586 ARDOUR_UI::audition_blink (bool onoff
)
592 if (_session
->is_auditioning()) {
594 auditioning_alert_button
.set_state (STATE_ACTIVE
);
596 auditioning_alert_button
.set_state (STATE_NORMAL
);
599 auditioning_alert_button
.set_active (false);
600 auditioning_alert_button
.set_state (STATE_NORMAL
);
605 ARDOUR_UI::build_shuttle_context_menu ()
607 using namespace Menu_Helpers
;
609 shuttle_context_menu
= new Menu();
610 MenuList
& items
= shuttle_context_menu
->items();
612 Menu
* speed_menu
= manage (new Menu());
613 MenuList
& speed_items
= speed_menu
->items();
615 RadioMenuItem::Group group
;
617 speed_items
.push_back (RadioMenuElem (group
, "8", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed
), 8.0f
)));
618 if (shuttle_max_speed
== 8.0) {
619 static_cast<RadioMenuItem
*>(&speed_items
.back())->set_active ();
621 speed_items
.push_back (RadioMenuElem (group
, "6", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed
), 6.0f
)));
622 if (shuttle_max_speed
== 6.0) {
623 static_cast<RadioMenuItem
*>(&speed_items
.back())->set_active ();
625 speed_items
.push_back (RadioMenuElem (group
, "4", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed
), 4.0f
)));
626 if (shuttle_max_speed
== 4.0) {
627 static_cast<RadioMenuItem
*>(&speed_items
.back())->set_active ();
629 speed_items
.push_back (RadioMenuElem (group
, "3", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed
), 3.0f
)));
630 if (shuttle_max_speed
== 3.0) {
631 static_cast<RadioMenuItem
*>(&speed_items
.back())->set_active ();
633 speed_items
.push_back (RadioMenuElem (group
, "2", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed
), 2.0f
)));
634 if (shuttle_max_speed
== 2.0) {
635 static_cast<RadioMenuItem
*>(&speed_items
.back())->set_active ();
637 speed_items
.push_back (RadioMenuElem (group
, "1.5", sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed
), 1.5f
)));
638 if (shuttle_max_speed
== 1.5) {
639 static_cast<RadioMenuItem
*>(&speed_items
.back())->set_active ();
642 items
.push_back (MenuElem (_("Maximum speed"), *speed_menu
));
646 ARDOUR_UI::show_shuttle_context_menu ()
648 if (shuttle_context_menu
== 0) {
649 build_shuttle_context_menu ();
652 shuttle_context_menu
->popup (1, gtk_get_current_event_time());
656 ARDOUR_UI::set_shuttle_max_speed (float speed
)
658 shuttle_max_speed
= speed
;
662 ARDOUR_UI::shuttle_box_button_press (GdkEventButton
* ev
)
668 if (shuttle_controller_binding_proxy
.button_press_handler (ev
)) {
672 if (Keyboard::is_context_menu_event (ev
)) {
673 show_shuttle_context_menu ();
677 switch (ev
->button
) {
679 shuttle_box
.add_modal_grab ();
680 shuttle_grabbed
= true;
681 mouse_shuttle (ev
->x
, true);
694 ARDOUR_UI::shuttle_box_button_release (GdkEventButton
* ev
)
700 switch (ev
->button
) {
702 mouse_shuttle (ev
->x
, true);
703 shuttle_grabbed
= false;
704 shuttle_box
.remove_modal_grab ();
705 if (Config
->get_shuttle_behaviour() == Sprung
) {
706 if (_session
->config
.get_auto_play() || roll_button
.get_visual_state()) {
707 shuttle_fract
= SHUTTLE_FRACT_SPEED1
;
708 _session
->request_transport_speed (1.0);
709 stop_button
.set_visual_state (0);
710 roll_button
.set_visual_state (1);
713 _session
->request_transport_speed (0.0);
715 shuttle_box
.queue_draw ();
720 if (_session
->transport_rolling()) {
721 shuttle_fract
= SHUTTLE_FRACT_SPEED1
;
722 _session
->request_transport_speed (1.0);
723 stop_button
.set_visual_state (0);
724 roll_button
.set_visual_state (1);
728 shuttle_box
.queue_draw ();
737 use_shuttle_fract (true);
743 ARDOUR_UI::shuttle_box_scroll (GdkEventScroll
* ev
)
749 switch (ev
->direction
) {
752 shuttle_fract
+= 0.005;
754 case GDK_SCROLL_DOWN
:
755 shuttle_fract
-= 0.005;
758 /* scroll left/right */
762 use_shuttle_fract (true);
768 ARDOUR_UI::shuttle_box_motion (GdkEventMotion
* ev
)
770 if (!_session
|| !shuttle_grabbed
) {
774 return mouse_shuttle (ev
->x
, false);
778 ARDOUR_UI::mouse_shuttle (double x
, bool force
)
780 double half_width
= shuttle_box
.get_width() / 2.0;
781 double distance
= x
- half_width
;
784 distance
= min (distance
, half_width
);
786 distance
= max (distance
, -half_width
);
789 shuttle_fract
= distance
/ half_width
;
790 use_shuttle_fract (force
);
795 ARDOUR_UI::set_shuttle_fract (double f
)
798 use_shuttle_fract (false);
802 ARDOUR_UI::use_shuttle_fract (bool force
)
804 microseconds_t now
= get_microseconds();
806 /* do not attempt to submit a motion-driven transport speed request
807 more than once per process cycle.
810 if (!force
&& (last_shuttle_request
- now
) < (microseconds_t
) engine
->usecs_per_cycle()) {
814 last_shuttle_request
= now
;
816 if (Config
->get_shuttle_units() == Semitones
) {
818 const double step
= 1.0 / 24.0; // range is 24 semitones up & down
822 semitones
= round (shuttle_fract
/ step
);
823 speed
= pow (2.0, (semitones
/ 12.0));
825 _session
->request_transport_speed (speed
);
832 neg
= (shuttle_fract
< 0.0);
834 fract
= 1 - sqrt (1 - (shuttle_fract
* shuttle_fract
)); // Formula A1
840 _session
->request_transport_speed (shuttle_max_speed
* fract
);
843 shuttle_box
.queue_draw ();
847 ARDOUR_UI::shuttle_box_expose (GdkEventExpose
* event
)
850 Glib::RefPtr
<Gdk::Window
> win (shuttle_box
.get_window());
852 /* redraw the background */
854 win
->draw_rectangle (shuttle_box
.get_style()->get_bg_gc (shuttle_box
.get_state()),
856 event
->area
.x
, event
->area
.y
,
857 event
->area
.width
, event
->area
.height
);
860 x
= (gint
) floor ((shuttle_box
.get_width() / 2.0) + (0.5 * (shuttle_box
.get_width() * shuttle_fract
)));
864 win
->draw_line (shuttle_box
.get_style()->get_fg_gc (shuttle_box
.get_state()),
868 shuttle_box
.get_height());
873 ARDOUR_UI::shuttle_unit_clicked ()
875 if (shuttle_unit_menu
== 0) {
876 shuttle_unit_menu
= dynamic_cast<Menu
*> (ActionManager::get_widget ("/ShuttleUnitPopup"));
878 shuttle_unit_menu
->popup (1, gtk_get_current_event_time());
882 ARDOUR_UI::shuttle_style_changed ()
884 ustring str
= shuttle_style_button
.get_active_text ();
886 if (str
== _("sprung")) {
887 Config
->set_shuttle_behaviour (Sprung
);
888 } else if (str
== _("wheel")) {
889 Config
->set_shuttle_behaviour (Wheel
);
894 ARDOUR_UI::update_speed_display ()
897 if (last_speed_displayed
!= 0) {
898 speed_display_label
.set_text (_("stop"));
899 last_speed_displayed
= 0;
905 float x
= _session
->transport_speed ();
907 if (x
!= last_speed_displayed
) {
910 if (Config
->get_shuttle_units() == Percentage
) {
911 snprintf (buf
, sizeof (buf
), "%d", (int) round (x
* 100));
915 snprintf (buf
, sizeof (buf
), "< %d", (int) round (12.0 * fast_log2 (-x
)));
917 snprintf (buf
, sizeof (buf
), "> %d", (int) round (12.0 * fast_log2 (x
)));
920 speed_display_label
.set_text (buf
);
922 speed_display_label
.set_text (_("stop"));
925 last_speed_displayed
= x
;
930 ARDOUR_UI::set_transport_sensitivity (bool yn
)
932 ActionManager::set_sensitive (ActionManager::transport_sensitive_actions
, yn
);
933 shuttle_box
.set_sensitive (yn
);
937 ARDOUR_UI::editor_realized ()
939 boost::function
<void (string
)> pc (boost::bind (&ARDOUR_UI::parameter_changed
, this, _1
));
940 Config
->map_parameters (pc
);
942 set_size_request_to_display_given_text (speed_display_box
, _("-0.55"), 2, 2);
947 ARDOUR_UI::maximise_editing_space ()
953 transport_tearoff
->set_visible (false);
954 editor
->maximise_editing_space ();
958 ARDOUR_UI::restore_editing_space ()
964 transport_tearoff
->set_visible (true);
965 editor
->restore_editing_space ();