Setup fixed ports for MIDI control data; hence remove configuration of those ports...
[ArdourMidi.git] / gtk2_ardour / ardour_ui2.cc
blob3a321cc5e38b36882ed01a5444b905d6268bcc00
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"
48 #include "midi_tracer.h"
50 #include "i18n.h"
52 using namespace std;
53 using namespace ARDOUR;
54 using namespace PBD;
55 using namespace Gtkmm2ext;
56 using namespace Gtk;
57 using namespace Glib;
59 int
60 ARDOUR_UI::setup_windows ()
62 if (create_editor ()) {
63 error << _("UI: cannot setup editor") << endmsg;
64 return -1;
67 if (create_mixer ()) {
68 error << _("UI: cannot setup mixer") << endmsg;
69 return -1;
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")));
78 #ifdef TOP_MENUBAR
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);
98 #else
99 top_packer.pack_start (menu_bar_base, false, false);
100 #endif
102 top_packer.pack_start (transport_frame, false, false);
104 editor->add_toplevel_controls (top_packer);
106 setup_clock ();
107 setup_transport();
108 build_menu_bar ();
110 _midi_tracer_window = new MidiTracer ();
111 manage_window (*_midi_tracer_window);
113 setup_tooltips ();
115 return 0;
118 void
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 ();
149 bool
150 ARDOUR_UI::status_bar_button_press (GdkEventButton* ev)
152 bool handled = false;
154 switch (ev->button) {
155 case 1:
156 status_bar_label.set_text ("");
157 handled = true;
158 break;
159 default:
160 break;
163 return handled;
166 void
167 ARDOUR_UI::display_message (const char *prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
169 ustring text;
171 UI::display_message (prefix, prefix_len, ptag, mtag, msg);
172 #ifdef TOP_MENUBAR
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\">";
180 } else {
181 text = "<span color=\"white\" weight=\"bold\">???";
184 text += prefix;
185 text += "</span>";
186 text += msg;
188 status_bar_label.set_markup (text);
189 #endif
192 XMLNode*
193 ARDOUR_UI::tearoff_settings (const char* name) const
195 XMLNode* ui_node = Config->extra_xml(X_("UI"));
197 if (ui_node) {
198 XMLNode* tearoff_node = ui_node->child (X_("Tearoffs"));
199 if (tearoff_node) {
200 XMLNode* mnode = tearoff_node->child (name);
201 return mnode;
205 return 0;
208 void
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);
264 Widget* w;
266 stop_button.set_visual_state (1);
268 w = manage (new Image (get_icon (X_("transport_start"))));
269 w->show();
270 goto_start_button.add (*w);
271 w = manage (new Image (get_icon (X_("transport_end"))));
272 w->show();
273 goto_end_button.add (*w);
274 w = manage (new Image (get_icon (X_("transport_play"))));
275 w->show();
276 roll_button.add (*w);
277 w = manage (new Image (get_icon (X_("transport_stop"))));
278 w->show();
279 stop_button.add (*w);
280 w = manage (new Image (get_icon (X_("transport_range"))));
281 w->show();
282 play_selection_button.add (*w);
283 w = manage (new Image (get_icon (X_("transport_record"))));
284 w->show();
285 rec_button.add (*w);
286 w = manage (new Image (get_icon (X_("transport_loop"))));
287 w->show();
288 auto_loop_button.add (*w);
289 w = manage (new Image (get_icon (X_("join_tools"))));
290 w->show ();
291 join_play_range_button.add (*w);
293 RefPtr<Action> act;
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));
324 /* clocks, etc. */
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");
348 /* alerts */
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);
409 } else {
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);
452 /* desensitize */
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");
471 if (tnode) {
472 transport_tearoff->set_state (*tnode);
476 void
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));
484 void
485 ARDOUR_UI::detach_tearoff (Box* b, Widget* w)
487 // editor->ensure_float (transport_tearoff->tearoff_window());
488 b->remove (*w);
491 void
492 ARDOUR_UI::reattach_tearoff (Box* b, Widget* w, int32_t n)
494 b->pack_start (*w);
495 b->reorder_child (*w, n);
498 void
499 ARDOUR_UI::soloing_changed (bool onoff)
501 if (solo_alert_button.get_active() != onoff) {
502 solo_alert_button.set_active (onoff);
506 void
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);
515 void
516 ARDOUR_UI::auditioning_changed (bool onoff)
518 UI::instance()->call_slot (MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::_auditioning_changed, this, onoff));
521 bool
522 ARDOUR_UI::audition_alert_press (GdkEventButton* ev)
524 if (_session) {
525 _session->cancel_audition();
527 return true;
530 bool
531 ARDOUR_UI::solo_alert_press (GdkEventButton* ev)
533 if (_session) {
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);
540 return true;
543 void
544 ARDOUR_UI::solo_blink (bool onoff)
546 if (_session == 0) {
547 return;
550 if (_session->soloing() || _session->listening()) {
551 if (onoff) {
552 solo_alert_button.set_state (STATE_ACTIVE);
553 } else {
554 solo_alert_button.set_state (STATE_NORMAL);
556 } else {
557 solo_alert_button.set_active (false);
558 solo_alert_button.set_state (STATE_NORMAL);
562 void
563 ARDOUR_UI::sync_blink (bool onoff)
565 if (_session == 0 || !_session->config.get_external_sync()) {
566 /* internal sync */
567 sync_button.set_visual_state (0);
568 return;
571 if (!_session->transport_locked()) {
572 /* not locked, so blink on and off according to the onoff argument */
574 if (onoff) {
575 sync_button.set_visual_state (1); // "-active"
576 } else {
577 sync_button.set_visual_state (0); // normal
579 } else {
580 /* locked */
581 sync_button.set_visual_state (1); // "-active"
585 void
586 ARDOUR_UI::audition_blink (bool onoff)
588 if (_session == 0) {
589 return;
592 if (_session->is_auditioning()) {
593 if (onoff) {
594 auditioning_alert_button.set_state (STATE_ACTIVE);
595 } else {
596 auditioning_alert_button.set_state (STATE_NORMAL);
598 } else {
599 auditioning_alert_button.set_active (false);
600 auditioning_alert_button.set_state (STATE_NORMAL);
604 void
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));
645 void
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());
655 void
656 ARDOUR_UI::set_shuttle_max_speed (float speed)
658 shuttle_max_speed = speed;
661 gint
662 ARDOUR_UI::shuttle_box_button_press (GdkEventButton* ev)
664 if (!_session) {
665 return true;
668 if (shuttle_controller_binding_proxy.button_press_handler (ev)) {
669 return true;
672 if (Keyboard::is_context_menu_event (ev)) {
673 show_shuttle_context_menu ();
674 return true;
677 switch (ev->button) {
678 case 1:
679 shuttle_box.add_modal_grab ();
680 shuttle_grabbed = true;
681 mouse_shuttle (ev->x, true);
682 break;
684 case 2:
685 case 3:
686 return true;
687 break;
690 return true;
693 gint
694 ARDOUR_UI::shuttle_box_button_release (GdkEventButton* ev)
696 if (!_session) {
697 return true;
700 switch (ev->button) {
701 case 1:
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);
711 } else {
712 shuttle_fract = 0;
713 _session->request_transport_speed (0.0);
715 shuttle_box.queue_draw ();
717 return true;
719 case 2:
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);
725 } else {
726 shuttle_fract = 0;
728 shuttle_box.queue_draw ();
729 return true;
731 case 3:
732 default:
733 return true;
737 use_shuttle_fract (true);
739 return true;
742 gint
743 ARDOUR_UI::shuttle_box_scroll (GdkEventScroll* ev)
745 if (!_session) {
746 return true;
749 switch (ev->direction) {
751 case GDK_SCROLL_UP:
752 shuttle_fract += 0.005;
753 break;
754 case GDK_SCROLL_DOWN:
755 shuttle_fract -= 0.005;
756 break;
757 default:
758 /* scroll left/right */
759 return false;
762 use_shuttle_fract (true);
764 return true;
767 gint
768 ARDOUR_UI::shuttle_box_motion (GdkEventMotion* ev)
770 if (!_session || !shuttle_grabbed) {
771 return true;
774 return mouse_shuttle (ev->x, false);
777 gint
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;
783 if (distance > 0) {
784 distance = min (distance, half_width);
785 } else {
786 distance = max (distance, -half_width);
789 shuttle_fract = distance / half_width;
790 use_shuttle_fract (force);
791 return true;
794 void
795 ARDOUR_UI::set_shuttle_fract (double f)
797 shuttle_fract = f;
798 use_shuttle_fract (false);
801 void
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()) {
811 return;
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
819 double semitones;
820 double speed;
822 semitones = round (shuttle_fract / step);
823 speed = pow (2.0, (semitones / 12.0));
825 _session->request_transport_speed (speed);
827 } else {
829 bool neg;
830 double fract;
832 neg = (shuttle_fract < 0.0);
834 fract = 1 - sqrt (1 - (shuttle_fract * shuttle_fract)); // Formula A1
836 if (neg) {
837 fract = -fract;
840 _session->request_transport_speed (shuttle_max_speed * fract);
843 shuttle_box.queue_draw ();
846 gint
847 ARDOUR_UI::shuttle_box_expose (GdkEventExpose* event)
849 gint x;
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()),
855 true,
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)));
862 /* draw line */
864 win->draw_line (shuttle_box.get_style()->get_fg_gc (shuttle_box.get_state()),
868 shuttle_box.get_height());
869 return true;
872 void
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());
881 void
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);
893 void
894 ARDOUR_UI::update_speed_display ()
896 if (!_session) {
897 if (last_speed_displayed != 0) {
898 speed_display_label.set_text (_("stop"));
899 last_speed_displayed = 0;
901 return;
904 char buf[32];
905 float x = _session->transport_speed ();
907 if (x != last_speed_displayed) {
909 if (x != 0) {
910 if (Config->get_shuttle_units() == Percentage) {
911 snprintf (buf, sizeof (buf), "%d", (int) round (x * 100));
912 } else {
914 if (x < 0) {
915 snprintf (buf, sizeof (buf), "< %d", (int) round (12.0 * fast_log2 (-x)));
916 } else {
917 snprintf (buf, sizeof (buf), "> %d", (int) round (12.0 * fast_log2 (x)));
920 speed_display_label.set_text (buf);
921 } else {
922 speed_display_label.set_text (_("stop"));
925 last_speed_displayed = x;
929 void
930 ARDOUR_UI::set_transport_sensitivity (bool yn)
932 ActionManager::set_sensitive (ActionManager::transport_sensitive_actions, yn);
933 shuttle_box.set_sensitive (yn);
936 void
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);
943 reset_dpi ();
946 void
947 ARDOUR_UI::maximise_editing_space ()
949 if (!editor) {
950 return;
953 transport_tearoff->set_visible (false);
954 editor->maximise_editing_space ();
957 void
958 ARDOUR_UI::restore_editing_space ()
960 if (!editor) {
961 return;
964 transport_tearoff->set_visible (true);
965 editor->restore_editing_space ();