use running_from_source_tree()
[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 "gtkmm2ext/binding_proxy.h"
25 #include "gtkmm2ext/cairo_widget.h"
26
27 #include "pbd/controllable.h"
28 #include "ardour/session_handle.h"
29
30 namespace Gtk {
31         class Menu;
32 }
33
34 #include "ardour/types.h"
35
36 class ShuttleControl : public CairoWidget, public ARDOUR::SessionHandlePtr
37 {
38   public:
39         ShuttleControl ();
40         ~ShuttleControl ();
41
42         void map_transport_state ();
43         void set_shuttle_fract (double, bool zero_ok = false);
44         double get_shuttle_fract () const { return shuttle_fract; }
45         void set_session (ARDOUR::Session*);
46
47         struct ShuttleControllable : public PBD::Controllable {
48                 ShuttleControllable (ShuttleControl&);
49                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
50                 double get_value (void) const;
51
52                 double lower() const { return -1.0; }
53                 double upper() const { return  1.0; }
54
55                 ShuttleControl& sc;
56         };
57
58         boost::shared_ptr<ShuttleControllable> controllable() const { return _controllable; }
59         void set_colors ();
60
61   protected:
62         bool _hovering;
63         float  shuttle_max_speed;
64         float  last_speed_displayed;
65         bool   shuttle_grabbed;
66         double shuttle_speed_on_grab;
67         float shuttle_fract;
68         boost::shared_ptr<ShuttleControllable> _controllable;
69         cairo_pattern_t* pattern;
70         cairo_pattern_t* shine_pattern;
71         ARDOUR::microseconds_t last_shuttle_request;
72         PBD::ScopedConnection parameter_connection;
73         Gtk::Menu*        shuttle_unit_menu;
74         Gtk::Menu*        shuttle_style_menu;
75         Gtk::Menu*        shuttle_context_menu;
76         BindingProxy      binding_proxy;
77         Glib::RefPtr<Pango::Layout> left_text;
78         Glib::RefPtr<Pango::Layout> right_text;
79         Pango::AttrList text_attributes;
80         Pango::AttrColor* text_color;
81         float bg_r, bg_g, bg_b;
82         void build_shuttle_context_menu ();
83         void show_shuttle_context_menu ();
84         void shuttle_style_changed();
85         void shuttle_unit_clicked ();
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_t *, 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__ */