Multimedia timer

Hello (sorry for my english)

does juce contains a possibility of using a multi-media timer identical to win32
api (timeBeginPeriod, timeSetEvent…) ?

where i can give a callback called per period



the Timer class is your friend.

if you make your ‘doing stuff’ class a subclass of Timer, you just need to put a definition for timerCallback(), which will be called every time the timer counts down. startTimer(time), where time is in ms, will start the timer going, and you can stop it with stopTimer(). it will just keep running til you stop it.

thanks for you reply :slight_smile:

does the precision as the same accuracy than win32 api ? (on window, and
other plateform ?)

i believe the timer is not entirely precise- it’s accurate to around 10ms apparently. what is it you need it for? if it is for sample accurate timing of audio etc… then there are other things to help there (not used them myself tho). if it’s just a case of doing something after a certain amount of time, Timers are fine.

The Timer class uses the event thread to do the callbacks, so it’s perfect for UI stuff, but can get blocked when there are lots of other messages flying around, or if some messages take a long time to process.

To use really accurate timings you’d need to run a dedicated high-priority thread, and have a loop in it using Time::waitForMillisecondCounter() to synchronise itself. That’d be accurate to within 1ms.