-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIDIReceiver.h
49 lines (43 loc) · 1.62 KB
/
MIDIReceiver.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
44
45
46
47
48
49
#ifndef __MIDIReceiver__
#define __MIDIReceiver__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wextra-tokens"
#include "IPlug_include_in_plug_hdr.h"
#pragma clang diagnostic pop
#include "IMidiQueue.h"
class MIDIReceiver {
private:
IMidiQueue mMidiQueue;
static const int keyCount = 128;
int mNumKeys; // how many keys are being played at the moment (via midi)
bool mKeyStatus[keyCount]; // array of on/off for each key (index is note number)
int mLastNoteNumber;
double mLastFrequency;
int mLastVelocity;
int mOffset;
inline double noteNumberToFrequency(int noteNumber) { return 440.0 * pow(2.0, (noteNumber - 69.0) / 12.0); }
public:
MIDIReceiver() :
mNumKeys(0),
mLastNoteNumber(-1),
mLastFrequency(-1.0),
mLastVelocity(0),
mOffset(0) {
for (int i = 0; i < keyCount; i++) {
mKeyStatus[i] = false;
}
};
// Returns true if the key with a given index is currently pressed
inline bool getKeyStatus(int keyIndex) const { return mKeyStatus[keyIndex]; }
// Returns the number of keys currently pressed
inline int getNumKeys() const { return mNumKeys; }
// Returns the last pressed note number
inline int getLastNoteNumber() const { return mLastNoteNumber; }
inline double getLastFrequency() const { return mLastFrequency; }
inline int getLastVelocity() const { return mLastVelocity; }
void advance();
void onMessageReceived(IMidiMsg* midiMessage);
inline void Flush(int nFrames) { mMidiQueue.Flush(nFrames); mOffset = 0; }
inline void Resize(int blockSize) { mMidiQueue.Resize(blockSize); }
};
#endif