Update GPL boilerplate and (C)
[ardour.git] / gtk2_ardour / shuttle_control.h
1 /*
2  * Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #ifndef __gtk2_ardour_shuttle_control_h__
21 #define __gtk2_ardour_shuttle_control_h__
22
23 #include <gtkmm/drawingarea.h>
24
25 #include "pbd/controllable.h"
26
27 #include "ardour/session_handle.h"
28 #include "ardour/types.h"
29
30 #include "gtkmm2ext/cairo_widget.h"
31
32 #include "widgets/ardour_button.h"
33 #include "widgets/binding_proxy.h"
34
35 namespace Gtk {
36         class Menu;
37 }
38
39 class ShuttleControl : public CairoWidget, public ARDOUR::SessionHandlePtr
40 {
41 public:
42         ShuttleControl ();
43         ~ShuttleControl ();
44
45         void map_transport_state ();
46         void set_shuttle_fract (double, bool zero_ok = false);
47         double get_shuttle_fract () const { return shuttle_fract; }
48         void set_session (ARDOUR::Session*);
49
50         struct ShuttleControllable : public PBD::Controllable {
51                 ShuttleControllable (ShuttleControl&);
52                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
53                 double get_value (void) const;
54
55                 double lower() const { return -1.0; }
56                 double upper() const { return  1.0; }
57
58                 ShuttleControl& sc;
59         };
60
61         boost::shared_ptr<ShuttleControllable> controllable() const { return _controllable; }
62         void set_colors ();
63
64         ArdourWidgets::ArdourButton* info_button () { return &_info_button; }
65
66 protected:
67         bool _hovering;
68         float  shuttle_max_speed;
69         float  last_speed_displayed;
70         bool   shuttle_grabbed;
71         double shuttle_speed_on_grab;
72         double requested_speed;
73         float shuttle_fract;
74         boost::shared_ptr<ShuttleControllable> _controllable;
75         cairo_pattern_t* pattern;
76         cairo_pattern_t* shine_pattern;
77         ARDOUR::microseconds_t last_shuttle_request;
78         PBD::ScopedConnection parameter_connection;
79         ArdourWidgets::ArdourButton _info_button;
80         Gtk::Menu*                  shuttle_context_menu;
81         ArdourWidgets::BindingProxy binding_proxy;
82         float bg_r, bg_g, bg_b;
83         void build_shuttle_context_menu ();
84         void shuttle_style_changed();
85         void set_shuttle_max_speed (float);
86         void reset_speed ();
87
88         bool on_enter_notify_event (GdkEventCrossing*);
89         bool on_leave_notify_event (GdkEventCrossing*);
90         bool on_button_press_event (GdkEventButton*);
91         bool on_button_release_event(GdkEventButton*);
92         bool on_scroll_event (GdkEventScroll*);
93         bool on_motion_notify_event(GdkEventMotion*);
94
95         void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
96
97         void on_size_allocate (Gtk::Allocation&);
98         bool on_query_tooltip (int, int, bool, const Glib::RefPtr<Gtk::Tooltip>&);
99
100         gint mouse_shuttle (double x, bool force);
101         void use_shuttle_fract (bool force, bool zero_ok = false);
102         void parameter_changed (std::string);
103
104         void set_shuttle_units (ARDOUR::ShuttleUnits);
105         void set_shuttle_style (ARDOUR::ShuttleBehaviour);
106
107         int speed_as_semitones (float, bool&);
108         int fract_as_semitones (float, bool&);
109
110         float semitones_as_speed (int, bool);
111         float semitones_as_fract (int, bool);
112 };
113
114 #endif /* __gtk2_ardour_shuttle_control_h__ */