From accb5d573dc641e7ee9d93fac477368c459ca01b Mon Sep 17 00:00:00 2001 From: Daniel Walz Date: Wed, 12 Sep 2018 14:50:21 +0100 Subject: [PATCH] BLOCKS: Added a method PhysicalTopologySource::isLockedFromOutside() --- .../topology/juce_PhysicalTopologySource.cpp | 24 +++++++++++++++++++ .../topology/juce_PhysicalTopologySource.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.cpp b/modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.cpp index f7a17cc3d5..0c8273a6a1 100644 --- a/modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.cpp +++ b/modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.cpp @@ -228,6 +228,8 @@ struct PhysicalTopologySource::Internal if (dev->lockAgainstOtherProcesses (pair.inputName, pair.outputName)) { + lockedFromOutside = false; + dev->midiInput.reset (juce::MidiInput::openDevice (pair.inputIndex, dev.get())); dev->midiOutput.reset (juce::MidiOutput::openDevice (pair.outputIndex)); @@ -237,11 +239,20 @@ struct PhysicalTopologySource::Internal return dev.release(); } } + else + { + lockedFromOutside = true; + } } return nullptr; } + bool isLockedFromOutside() const override + { + return lockedFromOutside; + } + static bool isBlocksMidiDeviceName (const juce::String& name) { return name.indexOf (" BLOCK") > 0 || name.indexOf (" Block") > 0; @@ -303,6 +314,9 @@ struct PhysicalTopologySource::Internal return result; } + private: + bool lockedFromOutside = true; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MIDIDeviceDetector) }; @@ -2598,6 +2612,8 @@ PhysicalTopologySource::~PhysicalTopologySource() void PhysicalTopologySource::setActive (bool shouldBeActive) { + JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED + if (isActive() == shouldBeActive) return; @@ -2622,6 +2638,14 @@ bool PhysicalTopologySource::isActive() const return detector != nullptr; } +bool PhysicalTopologySource::isLockedFromOutside() const +{ + if (detector != nullptr && detector->detector != nullptr) + return detector->detector->deviceDetector.isLockedFromOutside(); + + return false; +} + BlockTopology PhysicalTopologySource::getCurrentTopology() const { JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED // This method must only be called from the message thread! diff --git a/modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.h b/modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.h index a96cff3e6e..dc637e8ed6 100644 --- a/modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.h +++ b/modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.h @@ -51,6 +51,8 @@ public: /** Returns true, if the TopologySource is currently trying to connect the block devices */ bool isActive() const override; + /** This method will tell, if an other PhysicalTopologySource has locked the Midi connection */ + bool isLockedFromOutside() const; //========================================================================== /** For custom transport systems, this represents a connected device */ @@ -71,6 +73,7 @@ public: virtual juce::StringArray scanForDevices() = 0; virtual DeviceConnection* openDevice (int index) = 0; + virtual bool isLockedFromOutside() const { return false; } }; /** Constructor for custom transport systems. */