-
Notifications
You must be signed in to change notification settings - Fork 1
/
MIDIReceiver.cpp
37 lines (34 loc) · 1 KB
/
MIDIReceiver.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
#include "MIDIReceiver.h"
void MIDIReceiver::onMessageReceived(IMidiMsg* midiMessage) {
IMidiMsg::EStatusMsg status = midiMessage->StatusMsg();
// Only Note on/off
if (status == IMidiMsg::kNoteOn || status == IMidiMsg::kNoteOff) {
mMidiQueue.Add(midiMessage);
}
}
void MIDIReceiver::advance() {
while (!mMidiQueue.Empty()) {
IMidiMsg* midiMessage = mMidiQueue.Peek();
if (midiMessage->mOffset > mOffset) break;
IMidiMsg::EStatusMsg status = midiMessage -> StatusMsg();
int noteNumber = midiMessage->NoteNumber();
int velocity = midiMessage->Velocity();
// There are only note on/off messages in the queue, see ONMessageReceived
if (status == IMidiMsg::kNoteOn&&velocity) {
if (mKeyStatus[noteNumber] == false) {
mKeyStatus[noteNumber] = true;
mNumKeys += 1;
noteOn(noteNumber, velocity);
}
}
else {
if (mKeyStatus[noteNumber] == true) {
mKeyStatus[noteNumber] = false;
mNumKeys -= 1;
noteOff(noteNumber, velocity);
}
}
mMidiQueue.Remove();
}
mOffset++;
}