remove PBD::Connection (replace use with PBD::ScopedConnection); remove limitation...
[ardour.git] / libs / surfaces / mackie / mackie_jog_wheel.h
1 #ifndef mackie_jog_wheel
2 #define mackie_jog_wheel
3
4 #include "timer.h"
5
6 #include <stack>
7 #include <deque>
8 #include <queue>
9
10 class MackieControlProtocol;
11
12 namespace Mackie
13 {
14
15 class SurfacePort;
16 class Control;
17 class ControlState;
18
19 /**
20         A jog wheel can be used to control many things. This
21         handles all of the states and state transitions.
22         
23         Mainly it exists to avoid putting a bunch of messy
24         stuff in MackieControlProtocol.
25         
26         But it doesn't really know who it is, with stacks, queues and various
27         boolean state variables.
28 */
29 class JogWheel
30 {
31 public:
32         enum State { scroll, zoom, speed, scrub, shuttle, select };
33         
34         JogWheel( MackieControlProtocol & mcp );
35
36         /// As the wheel turns...
37         void jog_event( SurfacePort & port, Control & control, const ControlState & state );
38         
39         // These are for incoming button presses that change the internal state
40         // but they're not actually used at the moment.
41         void zoom_event( SurfacePort & port, Control & control, const ControlState & state );
42         void scrub_event( SurfacePort & port, Control & control, const ControlState & state );
43         void speed_event( SurfacePort & port, Control & control, const ControlState & state );
44         void scroll_event( SurfacePort & port, Control & control, const ControlState & state );
45
46         /// Return the current jog wheel mode, which defaults to Scroll
47         State jog_wheel_state() const;
48         
49         /// The current transport speed for ffwd and rew. Can be
50         /// set by wheel when they're pressed.
51         float transport_speed() const { return _transport_speed; }
52         
53         /// one of -1,0,1
54         int transport_direction() const { return _transport_direction; }
55         void transport_direction( int rhs ) { _transport_direction = rhs; }
56         
57         void push( State state );
58         void pop();
59         
60         /// Turn zoom mode on and off
61         void zoom_state_toggle();
62         
63         /**
64                 Cycle scrub -> shuttle -> previous
65         */
66         State scrub_state_cycle();
67         
68         /// Check to see when the last scrub event was
69         /// And stop scrubbing if it was too long ago.
70         /// Intended to be called from a periodic timer of 
71         /// some kind.
72         void check_scrubbing();
73
74 protected:
75         void add_scrub_interval( unsigned long elapsed );
76         float average_scrub_interval();
77         float std_dev_scrub_interval();
78
79 private:
80         MackieControlProtocol & _mcp;
81
82         /// transport speed for ffwd and rew, controller by jog
83         float _transport_speed;
84         int _transport_direction;
85
86         /// Speed for shuttle
87         float _shuttle_speed;
88         
89         /// a stack for keeping track of states
90         std::stack<State> _jog_wheel_states;
91
92         /// So we know how fast to set the transport speed while scrubbing
93         Timer _scrub_timer;
94
95         /// to keep track of what the current scrub rate is
96         /// so we can calculate a moving average
97         std::deque<unsigned long> _scrub_intervals;
98 };
99
100 }
101
102 #endif