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