diff --git a/modules/juce_blocks_basics/topology/internal/juce_BlockImplementation.cpp b/modules/juce_blocks_basics/topology/internal/juce_BlockImplementation.cpp index a49612fa3b..7eda9cfb2a 100644 --- a/modules/juce_blocks_basics/topology/internal/juce_BlockImplementation.cpp +++ b/modules/juce_blocks_basics/topology/internal/juce_BlockImplementation.cpp @@ -422,12 +422,41 @@ public: lastMessageReceiveTime = Time::getCurrentTime(); } + MIDIDeviceConnection* getDeviceConnection() + { + return dynamic_cast (detector->getDeviceConnectionFor (*this)); + } + void addDataInputPortListener (DataInputPortListener* listener) override { - Block::addDataInputPortListener (listener); + if (auto deviceConnection = getDeviceConnection()) + { + { + ScopedLock scopedLock (deviceConnection->criticalSecton); + Block::addDataInputPortListener (listener); + } - if (auto midiInput = getMidiInput()) - midiInput->start(); + deviceConnection->midiInput->start(); + } + else + { + Block::addDataInputPortListener (listener); + } + } + + void removeDataInputPortListener (DataInputPortListener* listener) override + { + if (auto deviceConnection = getDeviceConnection()) + { + { + ScopedLock scopedLock (deviceConnection->criticalSecton); + Block::removeDataInputPortListener (listener); + } + } + else + { + Block::removeDataInputPortListener (listener); + } } void sendMessage (const void* message, size_t messageSize) override