Browse Source

BLOCKS API: Added activation controls to PhysicalTopologySource

tags/2021-05-28
Daniel Walz Julian Storer 7 years ago
parent
commit
e64e1ebdaa
5 changed files with 87 additions and 14 deletions
  1. +45
    -11
      modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.cpp
  2. +9
    -2
      modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.h
  3. +20
    -0
      modules/juce_blocks_basics/topology/juce_RuleBasedTopologySource.cpp
  4. +7
    -1
      modules/juce_blocks_basics/topology/juce_RuleBasedTopologySource.h
  5. +6
    -0
      modules/juce_blocks_basics/topology/juce_TopologySource.h

+ 45
- 11
modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.cpp 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() 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 BlockTopology PhysicalTopologySource::getCurrentTopology() const
{ {
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED // This method must only be called from the message thread! 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 void PhysicalTopologySource::cancelAllActiveTouches() noexcept
{ {
detector->detector->cancelAllActiveTouches();
if (detector != nullptr)
detector->detector->cancelAllActiveTouches();
} }
bool PhysicalTopologySource::hasOwnServiceTimer() const { return false; } 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() {}
PhysicalTopologySource::DeviceConnection::~DeviceConnection() {} PhysicalTopologySource::DeviceConnection::~DeviceConnection() {}


+ 9
- 2
modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.h View File

@@ -34,7 +34,7 @@ class PhysicalTopologySource : public TopologySource
{ {
public: public:
/** Constructor. */ /** Constructor. */
PhysicalTopologySource();
PhysicalTopologySource (bool startDetached = false);
/** Destructor. */ /** Destructor. */
~PhysicalTopologySource(); ~PhysicalTopologySource();
@@ -45,6 +45,12 @@ public:
/** Reset all touches */ /** Reset all touches */
void cancelAllActiveTouches() noexcept override; 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 */ /** For custom transport systems, this represents a connected device */
@@ -68,7 +74,7 @@ public:
}; };
/** Constructor for custom transport systems. */ /** Constructor for custom transport systems. */
PhysicalTopologySource (DeviceDetector& detectorToUse);
PhysicalTopologySource (DeviceDetector& detectorToUse, bool startDetached = false);
static const char* const* getStandardLittleFootFunctions() noexcept; static const char* const* getStandardLittleFootFunctions() noexcept;
@@ -78,6 +84,7 @@ protected:
private: private:
//========================================================================== //==========================================================================
DeviceDetector* customDetector = nullptr;
struct Internal; struct Internal;
struct DetectorHolder; struct DetectorHolder;
std::unique_ptr<DetectorHolder> detector; std::unique_ptr<DetectorHolder> detector;


+ 20
- 0
modules/juce_blocks_basics/topology/juce_RuleBasedTopologySource.cpp 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; RuleBasedTopologySource& owner;
TopologySource& detector; TopologySource& detector;
@@ -103,4 +113,14 @@ BlockTopology RuleBasedTopologySource::getCurrentTopology() const {
void RuleBasedTopologySource::clearRules() { internal->clearRules(); } void RuleBasedTopologySource::clearRules() { internal->clearRules(); }
void RuleBasedTopologySource::addRule (Rule* r) { internal->addRule (r); } 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 } // namespace juce

+ 7
- 1
modules/juce_blocks_basics/topology/juce_RuleBasedTopologySource.h View File

@@ -45,7 +45,7 @@ public:
//========================================================================== //==========================================================================
/** Returns the currently active topology. */ /** Returns the currently active topology. */
BlockTopology getCurrentTopology() const;
BlockTopology getCurrentTopology() const override;
/** A rule that can transform parts of a topology. */ /** A rule that can transform parts of a topology. */
struct Rule struct Rule
@@ -73,6 +73,12 @@ public:
*/ */
void addRule (Rule*); 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: private:
//========================================================================== //==========================================================================
struct Internal; struct Internal;


+ 6
- 0
modules/juce_blocks_basics/topology/juce_TopologySource.h View File

@@ -37,6 +37,12 @@ public:
/** Returns the current topology that this object manages. */ /** Returns the current topology that this object manages. */
virtual BlockTopology getCurrentTopology() const = 0; 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 */ /** Used to receive callbacks for topology changes */
struct Listener struct Listener


Loading…
Cancel
Save