forked from Pomax/arduino-midi-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
40-midi.ino
51 lines (38 loc) · 1.27 KB
/
40-midi.ino
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
#include <MIDI.h>
#define NOTE_OFF_EVENT 0x80
#define NOTE_ON_EVENT 0x90
#define CONTROL_CHANGE_EVENT 0xB0
#define PITCH_BEND_EVENT 0xE0
MIDI_CREATE_DEFAULT_INSTANCE();
void setupMidi() {
// set up MIDI handling
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.setHandlePitchBend(handlePitchBend);
MIDI.setHandleControlChange(handleControlChange);
}
void loopMidi() {
MIDI.read();
}
void handleNoteOff(byte channel, byte pitch, byte velocity) {
writeToFile(NOTE_OFF_EVENT, pitch, velocity, getDelta());
lastNoteSignal = currentMillis;
}
void handleNoteOn(byte channel, byte pitch, byte velocity) {
// drawText("note on");
writeToFile(NOTE_ON_EVENT, pitch, velocity, getDelta());
lastNoteSignal = currentMillis;
// if (play) tone(AUDIO, 440 * pow(2, (pitch - 69.0) / 12.0), 100);
}
void handleControlChange(byte channel, byte cc, byte value) {
// drawText("cc");
writeToFile(CONTROL_CHANGE_EVENT, cc, value, getDelta());
lastCCSignal = currentMillis;
}
void handlePitchBend(byte channel, int bend) {
bend += 0x2000; // MIDI bend uses the range 0x0000-0x3FFF, with 0x2000 as center.
byte lsb = bend & 0x7F;
byte msb = bend >> 7;
writeToFile(PITCH_BEND_EVENT, lsb, msb, getDelta());
}