diff --git a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp index 50008645c7..62dcd423f2 100644 --- a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp @@ -1438,23 +1438,6 @@ private: }; //============================================================================== -class LambdaTimer final : private Timer -{ -public: - explicit LambdaTimer (std::function c) : callback (c) {} - - ~LambdaTimer() noexcept override { stopTimer(); } - - using Timer::startTimer; - using Timer::startTimerHz; - using Timer::stopTimer; - -private: - void timerCallback() override { callback(); } - - std::function callback; -}; - struct UiEventListener : public MessageBufferInterface { virtual int idle() = 0; @@ -1482,7 +1465,7 @@ public: private: Messages processorToUi; std::set activeUis; - LambdaTimer timer { [this] + TimedCallback timer { [this] { for (auto* l : activeUis) if (l->idle() != 0) @@ -4335,7 +4318,7 @@ private: Component::SafePointer editorPointer = nullptr; String uiBundleUri; UiDescriptor uiDescriptor; - LambdaTimer changedParameterFlusher; + TimedCallback changedParameterFlusher; }; template <> diff --git a/modules/juce_audio_processors/utilities/ARA/juce_ARADocumentController.cpp b/modules/juce_audio_processors/utilities/ARA/juce_ARADocumentController.cpp index 736ed5f22d..ef48727709 100644 --- a/modules/juce_audio_processors/utilities/ARA/juce_ARADocumentController.cpp +++ b/modules/juce_audio_processors/utilities/ARA/juce_ARADocumentController.cpp @@ -26,30 +26,6 @@ namespace juce { -class SimpleTimer final : private Timer -{ -public: - SimpleTimer (int frequencyHz, std::function callbackIn) - : callback (std::move (callbackIn)) - { - jassert (callback); - startTimerHz (frequencyHz); - } - - ~SimpleTimer() override - { - stopTimer(); - } - -private: - void timerCallback() override - { - callback(); - } - - std::function callback; -}; - class ARADocumentControllerSpecialisation::ARADocumentControllerImpl : public ARADocumentController { public: @@ -267,7 +243,7 @@ private: std::atomic internalAnalysisProgressIsSynced { true }; ScopedJuceInitialiser_GUI libraryInitialiser; int activeAudioSourcesCount = 0; - std::optional analysisTimer; + std::optional analysisTimer; void analysisTimerCallback(); @@ -386,9 +362,14 @@ void ARADocumentControllerSpecialisation::ARADocumentControllerImpl::didEndEditi notifyListeners (&ARADocument::Listener::didEndEditing, static_cast (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 diff --git a/modules/juce_events/timers/juce_TimedCallback.h b/modules/juce_events/timers/juce_TimedCallback.h index ba1f5507a8..d389a22d7a 100644 --- a/modules/juce_events/timers/juce_TimedCallback.h +++ b/modules/juce_events/timers/juce_TimedCallback.h @@ -53,6 +53,7 @@ public: using Timer::startTimerHz; using Timer::stopTimer; using Timer::isTimerRunning; + using Timer::getTimerInterval; private: void timerCallback() override { callback(); } diff --git a/modules/juce_gui_basics/native/juce_Windowing_linux.cpp b/modules/juce_gui_basics/native/juce_Windowing_linux.cpp index e103291b58..4426f2ef0a 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_linux.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_linux.cpp @@ -508,26 +508,6 @@ private: JUCE_DECLARE_NON_COPYABLE (LinuxRepaintManager) }; - class LinuxVBlankManager final : public Timer - { - public: - explicit LinuxVBlankManager (std::function cb) : callback (std::move (cb)) - { - jassert (callback); - } - - ~LinuxVBlankManager() override { stopTimer(); } - - //============================================================================== - void timerCallback() override { callback(); } - - private: - std::function callback; - - JUCE_DECLARE_NON_COPYABLE (LinuxVBlankManager) - JUCE_DECLARE_NON_MOVEABLE (LinuxVBlankManager) - }; - //============================================================================== template static Point localToGlobal (This& t, Point relativePosition) @@ -594,7 +574,7 @@ private: //============================================================================== std::unique_ptr repainter; - LinuxVBlankManager vBlankManager { [this]() { onVBlank(); } }; + TimedCallback vBlankManager { [this]() { onVBlank(); } }; ::Window windowH = {}, parentWindow = {}; Rectangle bounds; diff --git a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp index 32cd2ad204..39d22f61e6 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp @@ -1653,31 +1653,6 @@ private: JUCE_IMPLEMENT_SINGLETON (VBlankDispatcher) -//============================================================================== -class SimpleTimer final : private Timer -{ -public: - SimpleTimer (int intervalMs, std::function callbackIn) - : callback (std::move (callbackIn)) - { - jassert (callback); - startTimer (intervalMs); - } - - ~SimpleTimer() override - { - stopTimer(); - } - -private: - void timerCallback() override - { - callback(); - } - - std::function 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 deferredRepaints; ScopedSuspendResumeNotificationRegistration suspendResumeRegistration; - std::optional monitorUpdateTimer; + std::optional monitorUpdateTimer; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HWNDComponentPeer)