-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseOutputGenerator.cpp
More file actions
51 lines (39 loc) · 1.7 KB
/
BaseOutputGenerator.cpp
File metadata and controls
51 lines (39 loc) · 1.7 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
//
// Created by me on 04/04/2023.
//
#include "BaseOutputGenerator.h"
#include <MIDIUSB.h>
#include <Arduino.h>
#include "Constants.h"
BaseOutputGenerator::BaseOutputGenerator(PilotCore *pilotCore) {
this->pilotCore = pilotCore;
}
BaseOutputGenerator::~BaseOutputGenerator() {
}
PilotCore *BaseOutputGenerator::getCore() const {
return pilotCore;
}
void BaseOutputGenerator::SendPitchBend(unsigned short voltageValue) {
int pitchBend = constrain ( map ( voltageValue, 0, VOLTAGE_MAX, -PITCH_BEND_BASIS, PITCH_BEND_BASIS ), -PITCH_BEND_BASIS, PITCH_BEND_BASIS - 1);
unsigned int centered = PITCH_BEND_BASIS + pitchBend;
unsigned char low = centered & 0x7F; // LSB
unsigned char high = (centered >> 7) & 0x7F; // MSB
midiEventPacket_t event = {0x0E, 0xE0 | 0, low, high};
MidiUSB.sendMIDI(event);
}
void BaseOutputGenerator::SendCC(unsigned char ccNumber, unsigned short voltageValue) {
uint8_t ccValue = constrain ( map ( voltageValue, 0, VOLTAGE_MAX, 0, MIDI_MAX ), 0, MIDI_MAX );
midiEventPacket_t event = {0x0B, 0xB0 | 0, ccNumber,ccValue};
MidiUSB.sendMIDI(event);
}
void BaseOutputGenerator::SendNRPN(unsigned short nrpmNumber, unsigned short voltageValue) {
uint8_t nrpnValue = constrain ( map ( voltageValue, 0, VOLTAGE_MAX, 0, MIDI_MAX ), 0, MIDI_MAX );
midiEventPacket_t event = {0x0B, 0xB0 | 0, NRPN_MSB, nrpmNumber >> 7};
MidiUSB.sendMIDI(event);
event = {0x0B, 0xB0 | 0, NRPN_LSB, nrpmNumber & 0x7F};
MidiUSB.sendMIDI(event);
event = {0x0B, 0xB0 | 0, DATA_ENTRY_MSB, nrpnValue >> 7};
MidiUSB.sendMIDI(event);
event = {0x0B, 0xB0 | 0, DATA_ENTRY_LSB, nrpnValue & 0x7F};
MidiUSB.sendMIDI(event);
}