mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-03 03:30:06 +00:00
BLOCKS: Throttle frequency of topology change listener callbacks
This commit is contained in:
parent
b936eaeebc
commit
4d821219f8
1 changed files with 39 additions and 9 deletions
|
|
@ -505,8 +505,7 @@ struct PhysicalTopologySource::Internal
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
// The following methods will be called by the DeviceToHostPacketDecoder:
|
||||
|
||||
// The following methods will be called by the HostPacketDecoder:
|
||||
void beginTopology (int numDevices, int numConnections)
|
||||
{
|
||||
incomingTopologyDevices.clearQuick();
|
||||
|
|
@ -815,12 +814,13 @@ struct PhysicalTopologySource::Internal
|
|||
|
||||
for (auto& packet : packets)
|
||||
{
|
||||
lastGlobalPingTime = juce::Time::getCurrentTime();
|
||||
auto data = static_cast<const uint8*> (packet.getData());
|
||||
|
||||
BlocksProtocol::HostPacketDecoder<ConnectedDeviceGroup>
|
||||
::processNextPacket (*this, *data, data + 1, (int) packet.getSize() - 1);
|
||||
}
|
||||
|
||||
lastGlobalPingTime = juce::Time::getCurrentTime();
|
||||
}
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConnectedDeviceGroup)
|
||||
|
|
@ -833,11 +833,13 @@ struct PhysicalTopologySource::Internal
|
|||
{
|
||||
Detector() : defaultDetector (new MIDIDeviceDetector()), deviceDetector (*defaultDetector)
|
||||
{
|
||||
topologyBroadcastThrottle.detector = this;
|
||||
startTimer (10);
|
||||
}
|
||||
|
||||
Detector (DeviceDetector& dd) : deviceDetector (dd)
|
||||
{
|
||||
topologyBroadcastThrottle.detector = this;
|
||||
startTimer (10);
|
||||
}
|
||||
|
||||
|
|
@ -947,12 +949,7 @@ struct PhysicalTopologySource::Internal
|
|||
currentTopology.connections.swapWith (newDeviceConnections);
|
||||
}
|
||||
|
||||
for (auto d : activeTopologySources)
|
||||
d->listeners.call (&TopologySource::Listener::topologyChanged);
|
||||
|
||||
#if DUMP_TOPOLOGY
|
||||
dumpTopology (currentTopology);
|
||||
#endif
|
||||
topologyBroadcastThrottle.scheduleTopologyChangeCallback();
|
||||
}
|
||||
|
||||
void handleSharedDataACK (Block::UID deviceID, uint32 packetCounter) const
|
||||
|
|
@ -1193,6 +1190,39 @@ struct PhysicalTopologySource::Internal
|
|||
|
||||
juce::OwnedArray<ConnectedDeviceGroup> connectedDeviceGroups;
|
||||
|
||||
//==============================================================================
|
||||
/** Flurries of topology messages sometimes arrive due to loose connections.
|
||||
Avoid informing listeners until they've stabilised.
|
||||
*/
|
||||
struct TopologyBroadcastThrottle : private juce::Timer
|
||||
{
|
||||
TopologyBroadcastThrottle() = default;
|
||||
|
||||
void scheduleTopologyChangeCallback() { startTimer (750); }
|
||||
|
||||
void timerCallback() override
|
||||
{
|
||||
if (detector->currentTopology != lastTopology)
|
||||
{
|
||||
lastTopology = detector->currentTopology;
|
||||
|
||||
for (auto* d : detector->activeTopologySources)
|
||||
d->listeners.call (&TopologySource::Listener::topologyChanged);
|
||||
|
||||
#if DUMP_TOPOLOGY
|
||||
dumpTopology (lastTopology);
|
||||
#endif
|
||||
}
|
||||
|
||||
stopTimer();
|
||||
}
|
||||
|
||||
Detector* detector = nullptr;
|
||||
BlockTopology lastTopology;
|
||||
};
|
||||
|
||||
TopologyBroadcastThrottle topologyBroadcastThrottle;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Detector)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue