-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceManager.h
80 lines (63 loc) · 2.01 KB
/
DeviceManager.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
#pragma once
#include <chrono>
#include <cabl/cabl.h>
#include <RtMidi.h>
#include <boost/asio.hpp>
#define OSC_BUFFER_SIZE 1024
namespace sl {
using namespace cabl;
using namespace boost::asio;
enum class PadState: uint8_t
{
ON,
OFF,
ON_TO_OFF,
OFF_TO_ON,
};
enum class PadAction: uint8_t
{
NO_ACTION,
NOTE_ON,
NOTE_OFF,
NOTE_AFTERTOUCH,
};
class DeviceManager : public Client {
public:
DeviceManager(
DiscoveryPolicy = {},
int midiPort = 0,
std::string oscServerAddress = "",
int oscServerPort = 0,
bool invertLEDs = false,
bool invertShift = false,
std::string secondDisplayText_ = ""
);
~DeviceManager();
void initDevice() override;
void render() override;
void buttonChanged(Device::Button button_, bool buttonState_, bool shiftState_) override;
void encoderChanged(unsigned encoder_, bool valueIncreased_, bool shiftPressed_) override;
void encoderChangedRaw(unsigned encoder_, double delta_, bool shiftPressed_) override;
void keyChanged(unsigned index_, double value_, bool shiftPressed) override;
void keyUpdated(unsigned index_, double value_, bool shiftPressed) override;
private:
PadAction processPadUpdate(unsigned index_, double value_);
void sendOSCMessage(std::string address, std::string value);
PadState padStates[16] = {PadState::OFF};
double padVelocities[16] = {0.0};
std::chrono::steady_clock::time_point padTimes[16];
RtMidiOut *midiOut = 0;
std::vector<unsigned char> noteMessage;
std::vector<unsigned char> ccMessage;
io_service oscIOService;
ip::udp::endpoint oscRemoteEndpoint;
ip::udp::socket oscSocket = ip::udp::socket(oscIOService);
char oscBuffer[OSC_BUFFER_SIZE] = {0};
bool buttonShiftState[static_cast<unsigned>(Device::Button::Unknown)] = {false};
bool invertLEDs = false;
bool invertShift = false;
std::string secondDisplayText = "";
std::string lastDisplayText = "";
std::string displayText = "";
};
}