use new action map API instead of ActionManager::get_action
[ardour.git] / gtk2_ardour / shuttle_control.h
1 /*
2     Copyright (C) 2011 Paul Davis
3
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.
8
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.
13
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.
17 */
18
19 #ifndef __gtk2_ardour_shuttle_control_h__
20 #define __gtk2_ardour_shuttle_control_h__
21
22 #include <gtkmm/drawingarea.h>
23
24 #include "pbd/controllable.h"
25
26 #include "ardour/session_handle.h"
27 #include "ardour/types.h"
28
29 #include "gtkmm2ext/cairo_widget.h"
30
31 #include "widgets/ardour_button.h"
32 #include "widgets/binding_proxy.h"
33
34 namespace Gtk {
35         class Menu;
36 }
37
38 class ShuttleControl : public CairoWidget, public ARDOUR::SessionHandlePtr
39 {
40 public:
41         ShuttleControl ();
42         ~ShuttleControl ();
43
44         void map_transport_state ();
45         void set_shuttle_fract (double, bool zero_ok = false);
46         double get_shuttle_fract () const { return shuttle_fract; }
47         void set_session (ARDOUR::Session*);
48
49         struct ShuttleControllable : public PBD::Controllable {
50                 ShuttleControllable (ShuttleControl&);
51                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
52                 double get_value (void) const;
53
54                 double lower() const { return -1.0; }
55                 double upper() const { return  1.0; }
56
57                 ShuttleControl& sc;
58         };
59
60         boost::shared_ptr<ShuttleControllable> controllable() const { return _controllable; }
61         void set_colors ();
62
63         ArdourWidgets::ArdourButton* info_button () { return &_info_button; }
64
65 protected:
66         bool _hovering;
67         float  shuttle_max_speed;
68         float  last_speed_displayed;
69         bool   shuttle_grabbed;
70         double shuttle_speed_on_grab;
71         double requested_speed;
72         float shuttle_fract;
73         boost::shared_ptr<ShuttleControllable> _controllable;
74         cairo_pattern_t* pattern;
75         cairo_pattern_t* shine_pattern;
76         ARDOUR::microseconds_t last_shuttle_request;
77         PBD::ScopedConnection parameter_connection;
78         ArdourWidgets::ArdourButton _info_button;
79         Gtk::Menu*                  shuttle_unit_menu;
80         Gtk::Menu*                  shuttle_style_menu;
81         Gtk::Menu*                  shuttle_context_menu;
82         ArdourWidgets::BindingProxy binding_proxy;
83         float bg_r, bg_g, bg_b;
84         void build_shuttle_context_menu ();
85         void shuttle_style_changed();
86         void set_shuttle_max_speed (float);
87         void reset_speed ();
88
89         bool on_enter_notify_event (GdkEventCrossing*);
90         bool on_leave_notify_event (GdkEventCrossing*);
91         bool on_button_press_event (GdkEventButton*);
92         bool on_button_release_event(GdkEventButton*);
93         bool on_scroll_event (GdkEventScroll*);
94         bool on_motion_notify_event(GdkEventMotion*);
95
96         void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
97
98         void on_size_allocate (Gtk::Allocation&);
99         bool on_query_tooltip (int, int, bool, const Glib::RefPtr<Gtk::Tooltip>&);
100
101         gint mouse_shuttle (double x, bool force);
102         void use_shuttle_fract (bool force, bool zero_ok = false);
103         void parameter_changed (std::string);
104
105         void set_shuttle_units (ARDOUR::ShuttleUnits);
106         void set_shuttle_style (ARDOUR::ShuttleBehaviour);
107
108         int speed_as_semitones (float, bool&);
109         int fract_as_semitones (float, bool&);
110
111         float semitones_as_speed (int, bool);
112         float semitones_as_fract (int, bool);
113 };
114
115 #endif /* __gtk2_ardour_shuttle_control_h__ */