1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-16 00:34:19 +00:00

BLOCKS API: Added activation controls to PhysicalTopologySource

This commit is contained in:
Daniel Walz 2018-08-23 08:56:39 +01:00 committed by Julian Storer
parent 963e307ef8
commit e64e1ebdaa
5 changed files with 87 additions and 14 deletions

View file

@ -2599,38 +2599,72 @@ struct PhysicalTopologySource::DetectorHolder : private juce::Timer
};
//==============================================================================
PhysicalTopologySource::PhysicalTopologySource()
: detector (new DetectorHolder (*this))
PhysicalTopologySource::PhysicalTopologySource (bool startDetached)
{
detector->detector->activeTopologySources.add (this);
if (! startDetached)
setActive (true);
}
PhysicalTopologySource::PhysicalTopologySource (DeviceDetector& detectorToUse)
: detector (new DetectorHolder (*this, detectorToUse))
PhysicalTopologySource::PhysicalTopologySource (DeviceDetector& detectorToUse, bool startDetached)
: customDetector (&detectorToUse)
{
detector->detector->activeTopologySources.add (this);
if (! startDetached)
setActive (true);
}
PhysicalTopologySource::~PhysicalTopologySource()
{
detector->detector->detach (this);
detector = nullptr;
setActive (false);
}
void PhysicalTopologySource::setActive (bool shouldBeActive)
{
if (isActive() == shouldBeActive)
return;
if (shouldBeActive)
{
if (customDetector == nullptr)
detector = std::make_unique<DetectorHolder>(*this);
else
detector = std::make_unique<DetectorHolder>(*this, *customDetector);
detector->detector->activeTopologySources.add (this);
}
else
{
detector->detector->detach (this);
detector.reset();
}
}
bool PhysicalTopologySource::isActive() const
{
return detector != nullptr;
}
BlockTopology PhysicalTopologySource::getCurrentTopology() const
{
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED // This method must only be called from the message thread!
return detector->detector->currentTopology;
if (detector != nullptr)
return detector->detector->currentTopology;
return {};
}
void PhysicalTopologySource::cancelAllActiveTouches() noexcept
{
detector->detector->cancelAllActiveTouches();
if (detector != nullptr)
detector->detector->cancelAllActiveTouches();
}
bool PhysicalTopologySource::hasOwnServiceTimer() const { return false; }
void PhysicalTopologySource::handleTimerTick() { detector->handleTimerTick(); }
void PhysicalTopologySource::handleTimerTick()
{
if (detector != nullptr)
detector->handleTimerTick();
}
PhysicalTopologySource::DeviceConnection::DeviceConnection() {}
PhysicalTopologySource::DeviceConnection::~DeviceConnection() {}

View file

@ -34,7 +34,7 @@ class PhysicalTopologySource : public TopologySource
{
public:
/** Constructor. */
PhysicalTopologySource();
PhysicalTopologySource (bool startDetached = false);
/** Destructor. */
~PhysicalTopologySource();
@ -45,6 +45,12 @@ public:
/** Reset all touches */
void cancelAllActiveTouches() noexcept override;
/** Sets the TopologySource as active, occupying the midi port and trying to connect to the block devices */
void setActive (bool shouldBeActive) override;
/** Returns true, if the TopologySource is currently trying to connect the block devices */
bool isActive() const override;
//==========================================================================
/** For custom transport systems, this represents a connected device */
@ -68,7 +74,7 @@ public:
};
/** Constructor for custom transport systems. */
PhysicalTopologySource (DeviceDetector& detectorToUse);
PhysicalTopologySource (DeviceDetector& detectorToUse, bool startDetached = false);
static const char* const* getStandardLittleFootFunctions() noexcept;
@ -78,6 +84,7 @@ protected:
private:
//==========================================================================
DeviceDetector* customDetector = nullptr;
struct Internal;
struct DetectorHolder;
std::unique_ptr<DetectorHolder> detector;

View file

@ -79,6 +79,16 @@ struct RuleBasedTopologySource::Internal : public TopologySource::Listener,
}
}
void setActive (bool shouldBeActive)
{
detector.setActive (shouldBeActive);
}
bool isActive() const
{
return detector.isActive();
}
RuleBasedTopologySource& owner;
TopologySource& detector;
@ -103,4 +113,14 @@ BlockTopology RuleBasedTopologySource::getCurrentTopology() const {
void RuleBasedTopologySource::clearRules() { internal->clearRules(); }
void RuleBasedTopologySource::addRule (Rule* r) { internal->addRule (r); }
void RuleBasedTopologySource::setActive (bool shouldBeActive)
{
internal->setActive (shouldBeActive);
}
bool RuleBasedTopologySource::isActive() const
{
return internal->isActive();
}
} // namespace juce

View file

@ -45,7 +45,7 @@ public:
//==========================================================================
/** Returns the currently active topology. */
BlockTopology getCurrentTopology() const;
BlockTopology getCurrentTopology() const override;
/** A rule that can transform parts of a topology. */
struct Rule
@ -73,6 +73,12 @@ public:
*/
void addRule (Rule*);
/** Sets the TopologySource as active, occupying the midi port and trying to connect to the block devices */
void setActive (bool shouldBeActive) override;
/** Returns true, if the TopologySource is currently trying to connect the block devices */
bool isActive() const override;
private:
//==========================================================================
struct Internal;

View file

@ -37,6 +37,12 @@ public:
/** Returns the current topology that this object manages. */
virtual BlockTopology getCurrentTopology() const = 0;
/** Sets the TopologySource as active, occupying the midi port and trying to connect to the block devices */
virtual void setActive (bool shouldBeActive) = 0;
/** Returns true, if the TopologySource is currently trying to connect the block devices */
virtual bool isActive() const = 0;
//==========================================================================
/** Used to receive callbacks for topology changes */
struct Listener