factor out shuttle controller to its own class, new design
[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 #include "ardour/session_handle.h"
26
27 namespace Gtk {
28         class Menu;
29 }
30
31 #include "ardour/types.h"
32
33 class ShuttleControl : public Gtk::DrawingArea, public ARDOUR::SessionHandlePtr 
34 {
35   public:
36         ShuttleControl ();
37         ~ShuttleControl ();
38
39         void map_transport_state ();
40         void update_speed_display ();
41         void set_shuttle_fract (double);
42         double get_shuttle_fract () const { return shuttle_fract; }
43         void set_session (ARDOUR::Session*);
44
45         struct ShuttleControllable : public PBD::Controllable {
46                 ShuttleControllable (ShuttleControl&);
47                 void set_value (double);
48                 double get_value (void) const;
49                 
50                 void set_id (const std::string&);
51                 
52                 ShuttleControl& sc;
53         };
54
55         ShuttleControllable& controllable() { return _controllable; }
56
57   protected:
58         float  shuttle_max_speed;
59         float  last_speed_displayed;
60         bool   shuttle_grabbed;
61         double shuttle_fract;
62         ShuttleControllable _controllable;
63         cairo_pattern_t* pattern;
64         ARDOUR::microseconds_t last_shuttle_request;
65         PBD::ScopedConnection parameter_connection;
66         Gtk::Menu*        shuttle_unit_menu;
67         Gtk::Menu*        shuttle_style_menu;
68         Gtk::Menu*        shuttle_context_menu;
69
70         void build_shuttle_context_menu ();
71         void show_shuttle_context_menu ();
72         void shuttle_style_changed();
73         void shuttle_unit_clicked ();
74         void set_shuttle_max_speed (float);
75
76         bool on_button_press_event (GdkEventButton*);
77         bool on_button_release_event(GdkEventButton*);
78         bool on_scroll_event (GdkEventScroll*);
79         bool on_motion_notify_event(GdkEventMotion*);
80         bool on_expose_event(GdkEventExpose*);
81         void on_size_allocate (Gtk::Allocation&);
82
83         gint mouse_shuttle (double x, bool force);
84         void use_shuttle_fract (bool force);
85         void parameter_changed (std::string);
86
87         void set_shuttle_units (ARDOUR::ShuttleUnits);
88         void set_shuttle_style (ARDOUR::ShuttleBehaviour);
89 };
90
91 #endif /* __gtk2_ardour_shuttle_control_h__ */