1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Use the new TimedCallback in the codebase

This commit is contained in:
attila 2024-01-10 12:31:12 +01:00
parent 0611baf1be
commit d810a168eb
5 changed files with 16 additions and 93 deletions

View file

@ -1438,23 +1438,6 @@ private:
};
//==============================================================================
class LambdaTimer final : private Timer
{
public:
explicit LambdaTimer (std::function<void()> c) : callback (c) {}
~LambdaTimer() noexcept override { stopTimer(); }
using Timer::startTimer;
using Timer::startTimerHz;
using Timer::stopTimer;
private:
void timerCallback() override { callback(); }
std::function<void()> callback;
};
struct UiEventListener : public MessageBufferInterface<MessageHeader>
{
virtual int idle() = 0;
@ -1482,7 +1465,7 @@ public:
private:
Messages<UiMessageHeader, RealtimeWriteTrait> processorToUi;
std::set<UiEventListener*> activeUis;
LambdaTimer timer { [this]
TimedCallback timer { [this]
{
for (auto* l : activeUis)
if (l->idle() != 0)
@ -4335,7 +4318,7 @@ private:
Component::SafePointer<Editor> editorPointer = nullptr;
String uiBundleUri;
UiDescriptor uiDescriptor;
LambdaTimer changedParameterFlusher;
TimedCallback changedParameterFlusher;
};
template <>

View file

@ -26,30 +26,6 @@
namespace juce
{
class SimpleTimer final : private Timer
{
public:
SimpleTimer (int frequencyHz, std::function<void()> callbackIn)
: callback (std::move (callbackIn))
{
jassert (callback);
startTimerHz (frequencyHz);
}
~SimpleTimer() override
{
stopTimer();
}
private:
void timerCallback() override
{
callback();
}
std::function<void()> callback;
};
class ARADocumentControllerSpecialisation::ARADocumentControllerImpl : public ARADocumentController
{
public:
@ -267,7 +243,7 @@ private:
std::atomic<bool> internalAnalysisProgressIsSynced { true };
ScopedJuceInitialiser_GUI libraryInitialiser;
int activeAudioSourcesCount = 0;
std::optional<SimpleTimer> analysisTimer;
std::optional<TimedCallback> analysisTimer;
void analysisTimerCallback();
@ -386,9 +362,14 @@ void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::didEndEditi
notifyListeners (&ARADocument::Listener::didEndEditing, static_cast<ARADocument*> (getDocument()));
if (activeAudioSourcesCount == 0)
{
analysisTimer.reset();
}
else if (! analysisTimer.has_value() && (activeAudioSourcesCount > 0))
analysisTimer.emplace (20, [this] { analysisTimerCallback(); });
{
analysisTimer.emplace ([this] { analysisTimerCallback(); });
analysisTimer->startTimerHz (20);
}
}
void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::willNotifyModelUpdates() noexcept

View file

@ -53,6 +53,7 @@ public:
using Timer::startTimerHz;
using Timer::stopTimer;
using Timer::isTimerRunning;
using Timer::getTimerInterval;
private:
void timerCallback() override { callback(); }

View file

@ -508,26 +508,6 @@ private:
JUCE_DECLARE_NON_COPYABLE (LinuxRepaintManager)
};
class LinuxVBlankManager final : public Timer
{
public:
explicit LinuxVBlankManager (std::function<void()> cb) : callback (std::move (cb))
{
jassert (callback);
}
~LinuxVBlankManager() override { stopTimer(); }
//==============================================================================
void timerCallback() override { callback(); }
private:
std::function<void()> callback;
JUCE_DECLARE_NON_COPYABLE (LinuxVBlankManager)
JUCE_DECLARE_NON_MOVEABLE (LinuxVBlankManager)
};
//==============================================================================
template <typename This>
static Point<float> localToGlobal (This& t, Point<float> relativePosition)
@ -594,7 +574,7 @@ private:
//==============================================================================
std::unique_ptr<LinuxRepaintManager> repainter;
LinuxVBlankManager vBlankManager { [this]() { onVBlank(); } };
TimedCallback vBlankManager { [this]() { onVBlank(); } };
::Window windowH = {}, parentWindow = {};
Rectangle<int> bounds;

View file

@ -1653,31 +1653,6 @@ private:
JUCE_IMPLEMENT_SINGLETON (VBlankDispatcher)
//==============================================================================
class SimpleTimer final : private Timer
{
public:
SimpleTimer (int intervalMs, std::function<void()> callbackIn)
: callback (std::move (callbackIn))
{
jassert (callback);
startTimer (intervalMs);
}
~SimpleTimer() override
{
stopTimer();
}
private:
void timerCallback() override
{
callback();
}
std::function<void()> callback;
};
//==============================================================================
class HWNDComponentPeer final : public ComponentPeer,
private VBlankListener,
@ -1722,7 +1697,10 @@ public:
updateCurrentMonitorAndRefreshVBlankDispatcher();
if (parentToAddTo != nullptr)
monitorUpdateTimer.emplace (1000, [this] { updateCurrentMonitorAndRefreshVBlankDispatcher(); });
{
monitorUpdateTimer.emplace ([this] { updateCurrentMonitorAndRefreshVBlankDispatcher(); });
monitorUpdateTimer->startTimer (1000);
}
suspendResumeRegistration = ScopedSuspendResumeNotificationRegistration { hwnd };
}
@ -4727,7 +4705,7 @@ private:
RectangleList<int> deferredRepaints;
ScopedSuspendResumeNotificationRegistration suspendResumeRegistration;
std::optional<SimpleTimer> monitorUpdateTimer;
std::optional<TimedCallback> monitorUpdateTimer;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HWNDComponentPeer)