Fixed compile warnings.
[ardour.git] / gtk2_ardour / ardour_ui2.cc
index 3ce826ca82996dcfc013557f48d60ddcf77ec70b..f92201e36c543e75bb5dc42238237b7d6bc0987c 100644 (file)
@@ -29,7 +29,6 @@
 #include <pbd/error.h>
 #include <pbd/basename.h>
 #include <pbd/fastlog.h>
-#include <gtkmm2ext/pix.h>
 #include <gtkmm2ext/utils.h>
 #include <gtkmm2ext/click_box.h>
 #include <gtkmm2ext/tearoff.h>
@@ -48,6 +47,7 @@
 
 using namespace std;
 using namespace ARDOUR;
+using namespace PBD;
 using namespace Gtkmm2ext;
 using namespace Gtk;
 using namespace Glib;
@@ -56,8 +56,6 @@ using namespace sigc;
 int    
 ARDOUR_UI::setup_windows ()
 {
-       using namespace Menu_Helpers;
-
        if (create_editor ()) {
                error << _("UI: cannot setup editor") << endmsg;
                return -1;
@@ -117,31 +115,6 @@ ARDOUR_UI::setup_adjustables ()
        adjuster_table.attach (*mmc_id_button, 2, 3, 1, 2, FILL, FILL, 5, 5);
 }
 
-static const gchar * loop_xpm[] = {
-"19 19 3 1",
-"      c None",
-".     c #000000",
-"+     c #FFFFFF",
-"       ...         ",
-"       .+..        ",
-"       .++..       ",
-"     ...+++....    ",
-"   ...++++++++...  ",
-"  ..+++.+++..+++.. ",
-" ..++...++.....++..",
-" .++.. .+..   ..++.",
-" .+..  ...     ..+.",
-" .+.            .+.",
-" .+..     ...  ..+.",
-" .++..   ..+. ..++.",
-" ..++.....++...++..",
-"  ..+++..+++.+++.. ",
-"   ...++++++++...  ",
-"     ....+++...    ",
-"        ..++.      ",
-"         ..+.      ",
-"          ...      "};
-
 void
 ARDOUR_UI::transport_stopped ()
 {
@@ -225,7 +198,11 @@ ARDOUR_UI::setup_transport ()
                                                 static_cast<Widget*>(&transport_frame)));
        transport_tearoff->Attach.connect (bind (mem_fun(*this, &ARDOUR_UI::reattach_tearoff), static_cast<Box*> (&top_packer), 
                                                 static_cast<Widget*> (&transport_frame), 1));
-
+       transport_tearoff->Hidden.connect (bind (mem_fun(*this, &ARDOUR_UI::detach_tearoff), static_cast<Box*>(&top_packer), 
+                                                static_cast<Widget*>(&transport_frame)));
+       transport_tearoff->Visible.connect (bind (mem_fun(*this, &ARDOUR_UI::reattach_tearoff), static_cast<Box*> (&top_packer), 
+                                                 static_cast<Widget*> (&transport_frame), 1));
+       
        shuttle_box.set_name ("TransportButton");
        goto_start_button.set_name ("TransportButton");
        goto_end_button.set_name ("TransportButton");
@@ -288,7 +265,7 @@ ARDOUR_UI::setup_transport ()
        w = manage (new Image (Stock::MEDIA_RECORD, ICON_SIZE_BUTTON));
        w->show();
        rec_button.add (*w);
-       w = manage (new Image (Gdk::Pixbuf::create_from_xpm_data(loop_xpm)));
+       w = manage (new Image (get_xpm("loop.xpm")));
        w->show();
        auto_loop_button.add (*w);
 
@@ -323,47 +300,19 @@ ARDOUR_UI::setup_transport ()
        ARDOUR_UI::instance()->tooltips().set_tip (punch_in_button, _("Start recording at auto-punch start"));
        ARDOUR_UI::instance()->tooltips().set_tip (punch_out_button, _("Stop recording at auto-punch end"));
        ARDOUR_UI::instance()->tooltips().set_tip (click_button, _("Enable/Disable audio click"));
+       ARDOUR_UI::instance()->tooltips().set_tip (sync_option_combo, _("Positional sync source"));
        ARDOUR_UI::instance()->tooltips().set_tip (time_master_button, _("Does Ardour control the time?"));
        ARDOUR_UI::instance()->tooltips().set_tip (shuttle_box, _("Shuttle speed control"));
        ARDOUR_UI::instance()->tooltips().set_tip (shuttle_units_button, _("Select semitones or %%-age for speed display"));
        ARDOUR_UI::instance()->tooltips().set_tip (speed_display_box, _("Current transport speed"));
        
        shuttle_box.set_flags (CAN_FOCUS);
-       shuttle_box.set_events (shuttle_box.get_events() | Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::POINTER_MOTION_MASK);
+       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);
        shuttle_box.set_size_request (100, 15);
 
-       goto_start_button.unset_flags (CAN_FOCUS);
-       goto_end_button.unset_flags (CAN_FOCUS);
-       roll_button.unset_flags (CAN_FOCUS);
-       stop_button.unset_flags (CAN_FOCUS);
-       play_selection_button.unset_flags (CAN_FOCUS);
-       rec_button.unset_flags (CAN_FOCUS);
-       auto_loop_button.unset_flags (CAN_FOCUS);
-       auto_return_button.unset_flags (CAN_FOCUS);
-       auto_play_button.unset_flags (CAN_FOCUS);
-       auto_input_button.unset_flags (CAN_FOCUS);
-       punch_out_button.unset_flags (CAN_FOCUS);
-       punch_in_button.unset_flags (CAN_FOCUS);
-       click_button.unset_flags (CAN_FOCUS);
-       time_master_button.unset_flags (CAN_FOCUS);
-       
-       goto_start_button.set_events (goto_start_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       goto_end_button.set_events (goto_end_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       roll_button.set_events (roll_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       stop_button.set_events (stop_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       play_selection_button.set_events (play_selection_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       rec_button.set_events (rec_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       auto_loop_button.set_events (auto_loop_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       auto_return_button.set_events (auto_return_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       auto_play_button.set_events (auto_play_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       auto_input_button.set_events (auto_input_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       click_button.set_events (click_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       punch_in_button.set_events (punch_in_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       punch_out_button.set_events (punch_out_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-       time_master_button.set_events (punch_out_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
-
        shuttle_box.signal_button_press_event().connect (mem_fun(*this, &ARDOUR_UI::shuttle_box_button_press));
        shuttle_box.signal_button_release_event().connect (mem_fun(*this, &ARDOUR_UI::shuttle_box_button_release));
+       shuttle_box.signal_scroll_event().connect (mem_fun(*this, &ARDOUR_UI::shuttle_box_scroll));
        shuttle_box.signal_motion_notify_event().connect (mem_fun(*this, &ARDOUR_UI::shuttle_box_motion));
        shuttle_box.signal_expose_event().connect (mem_fun(*this, &ARDOUR_UI::shuttle_box_expose));
 
@@ -606,12 +555,73 @@ ARDOUR_UI::audition_blink (bool onoff)
        }
 }
 
+void
+ARDOUR_UI::build_shuttle_context_menu ()
+{
+       using namespace Menu_Helpers;
+
+       shuttle_context_menu = new Menu();
+       MenuList& items = shuttle_context_menu->items();
+
+       Menu* speed_menu = manage (new Menu());
+       MenuList& speed_items = speed_menu->items();
+
+       RadioMenuItem::Group group;
+
+       speed_items.push_back (RadioMenuElem (group, "8", bind (mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 8.0f)));
+       if (shuttle_max_speed == 8.0) {
+               static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();        
+       }
+       speed_items.push_back (RadioMenuElem (group, "6", bind (mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 6.0f)));
+       if (shuttle_max_speed == 6.0) {
+               static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();        
+       }
+       speed_items.push_back (RadioMenuElem (group, "4", bind (mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 4.0f)));
+       if (shuttle_max_speed == 4.0) {
+               static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();        
+       }
+       speed_items.push_back (RadioMenuElem (group, "3", bind (mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 3.0f)));
+       if (shuttle_max_speed == 3.0) {
+               static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();        
+       }
+       speed_items.push_back (RadioMenuElem (group, "2", bind (mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 2.0f)));
+       if (shuttle_max_speed == 2.0) {
+               static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();        
+       }
+       speed_items.push_back (RadioMenuElem (group, "1.5", bind (mem_fun (*this, &ARDOUR_UI::set_shuttle_max_speed), 1.5f)));
+       if (shuttle_max_speed == 1.5) {
+               static_cast<RadioMenuItem*>(&speed_items.back())->set_active ();        
+       }
+
+       items.push_back (MenuElem (_("Maximum speed"), *speed_menu));
+}
+
+void
+ARDOUR_UI::show_shuttle_context_menu ()
+{
+       if (shuttle_context_menu == 0) {
+               build_shuttle_context_menu ();
+       }
+
+       shuttle_context_menu->popup (1, 0);
+}
+
+void
+ARDOUR_UI::set_shuttle_max_speed (float speed)
+{
+       shuttle_max_speed = speed;
+}
 
 gint
 ARDOUR_UI::shuttle_box_button_press (GdkEventButton* ev)
 {
        if (!session) {
-               return TRUE;
+               return true;
+       }
+
+       if (Keyboard::is_context_menu_event (ev)) {
+               show_shuttle_context_menu ();
+               return true;
        }
 
        switch (ev->button) {
@@ -623,44 +633,53 @@ ARDOUR_UI::shuttle_box_button_press (GdkEventButton* ev)
 
        case 2:
        case 3:
-               return TRUE;
+               return true;
                break;
        }
 
-       return TRUE;
+       return true;
 }
 
 gint
 ARDOUR_UI::shuttle_box_button_release (GdkEventButton* ev)
 {
        if (!session) {
-               return TRUE;
+               return true;
        }
-
+       
        switch (ev->button) {
        case 1:
                mouse_shuttle (ev->x, true);
                shuttle_grabbed = false;
                shuttle_box.remove_modal_grab ();
                if (shuttle_behaviour == Sprung) {
-                       shuttle_fract = SHUTTLE_FRACT_SPEED1;
-                       session->request_transport_speed (1.0);
+                       if (session->get_auto_play() || roll_button.get_state()) {
+                               shuttle_fract = SHUTTLE_FRACT_SPEED1;                           
+                               session->request_transport_speed (1.0);
+                               stop_button.set_active (false);
+                               roll_button.set_active (true);
+                       } else {
+                               shuttle_fract = 0;
+                               session->request_transport_speed (0.0);
+                       }
                        shuttle_box.queue_draw ();
                }
-               return TRUE;
+               return true;
 
        case 2:
                if (session->transport_rolling()) {
                        shuttle_fract = SHUTTLE_FRACT_SPEED1;
                        session->request_transport_speed (1.0);
+                       stop_button.set_active (false);
+                       roll_button.set_active (true);
                } else {
                        shuttle_fract = 0;
                }
                shuttle_box.queue_draw ();
-               return TRUE;
+               return true;
 
        case 3:
-               return TRUE;
+               return true;
                
        case 4:
                shuttle_fract += 0.005;
@@ -672,14 +691,39 @@ ARDOUR_UI::shuttle_box_button_release (GdkEventButton* ev)
 
        use_shuttle_fract (true);
 
-       return TRUE;
+       return true;
+}
+
+gint
+ARDOUR_UI::shuttle_box_scroll (GdkEventScroll* ev)
+{
+       if (!session) {
+               return true;
+       }
+       
+       switch (ev->direction) {
+               
+       case GDK_SCROLL_UP:
+               shuttle_fract += 0.005;
+               break;
+       case GDK_SCROLL_DOWN:
+               shuttle_fract -= 0.005;
+               break;
+       default:
+               /* scroll left/right */
+               return false;
+       }
+
+       use_shuttle_fract (true);
+
+       return true;
 }
 
 gint
 ARDOUR_UI::shuttle_box_motion (GdkEventMotion* ev)
 {
        if (!session || !shuttle_grabbed) {
-               return TRUE;
+               return true;
        }
 
        return mouse_shuttle (ev->x, false);
@@ -699,7 +743,7 @@ ARDOUR_UI::mouse_shuttle (double x, bool force)
 
        shuttle_fract = distance / half_width;
        use_shuttle_fract (force);
-       return TRUE;
+       return true;
 }
 
 void
@@ -729,7 +773,7 @@ ARDOUR_UI::use_shuttle_fract (bool force)
                fract = -fract;
        }
 
-       session->request_transport_speed (8.0 * fract); // Formula A2
+       session->request_transport_speed (shuttle_max_speed * fract); // Formula A2
        shuttle_box.queue_draw ();
 }
 
@@ -756,7 +800,7 @@ ARDOUR_UI::shuttle_box_expose (GdkEventExpose* event)
                        0,
                        x,
                        shuttle_box.get_height());
-       return TRUE;
+       return true;
 }
 
 void
@@ -773,10 +817,10 @@ ARDOUR_UI::set_shuttle_units (ShuttleUnits u)
 {
        switch ((shuttle_units = u)) {
        case Percentage:
-               static_cast<Label*>(shuttle_units_button.get_child())->set_text ("% ");
+               shuttle_units_button.set_label("% ");
                break;
        case Semitones:
-               static_cast<Label*>(shuttle_units_button.get_child())->set_text (_("st"));
+               shuttle_units_button.set_label(_("st"));
                break;
        }
 }
@@ -886,3 +930,25 @@ ARDOUR_UI::sync_option_changed ()
                session->request_slave_source (Session::JACK);
        } 
 }
+
+void
+ARDOUR_UI::maximise_editing_space ()
+{
+       if (!editor) {
+               return;
+       }
+
+       transport_tearoff->set_visible (false);
+       editor->maximise_editing_space ();
+}
+
+void
+ARDOUR_UI::restore_editing_space ()
+{
+       if (!editor) {
+               return;
+       }
+
+       transport_tearoff->set_visible (true);
+       editor->restore_editing_space ();
+}