-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpedals.h
142 lines (97 loc) · 3.25 KB
/
pedals.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
#ifndef _pedals_h_
#define _pedals_h_
#include "prefs.h"
typedef struct
{
int x; // 0..127
int y;
int weight;
} pedalPoint_t;
class expressionPedal
{
public:
int getNum() { return m_num; }
const char *getName() { return m_name; }
int getValue() { return m_value; }
bool displayValueChanged() { return m_last_value != m_value; }
void clearDisplayValueChanged() { m_last_value = m_value; }
int getRawValue() { return m_raw_value; }
inline float getRawValuePct()
{
float min = m_auto ? 0 : getPrefPedalCalibMin(m_num);
float max = m_auto ? 127 : getPrefPedalCalibMax(m_num);
float val = m_raw_value - min;
if (val < 0.00) val = 0.00;
float ret_val = val / (max - min);
if (ret_val > 1.0) ret_val = 1.0;
return ret_val;
}
int getRawValueScaled()
{
float ret_val = getRawValuePct() * 127.00 + 0.5;
return ret_val;
}
void invalidate()
{
m_valid = false;
}
void setAuto();
void autoCalibrate();
bool inAutoCalibrate() { return m_in_auto_calibrate; }
bool isAuto() { return m_auto; }
void setAutoRawValue(int i);
int getAutoRawValue() { return m_auto_value; }
// midi
void setCCs(int channel, int cc_num)
{
m_cc_channel = channel;
m_cc_num = cc_num;
}
int getCCChannel() { return m_cc_channel; }
int getCCNum() { return m_cc_num; }
// PRIVATE isr handling
void teensyReceiveByte();
void teensySendByte(int byte);
protected:
friend class pedalManager;
expressionPedal() {}
void init(
int num,
int pin,
const char *name,
int cc_channel,
int cc_num);
void poll();
private:
// construction paramaters
int m_num;
int m_pin; // defined in pedals.cpp
int m_pedal_num; // they know this too ...
int m_cc_channel;
int m_cc_num;
const char *m_name;
// runtime working variables
bool m_valid;
int m_raw_value; // 0..1023
int m_direction; // -1,0,1
unsigned m_settle_time;
int m_value; // 0..127
int m_last_value; // display helper
bool m_auto;
int m_auto_value;
bool m_in_auto_calibrate;
};
class pedalManager
{
public:
pedalManager() {}
void init();
// called at runtime to setup pedals from prefs
void task();
// polls pedals, may call expSystem::onPedalEvent()
expressionPedal *getPedal(int i) { return &m_pedals[i]; }
private:
expressionPedal m_pedals[NUM_PEDALS];
};
extern pedalManager thePedals;
#endif // !_pedals_h_