-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPedalManager.h
158 lines (143 loc) · 4.36 KB
/
PedalManager.h
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* File: PedalMonitor.h
* Author: Saleem Edah-Tally - [email protected]
* Licence : LGPL 2.1
* Copyright Saleem Edah-Tally, M.D. - © 2014
*
* Created on 18 février 2014, 20:52
*/
#ifndef PEDALMONITOR_H
#define PEDALMONITOR_H
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/thread.h>
#include <wx/mediactrl.h>
#include <hidapi/hidapi.h>
class PedalEvent;
class PedalCodeIdentifier;
class PedalBytesPerClickFinder;
class MediaFastMove;
class MediaProgress;
class HIDTool;
class IPedalMonitor: public wxThreadHelper {
public:
IPedalMonitor();
virtual ~IPedalMonitor();
protected:
virtual wxThread::ExitCode Entry() = 0;
};
/*
* In both modes below, pressing three pedals blocks everything.
* No pedal pressed means no action.
*/
/*
* In this mode, pressing a second pedal blocks everything.
* Releasing one pedal resumes the action of the pressed pedal.
*/
class PedalMonitor_OnOff : public IPedalMonitor {
public:
PedalMonitor_OnOff(const wxString& newDevice, PedalEvent * newPedalEVH, const unsigned short newLeftCode = 1, const unsigned short newMiddleCode = 2, const unsigned short newRightCode = 4);
virtual ~PedalMonitor_OnOff();
protected:
virtual wxThread::ExitCode Entry();
private:
PedalEvent * m_pedalEVH;
unsigned short m_leftCode, m_middleCode, m_rightCode;
unsigned short m_current;
wxString m_device;
};
/*
*In this mode, pressing a second pedal overrides the first pedal.
* The action of the last pedal pressed takes precedence.
* Releasing one pedal resumes the action of the pressed pedal.
*/
class PedalMonitor_Override : public IPedalMonitor {
public:
PedalMonitor_Override(const wxString& newDevice, PedalEvent * newPedalEVH, const unsigned short newLeftCode = 1, const unsigned short newMiddleCode = 2, const unsigned short newRightCode = 4);
virtual ~PedalMonitor_Override();
protected:
virtual wxThread::ExitCode Entry();
private:
PedalEvent * m_pedalEVH;
unsigned short m_leftCode, m_middleCode, m_rightCode;
unsigned short m_current, m_previous;
wxString m_device;
};
/*
* A single class to manage events form many classes.
* Function names are explicit.
* Not using custom wxWidgets events facility because it's abstract to me, sorry.
*/
class PedalEvent {
public:
enum PedalStatus{RELEASED = 0, PRESSED};
enum PedalPressed{NONE = 0, LEFT, MIDDLE, RIGHT};
PedalEvent();
virtual ~PedalEvent();
virtual void Left(PedalEvent::PedalStatus status);
virtual void Middle(PedalEvent::PedalStatus PedalStatus);
virtual void Right(PedalEvent::PedalStatus PedalStatus);
virtual void OnPedalMonitorExit();
virtual void OnFastMoveExit(MediaFastMove * active);
virtual void OnCodeIdentifierExit(PedalCodeIdentifier * active);
virtual void OnPedalCaught(const unsigned short code);
virtual void OnMediaProgressExit(MediaProgress * active);
virtual void OnMediaProgressPosition();
virtual void OnMediaControlPosition(wxFileOffset position);
virtual void OnStreamError();
private:
};
/*
* For fast forward and rewind
*/
class MediaFastMove : public wxThreadHelper {
public:
MediaFastMove (wxMediaCtrl * newMedia, wxFileOffset newStep, unsigned long newSleepMs, PedalEvent * newCaller);
virtual ~MediaFastMove();
protected:
virtual wxThread::ExitCode Entry();
private:
wxMediaCtrl * m_media;
wxFileOffset m_step;
unsigned long m_sleepMs;
PedalEvent * m_pedalEVH;
};
/*
* Identify the bytes sent by each pedal.
*/
class PedalCodeIdentifier : public wxThreadHelper {
public:
PedalCodeIdentifier(const wxString& newDevice, PedalEvent * newPedalEvent);
~PedalCodeIdentifier();
protected:
virtual wxThread::ExitCode Entry();
private:
PedalEvent * m_pedalEVH;
wxString m_device;
};
/*
* Update media position in UI.
*/
class MediaProgress : public wxThreadHelper {
public:
MediaProgress(PedalEvent * newPedalEvent);
~MediaProgress();
protected:
virtual wxThread::ExitCode Entry();
private:
PedalEvent * m_pedalEVH;
};
class HIDTool {
public:
HIDTool();
virtual ~HIDTool();
static void GetHIDDevices(wxComboBox * cmb, wxArrayString& paths);
private:
static void AppendHIDDevice(hid_device_info * newDeviceInfo, wxComboBox * cmb, wxArrayString& paths);
};
#endif /* PEDALMONITOR_H */