-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidiNote.h
43 lines (36 loc) · 909 Bytes
/
MidiNote.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
#ifndef MIDI_NOTE_H
#define MIDI_NOTE_H
#include <MIDIUSB.h>
#include "MidiCommon.h"
class Note : public IPlayable {
public:
Note()
: Note(0)
{}
Note(note_t note, channel_t channel=1)
: note(note)
, active(false)
, channel(channel)
{}
void update(bool isActive, velocity_t velocity = 64) {
if (isActive && !this->active) {
this->noteOn(velocity);
} else if (!isActive && this->active) {
this->noteOff();
}
this->active = isActive;
}
private:
note_t note;
bool active;
channel_t channel;
void noteOn(velocity_t velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | this->channel, this->note, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff() {
midiEventPacket_t noteOff = {0x08, 0x80 | this->channel, this->note, 0};
MidiUSB.sendMIDI(noteOff);
}
};
#endif