Skip to content

Commit

Permalink
Experimental fix for win 32 timer #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jonoomph committed Dec 8, 2024
1 parent 6e61142 commit 6618786
Showing 1 changed file with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,50 @@
namespace juce
{

class PlatformTimer final
{
public:
explicit PlatformTimer (PlatformTimerListener& ptl)
: listener { ptl } {}

void startTimer(int newIntervalMs)
class PlatformTimer final
{
jassert(newIntervalMs > 0);
public:
explicit PlatformTimer(PlatformTimerListener& ptl)
: listener{ ptl } {}

// Define the callback with __stdcall explicitly
static void __stdcall timerCallback(UINT, UINT, DWORD_PTR context, DWORD_PTR, DWORD_PTR)
void startTimer(int newIntervalMs)
{
reinterpret_cast<PlatformTimerListener*>(context)->onTimerExpired();
jassert(newIntervalMs > 0);

// Use the static callback
timerId = timeSetEvent((UINT)newIntervalMs, 1, &PlatformTimer::timerCallback, (DWORD_PTR)&listener, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
intervalMs = timerId != 0 ? newIntervalMs : 0;
}

// Use the explicitly defined callback
timerId = timeSetEvent((UINT)newIntervalMs, 1, timerCallback, (DWORD_PTR)&listener, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
intervalMs = timerId != 0 ? newIntervalMs : 0;
}
void cancelTimer()
{
jassert(timerId != 0);

void cancelTimer()
{
jassert (timerId != 0);
timeKillEvent(timerId);
timerId = 0;
intervalMs = 0;
}

timeKillEvent (timerId);
timerId = 0;
intervalMs = 0;
}
int getIntervalMs() const
{
return intervalMs;
}

int getIntervalMs() const
{
return intervalMs;
}
private:
PlatformTimerListener& listener;
UINT timerId{ 0 };
int intervalMs{ 0 };

private:
PlatformTimerListener& listener;
UINT timerId { 0 };
int intervalMs { 0 };
// Define the static callback here
static void __stdcall timerCallback(UINT, UINT, DWORD_PTR context, DWORD_PTR, DWORD_PTR)
{
auto* listener = reinterpret_cast<PlatformTimerListener*>(context);
if (listener != nullptr)
listener->onTimerExpired();
}

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PlatformTimer)
JUCE_DECLARE_NON_MOVEABLE (PlatformTimer)
};
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PlatformTimer)
JUCE_DECLARE_NON_MOVEABLE(PlatformTimer)
};

} // namespace juce

0 comments on commit 6618786

Please sign in to comment.