496 |
throw MidiInputException("Invalid note on velocity filter, values must be in range 0 .. 127"); |
throw MidiInputException("Invalid note on velocity filter, values must be in range 0 .. 127"); |
497 |
|
|
498 |
// apply new filter ... |
// apply new filter ... |
499 |
noteOnVelocityFilterMutex.Lock(); |
LockGuard lock(noteOnVelocityFilterMutex); |
500 |
// double buffer ... double work ... |
// double buffer ... double work ... |
501 |
{ |
{ |
502 |
std::vector<uint8_t>& config = |
std::vector<uint8_t>& config = |
508 |
noteOnVelocityFilter.SwitchConfig(); |
noteOnVelocityFilter.SwitchConfig(); |
509 |
config = filter; |
config = filter; |
510 |
} |
} |
|
noteOnVelocityFilterMutex.Unlock(); |
|
511 |
} |
} |
512 |
|
|
513 |
void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) { |
void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) { |
515 |
throw MidiInputException("MIDI channel index out of bounds"); |
throw MidiInputException("MIDI channel index out of bounds"); |
516 |
|
|
517 |
// first check if desired connection is already established |
// first check if desired connection is already established |
518 |
MidiChannelMapMutex.Lock(); |
{ |
519 |
MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate(); |
LockGuard lock(MidiChannelMapMutex); |
520 |
bool bAlreadyDone = midiChannelMap[MidiChannel].count(pEngineChannel); |
MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate(); |
521 |
MidiChannelMapMutex.Unlock(); |
if (midiChannelMap[MidiChannel].count(pEngineChannel)) return; |
522 |
if (bAlreadyDone) return; |
} |
523 |
|
|
524 |
// remove all other connections of that engine channel (if any) |
// remove all other connections of that engine channel (if any) |
525 |
Disconnect(pEngineChannel); |
Disconnect(pEngineChannel); |
526 |
|
|
527 |
// register engine channel on the desired MIDI channel |
// register engine channel on the desired MIDI channel |
528 |
MidiChannelMapMutex.Lock(); |
{ |
529 |
MidiChannelMap.GetConfigForUpdate()[MidiChannel].insert(pEngineChannel); |
LockGuard lock(MidiChannelMapMutex); |
530 |
MidiChannelMap.SwitchConfig()[MidiChannel].insert(pEngineChannel); |
MidiChannelMap.GetConfigForUpdate()[MidiChannel].insert(pEngineChannel); |
531 |
MidiChannelMapMutex.Unlock(); |
MidiChannelMap.SwitchConfig()[MidiChannel].insert(pEngineChannel); |
532 |
|
} |
533 |
|
|
534 |
// inform engine channel about this connection |
// inform engine channel about this connection |
535 |
pEngineChannel->Connect(this, MidiChannel); |
pEngineChannel->Connect(this, MidiChannel); |
544 |
bool bChannelFound = false; |
bool bChannelFound = false; |
545 |
|
|
546 |
// unregister engine channel from all MIDI channels |
// unregister engine channel from all MIDI channels |
|
MidiChannelMapMutex.Lock(); |
|
547 |
try { |
try { |
548 |
|
LockGuard lock(MidiChannelMapMutex); |
549 |
{ |
{ |
550 |
MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate(); |
MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate(); |
551 |
for (int i = 0; i <= 16; i++) { |
for (int i = 0; i <= 16; i++) { |
563 |
} |
} |
564 |
} |
} |
565 |
catch(...) { /* NOOP */ } |
catch(...) { /* NOOP */ } |
|
MidiChannelMapMutex.Unlock(); |
|
566 |
|
|
567 |
// inform engine channel about the disconnection (if there is one) |
// inform engine channel about the disconnection (if there is one) |
568 |
if (bChannelFound) pEngineChannel->DisconnectMidiInputPort(); |
if (bChannelFound) pEngineChannel->DisconnectMidiInputPort(); |
585 |
} |
} |
586 |
|
|
587 |
void MidiInputPort::Connect(VirtualMidiDevice* pDevice) { |
void MidiInputPort::Connect(VirtualMidiDevice* pDevice) { |
588 |
virtualMidiDevicesMutex.Lock(); |
LockGuard lock(virtualMidiDevicesMutex); |
589 |
// double buffer ... double work ... |
// double buffer ... double work ... |
590 |
{ |
{ |
591 |
std::vector<VirtualMidiDevice*>& devices = |
std::vector<VirtualMidiDevice*>& devices = |
597 |
virtualMidiDevices.SwitchConfig(); |
virtualMidiDevices.SwitchConfig(); |
598 |
devices.push_back(pDevice); |
devices.push_back(pDevice); |
599 |
} |
} |
|
virtualMidiDevicesMutex.Unlock(); |
|
600 |
} |
} |
601 |
|
|
602 |
void MidiInputPort::Disconnect(VirtualMidiDevice* pDevice) { |
void MidiInputPort::Disconnect(VirtualMidiDevice* pDevice) { |
603 |
virtualMidiDevicesMutex.Lock(); |
LockGuard lock(virtualMidiDevicesMutex); |
604 |
// double buffer ... double work ... |
// double buffer ... double work ... |
605 |
{ |
{ |
606 |
std::vector<VirtualMidiDevice*>& devices = |
std::vector<VirtualMidiDevice*>& devices = |
612 |
virtualMidiDevices.SwitchConfig(); |
virtualMidiDevices.SwitchConfig(); |
613 |
devices.erase(std::find(devices.begin(), devices.end(), pDevice)); |
devices.erase(std::find(devices.begin(), devices.end(), pDevice)); |
614 |
} |
} |
|
virtualMidiDevicesMutex.Unlock(); |
|
615 |
} |
} |
616 |
|
|
617 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |