20 |
atomic_t notesChanged; // whether some key changed at all |
atomic_t notesChanged; // whether some key changed at all |
21 |
atomic_t pNoteChanged[MIDI_KEYS]; // which key(s) changed |
atomic_t pNoteChanged[MIDI_KEYS]; // which key(s) changed |
22 |
atomic_t pNoteIsActive[MIDI_KEYS]; // status of each key (either active or inactive) |
atomic_t pNoteIsActive[MIDI_KEYS]; // status of each key (either active or inactive) |
23 |
|
atomic_t pNoteOnVelocity[MIDI_KEYS]; |
24 |
|
atomic_t pNoteOffVelocity[MIDI_KEYS]; |
25 |
RingBuffer<VirtualMidiDevice::event_t,false> events; |
RingBuffer<VirtualMidiDevice::event_t,false> events; |
26 |
|
|
27 |
_private_data_t() : events(MAX_EVENTS, 0) {} |
_private_data_t() : events(MAX_EVENTS, 0) {} |
31 |
_private_data_t* p = new _private_data_t; |
_private_data_t* p = new _private_data_t; |
32 |
pPrivateData = p; |
pPrivateData = p; |
33 |
atomic_t zero = ATOMIC_INIT(0); |
atomic_t zero = ATOMIC_INIT(0); |
34 |
|
atomic_t defaultVelocity = ATOMIC_INIT(127); |
35 |
p->notesChanged = zero; |
p->notesChanged = zero; |
36 |
for (int i = 0; i < MIDI_KEYS; i++) { |
for (int i = 0; i < MIDI_KEYS; i++) { |
37 |
p->pNoteChanged[i] = zero; |
p->pNoteChanged[i] = zero; |
38 |
p->pNoteIsActive[i] = zero; |
p->pNoteIsActive[i] = zero; |
39 |
|
p->pNoteOnVelocity[i] = defaultVelocity; |
40 |
|
p->pNoteOffVelocity[i] = defaultVelocity; |
41 |
} |
} |
42 |
} |
} |
43 |
|
|
87 |
return atomic_read( &(p->pNoteIsActive)[Key] ); |
return atomic_read( &(p->pNoteIsActive)[Key] ); |
88 |
} |
} |
89 |
|
|
90 |
void VirtualMidiDevice::SendNoteOnToDevice(uint8_t Key, uint8_t /*Velocity*/) { |
uint8_t VirtualMidiDevice::NoteOnVelocity(uint8_t Key) { |
91 |
|
_private_data_t* p = (_private_data_t*)pPrivateData; |
92 |
|
return atomic_read( &(p->pNoteOnVelocity)[Key] ); |
93 |
|
} |
94 |
|
|
95 |
|
uint8_t VirtualMidiDevice::NoteOffVelocity(uint8_t Key) { |
96 |
|
_private_data_t* p = (_private_data_t*)pPrivateData; |
97 |
|
return atomic_read( &(p->pNoteOffVelocity)[Key] ); |
98 |
|
} |
99 |
|
|
100 |
|
void VirtualMidiDevice::SendNoteOnToDevice(uint8_t Key, uint8_t Velocity) { |
101 |
if (Key >= MIDI_KEYS) return; |
if (Key >= MIDI_KEYS) return; |
102 |
_private_data_t* p = (_private_data_t*)pPrivateData; |
_private_data_t* p = (_private_data_t*)pPrivateData; |
103 |
|
atomic_set( &(p->pNoteOnVelocity)[Key], Velocity ); |
104 |
atomic_inc( &(p->pNoteIsActive)[Key] ); |
atomic_inc( &(p->pNoteIsActive)[Key] ); |
105 |
atomic_inc( &(p->pNoteChanged)[Key] ); |
atomic_inc( &(p->pNoteChanged)[Key] ); |
106 |
atomic_inc( &p->notesChanged ); |
atomic_inc( &p->notesChanged ); |
107 |
} |
} |
108 |
|
|
109 |
void VirtualMidiDevice::SendNoteOffToDevice(uint8_t Key, uint8_t /*Velocity*/) { |
void VirtualMidiDevice::SendNoteOffToDevice(uint8_t Key, uint8_t Velocity) { |
110 |
if (Key >= MIDI_KEYS) return; |
if (Key >= MIDI_KEYS) return; |
111 |
_private_data_t* p = (_private_data_t*)pPrivateData; |
_private_data_t* p = (_private_data_t*)pPrivateData; |
112 |
|
atomic_set( &(p->pNoteOffVelocity)[Key], Velocity ); |
113 |
atomic_dec( &(p->pNoteIsActive)[Key] ); |
atomic_dec( &(p->pNoteIsActive)[Key] ); |
114 |
atomic_inc( &(p->pNoteChanged)[Key] ); |
atomic_inc( &(p->pNoteChanged)[Key] ); |
115 |
atomic_inc( &p->notesChanged ); |
atomic_inc( &p->notesChanged ); |