77 |
MidiInputPort::MidiInputPort(MidiInputDevice* pDevice, int portNumber) |
MidiInputPort::MidiInputPort(MidiInputDevice* pDevice, int portNumber) |
78 |
: MidiChannelMapReader(MidiChannelMap), |
: MidiChannelMapReader(MidiChannelMap), |
79 |
SysexListenersReader(SysexListeners), |
SysexListenersReader(SysexListeners), |
80 |
virtualMidiDevicesReader(virtualMidiDevices) { |
virtualMidiDevicesReader(virtualMidiDevices), |
81 |
|
noteOnVelocityFilterReader(noteOnVelocityFilter) |
82 |
|
{ |
83 |
this->pDevice = pDevice; |
this->pDevice = pDevice; |
84 |
this->portNumber = portNumber; |
this->portNumber = portNumber; |
85 |
Parameters["NAME"] = new ParameterName(this); |
Parameters["NAME"] = new ParameterName(this); |
99 |
|
|
100 |
void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) { |
void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) { |
101 |
if (Key > 127 || Velocity > 127 || MidiChannel > 16) return; |
if (Key > 127 || Velocity > 127 || MidiChannel > 16) return; |
102 |
|
|
103 |
|
// apply velocity filter (if any) |
104 |
|
const std::vector<uint8_t>& velocityFilter = noteOnVelocityFilterReader.Lock(); |
105 |
|
if (!velocityFilter.empty()) Velocity = velocityFilter[Velocity]; |
106 |
|
noteOnVelocityFilterReader.Unlock(); |
107 |
|
|
108 |
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
109 |
// dispatch event for engines listening to the same MIDI channel |
// dispatch event for engines listening to the same MIDI channel |
110 |
{ |
{ |
130 |
|
|
131 |
void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos) { |
void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos) { |
132 |
if (Key > 127 || Velocity > 127 || MidiChannel > 16) return; |
if (Key > 127 || Velocity > 127 || MidiChannel > 16) return; |
133 |
|
|
134 |
|
// apply velocity filter (if any) |
135 |
|
const std::vector<uint8_t>& velocityFilter = noteOnVelocityFilterReader.Lock(); |
136 |
|
if (!velocityFilter.empty()) Velocity = velocityFilter[Velocity]; |
137 |
|
noteOnVelocityFilterReader.Unlock(); |
138 |
|
|
139 |
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
140 |
// dispatch event for engines listening to the same MIDI channel |
// dispatch event for engines listening to the same MIDI channel |
141 |
{ |
{ |
443 |
break; |
break; |
444 |
} |
} |
445 |
} |
} |
446 |
|
|
447 |
|
void MidiInputPort::SetNoteOnVelocityFilter(const std::vector<uint8_t>& filter) { |
448 |
|
if (filter.size() != 128 && filter.size() != 0) |
449 |
|
throw MidiInputException("Note on velocity filter must be either of size 128 or 0"); |
450 |
|
|
451 |
|
// check the value range of the filter |
452 |
|
if (!filter.empty()) |
453 |
|
for (int i = 0; i < 128; i++) |
454 |
|
if (filter[i] > 127) |
455 |
|
throw MidiInputException("Invalid note on velocity filter, values must be in range 0 .. 127"); |
456 |
|
|
457 |
|
// apply new filter ... |
458 |
|
noteOnVelocityFilterMutex.Lock(); |
459 |
|
// double buffer ... double work ... |
460 |
|
{ |
461 |
|
std::vector<uint8_t>& config = |
462 |
|
noteOnVelocityFilter.GetConfigForUpdate(); |
463 |
|
config = filter; |
464 |
|
} |
465 |
|
{ |
466 |
|
std::vector<uint8_t>& config = |
467 |
|
noteOnVelocityFilter.SwitchConfig(); |
468 |
|
config = filter; |
469 |
|
} |
470 |
|
noteOnVelocityFilterMutex.Unlock(); |
471 |
|
} |
472 |
|
|
473 |
void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) { |
void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) { |
474 |
if (MidiChannel < 0 || MidiChannel > 16) |
if (MidiChannel < 0 || MidiChannel > 16) |