-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMidiController.cpp
More file actions
88 lines (71 loc) · 2.31 KB
/
MidiController.cpp
File metadata and controls
88 lines (71 loc) · 2.31 KB
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
#include "MidiController.h"
MidiController::MidiController() :
FootController(MIDI_GM),
serialMIDI(*(new midi::SerialMIDI<HardwareSerial>(Serial1)) ),
MIDI(*(new midi::MidiInterface<midi::SerialMIDI<HardwareSerial>>(serialMIDI)) )
{
_scene = 0;
_bank = 0;
}
void MidiController::init()
{
}
void MidiController::sendProgramChange(byte program)
{
MIDI.sendProgramChange(program, 1);
}
void MidiController::sendControlChange(byte control, byte value)
{
MIDI.sendControlChange(control, value, 1);
}
void MidiController::sendBankChange(byte bank)
{
MIDI.sendControlChange(0, bank, 1);
}
void MidiController::update()
{
_leds.update(); // update the timer
}
void MidiController::handleEvents()
{
long nowTimeMs = millis();
for (byte switchIndex = 0; switchIndex < NUM_BUTTONS; switchIndex++) {
#ifdef HAS_MUX
_mux.select(switchIndex);
#endif
auto& currentButton = _buttons[switchIndex];
currentButton.update();
// handle hold durations
const auto fellState = currentButton.fell();
const auto roseState = currentButton.rose();
HoldMgr.update(switchIndex, fellState, roseState, nowTimeMs);
const auto changed = HoldMgr.hasChanged(switchIndex);
const auto bankOffset = HoldMgr.getPresetAutoRepeatAmplitude(switchIndex, true);
constexpr int NumPresets = 128;
constexpr int NumBanks = NumPresets / NUM_SCENES;
int bank = _bank;
// First handle autorepeat keys:
if (switchIndex == SWITCH_PRESET_DEC || switchIndex == SWITCH_PRESET_INC) {
auto newBank = switchIndex == SWITCH_PRESET_DEC ?
(bank + NumBanks - bankOffset) % NumBanks :
(bank + bankOffset) % NumBanks;
if (fellState || changed) {
sendProgramChange(newBank * NUM_SCENES + _scene);
_bank = newBank;
_leds.flashLed(switchIndex, PEDAL_ACTIVE_FLASH );
HoldMgr.clearChanged(switchIndex);
}
}
else if (fellState) {
switch ( switchIndex ) {
// Switches 1-4, 6-9 (Scene 1-8)
case SWITCH_S1: case SWITCH_S2: case SWITCH_S3: case SWITCH_S4:
case SWITCH_S5: case SWITCH_S6: case SWITCH_S7: case SWITCH_S8:
_scene = sceneFromSwitchValue(switchIndex) - 1;
sendProgramChange(_bank * NUM_SCENES + _scene);
break;
}
HoldMgr.clearChanged(switchIndex);
}
}
}