-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaste.cpp
82 lines (68 loc) · 1.64 KB
/
taste.cpp
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
#include "taste.h" //include the declaration for this class
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); // using TX1 for sending MIDI signal
int Taste::globalVelo = 0;
static void Taste::overrideVelo(int velo) {
globalVelo = velo;
}
static void Taste::midibegin() {
MIDI.begin(MIDI_CHANNEL_OMNI);
}
static void Taste::setPedal(bool press) {
if(press) {
Serial.println("PRESS DOWN ");
MIDI.sendControlChange(64, 127, 1);
} else {
Serial.println("RELEASE ");
MIDI.sendControlChange(64, 0, 1);
}
}
Taste::Taste() {
timer.stop();
delayTimer.stop();
}
Taste::~Taste() {
/*nothing to destruct*/
}
void Taste::playDelayed(int delay, int duration, int velo) {
this->delay = delay;
delayDuration = duration;
delayVelo = velo;
delayTimer.restart();
}
void Taste::play(int duration, int velo) {
if (!timer.isRunning()) {
/*Serial.print("Note: ");
Serial.print(midinote);
Serial.print(" Duration: ");
Serial.println(duration);*/
this->duration = duration;
timer.restart();
if(globalVelo == 0) {
MIDI.sendNoteOn(midinote, velo, 1);
} else {
MIDI.sendNoteOn(midinote, globalVelo, 1);
}
}
}
void Taste::update() {
if (timer.hasPassed(duration) && timer.isRunning()) {
timer.stop();
MIDI.sendNoteOff(midinote, 0, 1);
}
if (delayTimer.hasPassed(delay) && delayTimer.isRunning()){
delayTimer.stop();
play(delayDuration, delayVelo);
}
}
void Taste::stop() {
if (delayTimer.isRunning()) {
delayTimer.stop();
}
}
bool Taste::isPlaying() {
return timer.isRunning();
}
void Taste::setNote(int midinote) {
this->midinote = midinote;
}